Skip to content

Instantly share code, notes, and snippets.

@delboy1978uk
Created December 1, 2014 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delboy1978uk/3b64896769c992081129 to your computer and use it in GitHub Desktop.
Save delboy1978uk/3b64896769c992081129 to your computer and use it in GitHub Desktop.
/**
* Now with added Transparency resizing feature
* @param int $width
* @param int $height
*/
public function resize($width,$height)
{
$new_image = imagecreatetruecolor($width, $height);
if ( ($this->getImageType() == IMAGETYPE_GIF) || ($this->getImageType() == IMAGETYPE_PNG) )
{
$transparency = imagecolortransparent($this->_image);
if ($transparency >= 0)
{
$transparent_color = imagecolorsforindex($this->_image, $transparency);
$transparency = imagecolorallocate($new_image, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
imagefill($new_image, 0, 0, $transparency);
imagecolortransparent($new_image, $transparency);
}
elseif ($this->getImageType() == IMAGETYPE_PNG)
{
imagealphablending($new_image, false);
imagesavealpha($new_image, true);
$color = imagecolorallocatealpha($new_image, 0, 0, 0, 127);
imagefill($new_image, 0, 0, $color);
}
}
imagecopyresampled($new_image, $this->_image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->_image = $new_image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment