2012-03-28 45 views
1

進出口面臨的一個奇怪的問題,當我使用imagemagik轉換的圖像用PHP imagecopy的。這裏是我的代碼Imagemagik和PHP imagecopy的不保留透明度

$cmd = "convert ".realpath($temp1)." -alpha set -channel alpha -background none -vignette 0x3 ".$dest_img; 
exec($cmd); 

這段代碼的邊緣羽化,所以我可以有一個乾淨的合併。這裏是我的影像融合

$image = imagecreatefromjpeg($postcard_img); 
    $frame = imagecreatefrompng($thumb_img); 

    list($w, $h) = getimagesize($postcard_img); 
    imagealphablending($frame,true); 

    //imagecopymerge($image, $frame, $coords[0], $coords[1], 0, 0, $w, $h, 100); 
    imagecopy($image, $frame, $coords[0], $coords[1], 0, 0, $w, $h); 

代碼這裏是結果

enter image description here

現在沒事了奇怪的東西..如果我不使用ImageMagik和簡單地更換與imagecopymerge(imagecopy的()進行合併),它的工作原理,然後但留下粗糙的邊緣。這裏是)imagecopymerge的代碼(

$postcard_img = $postcard[0]["ms_filepath"].$postcard[0]["ms_filename"]; 
    $thumb_img = $thumb[0]["ms_thumbpath"].$thumb[0]["ms_thumbname"]; 

    $image = imagecreatefromjpeg($postcard_img); 
    $frame = imagecreatefrompng($thumb_img); 

    list($w, $h) = getimagesize($postcard_img); 
    imagealphablending($frame,true); 

    imagecopymerge($image, $frame, $coords[0], $coords[1], 0, 0, $w, $h, 100); 

這裏是結果(見粗糙的邊緣)

enter image description here

所有我需要的是有羽毛的形象。任何想法,爲什麼它的發生,以及如何克服呢?

+1

爲什麼不使用Imagemagick處理所有事情? – 2012-03-28 19:17:58

+0

是的,我想要走你的路,但除了imagemagik以外沒有其他辦法嗎? – casper123 2012-03-28 20:12:30

回答

1

編號抵抗是徒勞的。

convert (frame.png -channel alpha -blur 0x5 -level 50%,100%) (avatar.jpg -geometry +70+120) -compose dstover -composite output.png 

enter image description here

您隨時可以在Photoshop(或類似)與薄邊邊緣的框架,只是把一個在另一個上面。

+0

它的一個在線應用程序,所以不能使用Photoshop :) – casper123 2012-03-29 05:24:04

+0

@abdulwahabkotwal我的意思是創建框架,但從來不知道,你可以做你想要的imagemagick,命令行photoshop;) – 2012-03-29 09:37:16