Question

How do I use mogrify to batch-convert a ton of files (.TIF, .EPS, .JPG but most annoyingly of all-) .PSD files and only keep their first layer?

I found a solution on how to convert all images, but I kept getting filenames in my output-directory which were different from my originals (they had -0, -1, -2 etc. attached to the original filename).

I have 2 folders, ./original/ (which contains my PSDs, EPS, TIF, GIF, JPGs and other images) + the folder ./converted/ (which is the target folder for my conversion)

The command I use to convert my images are:

mogrify -verbose -path ./converted/ \
-alpha off -strip -mattecolor white -background white \
-resize 512x512 -format jpg -quality 75% -interlace Plane ./original/*.*

But no matter what I try, I keep getting this garbage which mangles my filenames. There is one mode however which just merges every interpretation of the files into one, but that's also quite useless as I am getting black backgrounds on my transparent files.

Was it helpful?

Solution

After 2 hours of searching I finally found the answer, and since I love stackoverflow, I'm sharing it here:

In order to select the best image of PSD's or first frame of .GIF's, all you need to add is an index of 0 (litterally, without the double quotes: "[0]") to the input file.

So the command to convert all images (you need to install ImageMagick with mogrify first), with a white background for anything transparant, within a bounding box of 512x512 pixels, outputted at jpg with 50% compression quality, the layers Disposed and the first index used, you need to execute the following command:

mogrify -verbose -path ./converted/ \
-alpha off -strip -mattecolor white -background white -layers Dispose \
-resize 512x512 -format jpg -quality 75% -interlace Plane ./original/*.*[0]

Hopefully this will serve as an easy to use template for anyone who needs to batch convert a lot of images.

I found several image converters but none were as easy to use as mogrify, and of course, it being a linux executable, it gives near infinite possibilities about what you can do with it... everything should be scriptable.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top