Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ImageCopy重采样裁剪_Php_Image_Crop - Fatal编程技术网

Php ImageCopy重采样裁剪

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,

如果我有一张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";

}

编辑:我认为问题在于,您的源代码大小将使
图像重新采样
缩小它的比例。这可能适用于作物:

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)
这两种方法都有效。我永远不会完全理解这个函数。我不是专家,但我认为你在函数末尾传递的两个“大小”只会影响缩放。因此,如果它们是相同的,那么显然它不会进行缩放(无论实际图像大小如何)。