Page 1 of 1

converting with max size

Posted: 2016-02-08T02:31:31-07:00
by mopi42
Hey,
Sorry for my english.
Actually, I'm using 2 command line to resize images (jpg to jpg or png to jpg depend of original type).

Code: Select all

mogrify -resize 50% /home/repository_destination *.jpg
or

Code: Select all

convert -background white -flatten -resize 50% img_src.png img_dest.jpg
1) For the second command line, how to convert a lot of .png file top .jpg 50% like the first command line ?
2) Is it possible to reduce size not with 50% but with a max size like 250ko (IMPORTANT : If origin size is > 250ko for example 5Mo, the new image must be 250ko but if origin size is < 250ko for example 200ko, the new image must be the same 200ko

This is for a website, I need to have max 250ko image (quick loading) but if origin Image is small I don't want to resize it to stay beautifull :)
And if it's possible to have just one command for png and jpg I take it :D
Thank's a lot !!!

Re: converting with max size

Posted: 2016-02-08T08:04:36-07:00
by snibgo
To reduce the number of pixels to make the output less than X bytes needs a script. You can directly reduce the quality so the output is less than X bytes:

Code: Select all

mogrify -background White -alpha remove -format JPG -define jpeg:extent=1KB *.png
See http://www.imagemagick.org/script/comma ... php#define etc.

Re: converting with max size

Posted: 2016-02-08T11:11:21-07:00
by mopi42
OK thank's but is there any way to also resize image (because I would like maximum 1500*1500)
So something like -maxsize 1500*1500 (and keep ratio so for example make an image 1500*1354)
But if the picture is less than 1500*1500 don't resize it.
So first step is resize near from 1500*1500 and second step is extend=250Ko (to have an image less than 250Ko).
Thank's a lot !

Re: converting with max size

Posted: 2016-02-08T11:13:00-07:00
by mopi42
I found this:

Code: Select all

-define jpeg:size=128x128
But I would like to keep ratio ..

Re: converting with max size

Posted: 2016-02-08T11:28:49-07:00
by snibgo
For the first step, use ">", eg:

Code: Select all

-resize 1500x1500>
See http://www.imagemagick.org/script/comma ... p#geometry

Re: converting with max size

Posted: 2016-02-08T11:32:47-07:00
by fmw42
If you are on a relatively current IM version then -define jpeg:size has been change to -define jpeg:extent. See http://www.imagemagick.org/Usage/formats/#jpg_write

For the ">", see http://www.imagemagick.org/script/comma ... p#geometry

Re: converting with max size

Posted: 2016-02-08T12:01:35-07:00
by mopi42
Thank's for your help.
I used :
for jpg images :

Code: Select all

mogrify -resize 1500x1500> -path /home/result *.jpg
and for png images :

Code: Select all

mogrify -background White -alpha remove -format JPG -resize 1500x1500> -path /home/result *.png
But 2 problems :
1) The path /home/result (destination) doesn't work and the original image changed !
2) All of images are setting to 1500 (for witdh or height depending on higher value) even if original image is 300*200 (so I don't want to resize it else it's not very beautifull I prefer to keep it small)
I don't know if my english is clear sorry if you don't understand.
Thank's again for your help

Re: converting with max size

Posted: 2016-02-08T12:45:44-07:00
by snibgo
In most shells, ">" is a special character that redirects output. So you need to escape it, with ^ in Windows or \ in bash.

Code: Select all

-resize 1500x1500^>
-resize 1500x1500\>

Re: converting with max size

Posted: 2016-02-08T13:47:36-07:00
by mopi42
Yes it works thank you very much ! You have an answer for all questions thank you !