Php ImageCopy重采样裁剪
如果我有一张2048 x 2048的图像,我想要一张1488x1488的图像,从上往下看450像素,从左往下看280像素 这是正确的代码x.png是2048 x 2048图片:Php ImageCopy重采样裁剪,php,image,crop,Php,Image,Crop,如果我有一张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,
<?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";
}
编辑:我认为问题在于,您的源代码大小将使图像重新采样
缩小它的比例。这可能适用于作物:
imagecopyresampled($imagedst,$imagesrc,0,0,280,450,1488,1488,1488,1488)
但看看这里:
我想你想要的是:
imagecopy($imagedst,$imagesrc,0,0,280,450,1488,1488)
它对我不起作用。我给它这样的解释:它得出这样的结论:奇怪的是,imagecopyresampled($imagedst,$imagesrc,0,02804501488148814881488)
和imagecopyresampled($imagedst,$imagesrc,0,02804502048204820482048)
这两种方法都有效。我永远不会完全理解这个函数。我不是专家,但我认为你在函数末尾传递的两个“大小”只会影响缩放。因此,如果它们是相同的,那么显然它不会进行缩放(无论实际图像大小如何)。