Figured it out.
//Open your image and get its dimensions $image = new Imagick('image.png'); $height = $image->getImageHeight(); $width = $image->getImageWidth(); //Create a new transparent image of the same size $mask = new Imagick(); $mask->newImage($width, $height, new ImagickPixel('none')); $mask->setImageFormat('png'); //Draw onto the new image the areas you want to be transparent in the original $draw = new ImagickDraw(); $draw->setFillColor('black'); $draw->rectangle( 10,10,100,100 ); $mask->drawImage( $draw ); //Composite the images using Imagick::COMPOSITE_DSTOUT $image->compositeImage($mask, Imagick::COMPOSITE_DSTOUT, 0, 0, Imagick::CHANNEL_ALPHA);
source share