--- library/simplegd/classes/SimpleGdImage.class.old.php 2008-08-19 09:04:23.000000000 -0400 +++ library/simplegd/classes/SimpleGdImage.class.php 2008-08-19 09:35:06.000000000 -0400 @@ -290,17 +290,28 @@ $width = (integer) $width > 0 ? (integer) $width : 1; $height = (integer) $height > 0 ? (integer) $height : 1; - if ($this->getImageType() == IMAGETYPE_GIF) { - $new_resource = imagecreatetruecolor($new_width, $new_height); - $colorcount = imagecolorstotal($this->resource); - imagetruecolortopalette($new_resource, true, $colorcount); - imagepalettecopy($new_resource, $this->resource); - $transparentcolor = imagecolortransparent($this->resource); - imagefill($new_resource, 0, 0, $transparentcolor); - imagecolortransparent($new_resource, $transparentcolor); - } else { - $new_resource = imagecreatetruecolor($width, $height); - } // if + switch($this->getImageType()) { + case IMAGETYPE_GIF: + $new_resource = imagecreatetruecolor($new_width, $new_height); + $colorcount = imagecolorstotal($this->resource); + imagetruecolortopalette($new_resource, true, $colorcount); + imagepalettecopy($new_resource, $this->resource); + $transparentcolor = imagecolortransparent($this->resource); + imagefill($new_resource, 0, 0, $transparentcolor); + imagecolortransparent($new_resource, $transparentcolor); + break; + + case IMAGETYPE_PNG: + $new_resource = imagecreatetruecolor($new_width, $new_height); + $background = imagecolorallocate($new_resource, 0, 0, 0); + ImageColorTransparent($new_resource, $background); + imagealphablending($new_resource, false); + break; + + default: + $new_resource = imagecreatetruecolor($new_width, $new_height); + break; + } imagecopyresampled($new_resource, $this->resource, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); if ($mutate) { @@ -364,17 +375,28 @@ $new_width = floor($scale * $this->getWidth()); $new_height = floor($scale * $this->getHeight()); - if ($this->getImageType() == IMAGETYPE_GIF) { - $new_resource = imagecreatetruecolor($new_width, $new_height); - $colorcount = imagecolorstotal($this->resource); - imagetruecolortopalette($new_resource, true, $colorcount); - imagepalettecopy($new_resource, $this->resource); - $transparentcolor = imagecolortransparent($this->resource); - imagefill($new_resource, 0, 0, $transparentcolor); - imagecolortransparent($new_resource, $transparentcolor); - } else { - $new_resource = imagecreatetruecolor($new_width, $new_height); - } // if + switch($this->getImageType()) { + case IMAGETYPE_GIF: + $new_resource = imagecreatetruecolor($new_width, $new_height); + $colorcount = imagecolorstotal($this->resource); + imagetruecolortopalette($new_resource, true, $colorcount); + imagepalettecopy($new_resource, $this->resource); + $transparentcolor = imagecolortransparent($this->resource); + imagefill($new_resource, 0, 0, $transparentcolor); + imagecolortransparent($new_resource, $transparentcolor); + break; + + case IMAGETYPE_PNG: + $new_resource = imagecreatetruecolor($new_width, $new_height); + $background = imagecolorallocate($new_resource, 0, 0, 0); + ImageColorTransparent($new_resource, $background); + imagealphablending($new_resource, false); + break; + + default: + $new_resource = imagecreatetruecolor($new_width, $new_height); + break; + } imagecopyresampled($new_resource, $this->resource, 0, 0, 0, 0, $new_width, $new_height, $this->getWidth(), $this->getHeight()); if ($mutate) {