Created
December 1, 2014 15:34
-
-
Save delboy1978uk/3b64896769c992081129 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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