如果我有一张图像2048 x 2048,我想要一张图像1488x1488从顶部向下450像素,向左向下280像素
这是正确的代码x.png是2048 x 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";
}
这是一张显示我想要的图片,灰色部分是裁剪的图片。
答案 0 :(得分: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