ImageMagick command to convert and save with same name ImageMagick command to convert and save with same name shell shell

ImageMagick command to convert and save with same name


Another way:

convert *.jpg -resize 80% -set filename:f '%t' ../'%[filename:f].jpg'

Will place converted files in the folder above.

The option -set filename:f '%t' sets the property filename:f to the current filename without the extension. Properties beginning with filename: are a special case that can be referenced in the output filename. Here we set it to ../'%[filename:f].jpg, which ends up being the image filename with the extension replaced with .jpg in the parent directory.

Documentation references:


A simple solution would be copy, followed by mogrify - another imagemagick tool - this will keep the same names, it takes all the same args as convert.

cp *.jpg thumb/cd thumbmogrify -resize 120X120 *.JPG

Alternatively you could do a bit of shell scripting, using find -exec or xargs

# using -execfind . -iname "*.JPG" -maxdepth 1 -exec convert -resize 120x120 {} thumbs/{} \;# using xargsfind . -iname "*.JPG" -maxdepth 1 | xargs -i{} convert -resize 120x120 {} thumbs/{}


Another easy way that doesn't involve a lot of typing is GNU Parallel:

parallel convert {} -resize 120X120 thumb/{} ::: *.jpg

convert is called for each of the files given after :::, and {} is replaced with the file name for each invokation. This will also process the files in parallel, so it's likely a lot faster than the other solutions here.

It also works if you want to convert the file type:

parallel convert {} {.}.png ::: *.jpg

{.} is replaced with the filename without extension, allowing you to change it easily.