Need help to create transparent image using iMagick

Hi!

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.

You could just create a transparent PNG and overlay the logo onto that; I guess this might not work though if your width and height’s are to be dynamic (unless you made a really big transparent image, cropped it and then used that?)

How can I do this using Imagick? I want to use that class as the images come out at a better quality.

Thanks.