Ticket #726 (closed Patch: fixed)

Opened 4 months ago

Last modified 4 months ago

Image library : GD driver, error in assigning resize AUTO property

Reported by: ae Owned by: Geert
Priority: minor Milestone: 2.2
Component: Libraries:Image Version: SVN HEAD
Keywords: Image, GD, driver Cc:

Description

When using the resize method you can assign Image::AUTO so that the driver will work out whether it should use the width or height of the image to base the resize on. The problem is that the logic to determine the base property (width OR height) is not correct.

Example: The source image has a width and height of 800 x 600

$image->resize(740,400,Image::AUTO)->quality(80)->save();

In the GD driver it works out whether to use w or h to base the resize on by::

$properties['master'] = ($width > $height) ? Image::WIDTH : Image::HEIGHT;

However, because in the example above the w is greater then the h it bases the resize on the width. This means the resulting resized image is 740 x 555, where the height is GREATER then the height submitted to the method.

The fix for this is to change the way the driver calculates the base to do the resize. Basically by checking the percentage difference between the w and h:

$properties['master'] = (($width / $properties['width']) > ($height / $properties['height'])) ? Image::WIDTH : Image::HEIGHT;

This returns an image of 533x400 which is correct.

The change is for line 197 of the GD library.

Change History

Changed 4 months ago by Geert

  • owner changed from - No owner - to Geert
  • status changed from new to assigned

Changed 4 months ago by Geert

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r3241. Good catch, thanks!

Note: See TracTickets for help on using tickets.