2010-02-08 104 views
1

我正在嘗試裁剪一個圓形圖像並在其周圍添加邊框。以下是我的代碼來裁剪一個圓形圖像。將圖像裁剪成圓形並添加邊框

<?php 

$img1 = imagecreateFromjpeg("./a.jpg"); 
$x=imagesx($img1)-$width ; 
$y=imagesy($img1)-$height; 


$img2 = imagecreatetruecolor($x, $y); 
$bg = imagecolorallocate($img2, 255, 255, 255); 
imagefill($img2, 0, 0, $bg); 

$e = imagecolorallocate($img2, 0, 0, 0); 

$r = $x <= $y ? $x : $y; 
imagefilledellipse($img2, ($x/2), ($y/2), $r, $r, $e); 

imagecolortransparent($img2, $e); 

imagecopymerge($img1, $img2, 0, 0, 0, 0, $x, $y, 100); 

imagecolortransparent($img1, $bg); 

header("Content-type: image/png"); 
imagepng($img1); 

imagedestroy($img2); 
imagedestroy($img1); 

?> 

任何想法或指南我可以使用PHP GD添加一個邊框嗎?

回答

4

如果您設法修剪,那麼它應該很容易。

只需創建一個黑圈,並把它2px的小圓圈,然後用圖像FIL它;)

EDIT(這是你做什麼,isnt'it?):

更精確:

現在您創建一個充滿圖像的圓圈。我建議:

  1. 創建一個圈子並與 黑色
  2. 填補它在其上創建 另一個圈子,併爲您做 現在
+0

是你建議imagearc添加您的圖像填充在它周圍繞嗎? – Teon 2010-02-09 01:30:15

+0

不,你沒有明白。我將編輯帖子以清除此問題 – naugtur 2010-02-09 11:18:55

+0

謝謝。我想我明白了。 – Teon 2010-02-09 15:25:24