I’m building an application that resizes clients logo to a certain width/height and also want to add a transparent background. I’m using iMagick and PHP. The following code does not create an image with a transparent background (just creates it on white). What do I need to change? This has been driving me mad.
$thumb = new Imagick($original); $thumb->thumbnailImage($width,$height,true); /* create canvas */ $canvas = new Imagick(); $canvas->newImage($width, $height, new ImagickPixel('transparent'), 'png'); $geometry = $thumb->getImageGeometry(); $x = ($width - $geometry['width']) / 2; $y = ($height - $geometry['height']) / 2; $canvas->compositeImage($thumb, imagick::COMPOSITE_OVER, $x, $y); $canvas->writeImage($new_file); $canvas->destroy();
Thanks in advance.