Is it better to resize one time or it's ok to do it several time ?

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
loki5100
Posts: 22
Joined: 2018-02-24T14:51:41-07:00
Authentication code: 1152

Is it better to resize one time or it's ok to do it several time ?

Post by loki5100 » 2018-02-27T09:53:20-07:00

I need to create several variation of a picture in several resolutions like :

original size = 2048x2048
1280x1280
800x800
640x640
480x480
360x360
240x240
150x150
100x100

Actually i always resize each variation from the original size like this :

2048x2048 => 1280x1280
2048x2048 => 800x800
2048x2048 => 640x640
2048x2048 => 480x480
2048x2048 => 360x360
2048x2048 => 240x240
2048x2048 => 150x150
2048x2048 => 100x100

but it's a little longer and maybe i can do something like this :

2048x2048 => 1280x1280
1280x1280 => 800x800
800x800=> 640x640
640x640 => 480x480
480x480=> 360x360
360x360=> 240x240
240x240=> 150x150
150x150=> 100x100

But does the quality of the image will be the same ? or doing resizing on the top of resizing will degrade the quality of the final result ?

Bonzo
Posts: 2968
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Is it better to resize one time or it's ok to do it several time ?

Post by Bonzo » 2018-02-27T10:10:36-07:00

Try one of these - php code but you should get the idea:

Code: Select all

$cmd = "input.jpg -write mpr:image +delete ".
" \( mpr:image -thumbnail x480 -write 480_wide.jpg \) ".
" \( mpr:image -thumbnail x250 -write 250_wide.jpg \) ".
" \( mpr:image -thumbnail x100 -write 100_wide.jpg \) ".
" \( mpr:image -thumbnail 64x64! -write 64_square.jpg \) ".
" \( mpr:image -colorspace Gray -write black_white.jpg \)";
exec("convert $cmd ");
Reads the image into memory and then deletes the original. Uses the memory image to create the others

Code: Select all

$cmd = " input.jpg \( -clone 0 -thumbnail x480 -write 480_wide.jpg +delete \)".
" \( -clone 0 -thumbnail x250 -write 250_wide.jpg +delete \) ".
" \( -clone 0 -thumbnail x100 -write 100_wide.jpg +delete \) -thumbnail 64x64! null: ";
exec("convert $cmd 64_square.jpg ");
Again reads the image into memory but clones it each time.

Both read the original image once and wok on it so should be fater than what you are doing.

Infrid
Posts: 3
Joined: 2018-02-27T06:52:27-07:00
Authentication code: 1152

Re: Is it better to resize one time or it's ok to do it several time ?

Post by Infrid » 2018-02-28T03:12:23-07:00

theoretically the quality will be degraded if you don't start from the original one, if you need to speed up and save up memory and the quality is overall acceptable, you can chain the resize process in that way.

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

Re: Is it better to resize one time or it's ok to do it several time ?

Post by fmw42 » 2018-02-28T10:25:43-07:00

It really depends upon the type of artifacts you are willing to accept. If you shrink an image a very large amount, then the resampling is skipping lots of pixels. If you resize in steps, then you involve more of the original pixels, but the multiple resampling may cause more smoothing.

Post Reply