2011-05-29 28 views
0

所以我有一個用戶圖像和一個基於該圖像的用戶指定興趣點。PHP在用戶指定的點周圍創建縮略圖

我已經從XML文件中檢索到這個感興趣的點,並將它們放入變量中,所以我有2點。

X = 246 Y = 73

我的問題:如何裁剪45由53縮略圖圖像與上述座標爲縮略圖的中心點?我不希望圖像縮放,只是裁剪。

+0

通過搜索[php crop image](http://www.google.com/search?client=safari&rls=zh-CN&q=php+crop+image&ie=UTF-8&oe=UTF-8)可以更輕鬆地找到答案。 – Ibu 2011-05-29 00:32:53

+0

你有安裝在php中的gd-或imagick模塊嗎? – marsbear 2011-05-29 00:33:56

回答

2

隨着GD應該以這種方式工作:

// Open source image 
$srcImg = imagecreatefromjpeg ($filename); 

// Create new image for the cropped version 
$destImg = imagecreate (45, 53); 

// Calculate the upper left of the image-part we want to crop 
$startX = x - 45/2; 
$startY = y - 53/2; 

// Copy image part into the new image 
imagecopy ($destImg, $srcImg , 0, 0, $startX, $startY, 45, 53); 

// Write the new image with quality 90 
imagejpeg($destImg, 'newfile.jpg', 90); 

您可能要檢查圓座標,如果你不這樣做你的形象可能會變得模糊。如果用戶讓角色選擇角落爲poi,則應檢查裁剪後的圖像座標是否在原始圖像內。

+0

非常感謝! – 2011-05-29 04:36:32