2012-10-04 79 views
1

我在使用PHP和imagick创建缩略图时遇到了问题。代码工作正常,缩略图以正确的大小生成,但当我尝试在缩略图上放置PDF徽标时,它会变为半透明。我想这与InDesign中生成的PDF文件有关,它可能没有任何背景定义。有没有人遇到这个问题或有一个想法该怎么办呢?我试图在背景中放置一张白色的画布,但这没有帮助。我还为compositeImage函数指定了一个通道,但这也没有帮助。使用Imagick转换透明PDF文件

这是我遇到问题的PDF文件:https://dl.dropbox.com/u/13712643/Case_Study.pdf 所生成的缩略图像这样: https://dl.dropbox.com/u/13712643/Case_Study1.jpg

到目前为止,我公司生产的代码:HTTP:// pastebin.com/74CYC972

任何想法?感谢您的帮助。

+0

我有我一样的我与我的PDF缩略图功能!它很痛苦,并且将背景设置为透明并不能解决问题。如果我在不调整大小的情况下渲染图像,但透明度问题消失。 – Josiah

回答

0

我有同样的问题,我解决它通过使用Imagick::compositeImage这是在这里找到:php imagick convert PNG to jpg

代码像这样:

$im = new Imagick(); 
$im->readimage($pdfFile."[$currentPage]"); 
$res = $im->getimageresolution(); 

$bg = new Imagick(); 
$bg->setresolution($res["x"],$res["y"]); //setting the same image resolution 

//create a white background image with the same width and height 
$bg->newimage($im->getimagewidth(), $im->getimageheight(), 'white'); 
$bg->compositeimage($im, Imagick::COMPOSITE_OVER, 0, 0); //merging both images 
$bg->setimageformat("png"); 

//then you can write to a file 
$bg->writeImage('white-background-pdf-image.png'); 

//or output it 
header('Content-type: image/png'); 
echo $bg;