Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a lot of .png images in a folder. Is there a command (or software) that can convert all them to .jpg and (simultaneously) rescale the created .jpg files to 25% of their original size?

share|improve this question

2 Answers 2

up vote 12 down vote accepted

Use the convert command from ImageMagick:

convert x.png -resize 25% x.jpg

will create a 25%-scaled JPEG version of x.png.

To do all the PNG files at once, use a for loop:

for filename in *.png ; do convert "$filename" -resize 25% "${filename%.png}.jpg" ; done

We look at every file matching *.png, and for each one run the convert command above. "${filename%.png}.jpg" generates the .jpg filename for each .png: it removes the extension with % and puts .jpg back on the end.

share|improve this answer

You could use mogrify to batch convert & resize all .png images in the current directory:

mogrify -resize 25% -format jpg *.png

because it uses -format jpg the original .png images are left untouched
(when format is the same or missing the originals are overwritten).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.