Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imagick::resizeImage vs Imagick::scaleImage

Tags:

What are the differences between resizeImage and scaleImage?

I need to resize an image if its size is > $myLimit

Example (pseudocode):

$myLimit = 1MB
user uplaod an image of 1000x1000 of 2MB
2MB > $myLimit
while( $imagefilesize > $myLimit  ) {
  resizeImageBy 0.9%;
}

//> output 900x900 image of 900 kB

In the while block, which of the two methods should I use?

Edit: I found something that could help: http://www.imagemagick.org/Usage/resize/ But could someone simplify that?

like image 215
dynamic Avatar asked Mar 12 '11 20:03

dynamic


2 Answers

The difference between the two seems to be that scaleImage does a raw, pixel based resize, while resizeImage can use an interpolation filter:

imagick::INTERPOLATE_AVERAGE
imagick::INTERPOLATE_BICUBIC
imagick::INTERPOLATE_BILINEAR
...

that is likely to produce better results.

More on the various interpolation methods on Wikipedia.

like image 186
Pekka Avatar answered Sep 18 '22 11:09

Pekka


Brilliant, their own documentation is awful... But ok: It looks to me like resizeImage is more powerful, and therefore the better choice... This link shows the usage along with some measurements for different filters.

like image 26
Yuri Avatar answered Sep 20 '22 11:09

Yuri