Bug Report #1963

resizing images results in error when dimensions are strange

Added by David Spiral over 5 years ago. Updated over 5 years ago.

Status:ClosedStart date:08/19/2009
Priority:NormalDue date:
Assignee:Kiall Mac Innes% Done:


Target version:2.4
Resolution:fixed Points:


Hi there,

When resizing an image using Image helper and GD driver, an error occurs if the scaled height or width rounds to zero

I 'thumbnailed' an image of dimensions 2000 x 7 down to fit a thumbnail area of 120x120. This resulted in the GD Driver being asked to resize the image to 120 x 0, due to rounding.

$thumbnail = Image::factory($filename)->resize(120,120)->save();

(where $filename is an image processed through upload::save previously, of extreme height/width ratio)

Expected Results:

Resized, valid image.
For the above example, expected result would be 120 x 1 image

Actual results:

An error was detected which prevented the loading of this page. If this problem persists, please contact the website administrator.

/sitename/system/libraries/drivers/Image/GD.php [367]:

imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions

Stack Trace

  • /sitename/system/libraries/drivers/Image/GD.php [367]:

imagecreatetruecolor( 120 )

  • /sitename/system/libraries/drivers/Image/GD.php [271]:

Image_GDCustom_Driver->imagecreatetransparent( 120 )

Note that imagecreatetransparent is being passed 120 x 0 as the dimensions of the image to resize to


I solved the problem on my local installation by creating a new driver, which extends Image_GD_Driver
I set my system to use the new driver, and wrapped the call to imagecreatetransparent thus:

protected function imagecreatetransparent ($width, $height)
    if ($width < 1) $width = 1;
    if ($height < 1) $height = 1;

    return parent::imagecreatetransparent($width, $height);

Associated revisions


#1 Updated by David Spiral over 5 years ago

Sorry, after re-reading the ticket submission guidelines, this should have been set to version 2.4.3 instead of SVN Head and an appropriate target version - my bad :(

#2 Updated by Jeremy Bush over 5 years ago

  • Assignee set to Kiall Mac Innes
  • Target version set to 2.4

#3 Updated by Kiall Mac Innes over 5 years ago

  • Status changed from New to Closed
  • % Done changed from 0 to 100

Applied in changeset r4518.

#4 Updated by Kiall Mac Innes over 5 years ago

  • Resolution set to fixed

Also available in: Atom PDF