Per GPG guidelines, photo IDs should be about 240x288 pixels and 4k-6k in size. I used: convert -resize 240x240 -quality 75 original.jpg gpguid.jpg
. However, the resulting file is still 17k. Specifically, I am curious what options I have before decreasing the quality level.

- 1,176
- 7
- 23
-
Thanks @ryan-vincent, I was actually wondering if there were other optimisations I could do before decreasing the quality. – Carlos Macasaet Sep 27 '15 at 22:21
-
1I would not really care about 16kB image size at all. 16kB roughly equivs four certifications on your key made using 4k RSA keys. – Jens Erat Sep 28 '15 at 07:03
2 Answers
This is the command I settled on: convert -resize 240x240 -quality 55 -strip -sampling-factor 4:2:0 original.jpg gpguid.jpg
.
The original command yielded a file that was 17,169 bytes. The -strip
argument brought the size down to 10,226 bytes by removing profiles and comments. The -sampling-factor
argument reduced the size to 8,315 bytes by cutting the chroma channel's resolution in half without affecting the luminance resolution. Finally, turning down the quality to 55 brought me within the recommended 6K.

- 1
- 1

- 1,176
- 7
- 23
ImageMagick has a feature that allows you to set a maximum output file size, and you may find you get on better letting it do that rather than arbitrarily reducing quality to the point that all photos are within the specified size - that way you should hopefully retain as much quality as possible:
convert input.jpg -strip -resize 240x240 -define jpeg:extent=6kb result.jpg
The above command will result in a file just under 6kB.
If you want a way to do something similar with Python, I wrote an answer that works pretty well here. It does a binary search for a JPEG quality that satisfies a maximum size requirement.

- 191,897
- 31
- 273
- 432