0

when I trying to resize an PNG with

    function resize($width,$height){
    $new_image = imagecreatetruecolor($width, $height);

    if($this->image_type == IMAGETYPE_PNG || $this->type == 'image/png')
    {
        imagealphablending($new_image, false);
        imagesavealpha($new_image,true);
        $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127);
        imagefilledrectangle($new_image, 0, 0, $width, $height, $transparent);

    }

    imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
    $this->image = $new_image; 
}
function output($image_type=IMAGETYPE_JPEG, $compression=100){
    if($image_type == IMAGETYPE_JPEG){
        imagejpeg($this->image, null, $compression);
    }elseif($image_type == IMAGETYPE_GIF){
        imagegif($this->image);         
    }elseif($image_type == IMAGETYPE_PNG){
        imagepng($this->image);
    }   
}

then the background of the resized image is black, I have tried some differnt solutions bus nohting worked yet.

  • instead of `$transparent = ...` try this instead: `imagecolortransparent($new_image, imagecolorallocatealpha($new_image, 0, 0, 0, 127));` – Phiter Jan 23 '16 at 14:37
  • i was able to fix the problem: the $image_type was not set so every recaled image was an jpeg – Seb-Eisdrache Jan 24 '16 at 20:04

0 Answers0