Retain PNG transparency.

Transparency data will be saved when cropping or resizing.
This commit is contained in:
Hakim Zulkufli 2017-04-30 17:03:33 +08:00
parent dc553bae2f
commit aebaed2a8c
1 changed files with 4 additions and 0 deletions

View File

@ -108,6 +108,8 @@ class Image {
// *** Resample - create image canvas of x, y size
$this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
imagealphablending($this->imageResized, false);
imagesavealpha($this->imageResized, true);
imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);
@ -230,6 +232,8 @@ class Image {
// *** Now crop from center to exact requested size
$this->imageResized = imagecreatetruecolor($newWidth , $newHeight);
imagealphablending($this->imageResized, false);
imagesavealpha($this->imageResized, true);
imagecopyresampled($this->imageResized, $crop , 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight , $newWidth, $newHeight);
}
}