Score:1

Resize image to specific size

cn flag

I know there are several ways to resize an image via the command line. Some of them are specified here. However, I was wondering whether there is a way to specify the size of the resized image, e.g. I want to resize an image that is 8.5 MB big to an image that is 2.5 MB. Preferably, the solution uses imagemagick.

Levente avatar
cn flag
Do you want to achieve the reduction solely through image data compression, or are you ready to change image resolution (pixel count) too?
hyhno01 avatar
cn flag
I prefer data compression. The goal is to achieve the best image quality, but reduce the size so that I can upload the image to an online-forum
vanadium avatar
cn flag
Resize the image to the resolution of a screen (i.e., HD is 1920x1080) and you will already have an image far less than 8 MB *and* in max quality for screen display.
hyhno01 avatar
cn flag
Thanks for the recommendation. Though it does not solve my problem. The ratios of the images may differ (2:3, 3:4, 16:19 etc.) and I want to make sure that every image ends up being 2.5 MB which is the maximal size for upload in the forum and thus ensures the best quality
vanadium avatar
cn flag
Yes it does. And no, 2,5 MB is not necessarily ensuring the best quality. For on screen display, it probably will be overkill. Start with reducing the size to the display resolution. That will usually bring you already below 2 MB. If that doesn't, increase the jpeg compression until it does. The result will be very acceptable. If it is only a few images, Gimp allows to see the resulting file size while you tweak the compression settings.
vanadium avatar
cn flag
I found an obscure setting allowing to set the maximum size: see my answer. Still, for your application, prefer to adjust the image to the screen display resolution first. You can go much lower than 2 Mb for optimum on screen display.
Score:3
cn flag

With credit to here, there is a jpeg codec option for Imagemagick's convert supports an option for jpeg that allows to restrict the size of the output file: -define jpeg:extent=max_value. It is used as:

convert test.jpg -define jpeg:extent=1M testout.jpg

If anyone could tell where such settings are officially documented, I will include it in this answer.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.