I have the following code to create a png swatch with a drop shadow (to dynamically insert in a PDF file using FPDF.)
$shadowSwatch = $pm->clone() ;
$shadowSwatch->setImageBackgroundColor('#000000') ;
//Angle & Offset of Drop Shadow based on photoshop settings
$angle = deg2rad(45) ;
$xOffset = round(sin($angle) * 18, 0) ;
$yOffset = round(cos($angle) * 18, 0) ;
//Shadow Image seems to take extra time
ini_set('max_execution_time', 300) ;
$shadowSwatch->shadowImage(8, 8, $xOffset, $yOffset) ;
//Overlay original image on its shadow
$shadowSwatch->compositeImage($pm, Imagick::COMPOSITE_OVER, 0, 0) ;
//Attempts at forcing consistent output
$shadowSwatch->flattenImages();
$shadowSwatch->setImageColorspace(13);
$shadowSwatch->setImageDepth(32);
$shadowSwatch->setImageFormat('PNG32');
//Save Swatch
$shadowSwatch->writeImage($swatchDestination) ;
My problem is that I need to have it consistently output the same bit depth on writeImage ... and it isn't. Occasionally it outputs 64 bit PNGs when FPDF can only handle 32bit (8 per RGBA.)
Any advice on getting consistent bit depth from Imagick PNGs will be greatly appreciated!