Batch reset horizontal size without major increase in filesize

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Iftikhar Zaman
Posts: 2
Joined: 2020-02-03T19:42:07-07:00
Authentication code: 1152

Batch reset horizontal size without major increase in filesize

Post by Iftikhar Zaman »

ALERT:I am new to graphics, new to IM!
I HAVE spent two weeks trying to solve this simple problem.
I have a batch of pictures of passport pages from my phone camera. They are around 300k each, jpg.
Before making a pdf of them I want to set them to the same horizontal size so that the pdf scrolls smoothly when used.
"identify *.jpg" shows horizontal size around 2000 so I use

mogrify -resize 2000 *.jpg

But filesize increases about three times?! I try

convert *.jpg -gravity center -extent 2000

but that also increases filesize many times. So: is there are way to batch reset width on jpegs before creating a pdf out of them without major increase in filesize?

Here is a link to ten of the files I am working with.

https://www.dropbox.com/sh/hl029ro0thfz ... 0xdYa?dl=0

[Using Raspberry Pi running Debian 10 Buster]

User avatar
fmw42
Posts: 26262
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch reset horizontal size without major increase in filesize

Post by fmw42 »

Add -quality before saving to JPG in mogrify or convert.

Or with convert, use -define jpeg:extent=size in kbytes.

See https://imagemagick.org/Usage/formats/#jpg_write

Your convert command is not correct. It needs an output name specified. So with convert, you will have to loop over each input and write one corresponding output. If you use wildcards in the input to convert and specify one single output name, then it will make multiple images with number appended such as file-0, file-1, etc.

snibgo
Posts: 12899
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Batch reset horizontal size without major increase in filesize

Post by snibgo »

I suggest "-quality 50%" to get a similar size with hardly any difference to the image.
snibgo's IM pages: im.snibgo.com

Iftikhar Zaman
Posts: 2
Joined: 2020-02-03T19:42:07-07:00
Authentication code: 1152

Re: Batch reset horizontal size without major increase in filesize

Post by Iftikhar Zaman »

Excellent! -quality 50% works great. I guess I was expecting the default conversion to preserve filesize: but my expectations are based on ignorance and hence cannot be relied upon! Thanks a lot.
(fmw42: No need for output filename as mogrify modifies the files in place)

User avatar
fmw42
Posts: 26262
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Batch reset horizontal size without major increase in filesize

Post by fmw42 »

(fmw42: No need for output filename as mogrify modifies the files in place)
I was referring to convert not mogrify. Convert needs an output file name.

Imagemagick will use the quality in the input if it was specified in the file; otherwise it uses 92. So 50 is much lower quality than the default 92. I guess your JPG files did not record the quality value.

Post Reply