2012-10-04 70 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;