我有以下代码来创建带阴影的png样例(使用FPDF动态插入PDF文件。)
$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) ;
我的问题是我需要在writeImage上始终输出相同的位深度......而事实并非如此。当FPDF只能处理32位(每个RGBA 8个)时,偶尔会输出64位PNG。
任何有关从Imagick PNG获得一致位深度的建议都将非常感谢!
答案 0 :(得分:3)
我找到了答案。使用imagick替换在PNG中提供一致的位深度:
$shadowSwatch->setColorspace(13);
$shadowSwatch->setImageDepth(32);
使用:
$shadowSwatch->setOption('png:color-type', 6);
$shadowSwatch->setOption('png:bit-depth', 8);