2012-02-12 124 views
0

如果我有一個圖像2048×2048,我希望將圖像從頂部1488x1488像素450向下和280個像素從左imagecopyresampled裁剪

是這個正確的代碼x.png是2048×2048圖像:

<?php 

$imagesrc_location = 'x.png'; 

// Get new sizes 
list($srcwidth, $srcheight) = getimagesize($imagesrc_location); 

$imagedst = imagecreatetruecolor(1488, 1488); 
$imagesrc = imagecreatefrompng($imagesrc_location); 

if (imagecopyresampled($imagedst,$imagesrc,0,0,280,450,1488,1488,2048,2048)) { 
    // Output image 
    header('Content-type: image/png'); 
    imagepng($imagedst); 
} else { 
    echo "Could not resize file"; 

} 

這是一張圖片,顯示我想要的,灰色部分是裁剪圖片。

                                    enter image description here

回答

1

編輯:我認爲這個問題是,你的源尺寸會使imagecopyresampled規模下來。這可能適用作物:

imagecopyresampled($imagedst,$imagesrc,0,0,280,450,1488,1488,1488,1488) 

但是看看這裏:http://www.johnconde.net/blog/cropping-an-image-with-php-and-the-gd-library/ 我認爲,你想要的是:

imagecopy($imagedst,$imagesrc,0,0,280,450,1488,1488) 

http://us3.php.net/manual/en/function.imagecopy.php

http://us3.php.net/manual/en/function.imagecopyresampled.php

+0

它不是爲我工作。我給它這個:http://i.min.us/ibvzyAeW9415uv.png它提出了這個:http://i.min.us/ibyi5KbfTglN2P.png – ParoX 2012-02-13 00:11:24

+0

嘗試我發佈的新代碼,並讓我知道 – Matt 2012-02-13 04:41:58

+0

奇怪的是'imagecopyresampled($ imagedst,$ imagesrc,0,0,280,450,1488,1488,1488,1488)'和'imagecopyresampled($ imagedst,$ imagesrc,0,0,280,450,2048,2048,2048,2048)'都可以。我永遠不會完全理解這個功能。 – ParoX 2012-02-14 16:53:37