phpgdlib

Resize PNG without losing quality and transparency


I have to resize images, cause we upload printable high res images and for the preview people dont need a 4000px+ image. Some images using the rgb color space "eci" and others using the color space srgb. The srgb files dont have any problems, but the eci looking a bit colourless than before. And when I upload a transparent image, its not perfect transparent. Is there any solution? When I resize and its a png image, I use following extra function.

private function imagetranstowhite($trans) {
    // Create a new true color image with the same size
    $w = imagesx($trans);
    $h = imagesy($trans);
    $white = imagecreatetruecolor($w, $h);

    // Fill the new image with white background
    $bg = imagecolorallocate($white, 255, 255, 255);
    imagefill($white, 0, 0, $bg);

    // Copy original transparent image onto the new image
    imagecopy($white, $trans, 0, 0, 0, 0, $w, $h);

    return $white;
}

Does anyone have a solution? Imagemagick instead of gdlib is fine too.


Solution

  • For people with the same problem in the future. I solved it by stopped using imagegd and switched to ImageMagick. All images are still transparent and u can easily convert cmyk images to sRGB with the correct ICC profile