Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.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 GD裁剪PNG不';行不通_Php_Image_Png_Jpeg_Crop - Fatal编程技术网

PHP GD裁剪PNG不';行不通

PHP GD裁剪PNG不';行不通,php,image,png,jpeg,crop,Php,Image,Png,Jpeg,Crop,我正在创建一个使用PHP GD裁剪图像的函数。 该功能对JPEG图像非常有效,但当我尝试对PNG使用相同的功能时,我只得到一个空白页面,并且在chrome中检查页面时出现以下错误: 我意识到这是一个javascript错误,但这可能是chrome所做的?这就是我访问图像URL时发生的情况。如果我用JPEG代码复制它,它会工作得很好 编辑:在Firefox中,它说“图像[URL]无法显示,因为它包含错误。下面的js错误只是一个chrome错误,与此无关。” 未捕获的TypeError:无法读取nu

我正在创建一个使用PHP GD裁剪图像的函数。 该功能对JPEG图像非常有效,但当我尝试对PNG使用相同的功能时,我只得到一个空白页面,并且在chrome中检查页面时出现以下错误:

我意识到这是一个javascript错误,但这可能是chrome所做的?这就是我访问图像URL时发生的情况。如果我用JPEG代码复制它,它会工作得很好

编辑:在Firefox中,它说“图像[URL]无法显示,因为它包含错误。下面的js错误只是一个chrome错误,与此无关。”

未捕获的TypeError:无法读取null的属性“getAttribute” data_loader.js:2未捕获类型错误:无法读取属性 空全局快捷方式的“hasAttribute”。js:9

工作JPEG代码如下所示:

$fileName = $_POST['file'];
$jpeg_quality = 100;
$ratio = $_POST['r'];

$src = '/var/www/admin/public_html/images/'.$fileName;
$image = imagecreatefromjpeg($src);
$target = '/var/www/admin/public_html/images/crop/'.$fileName;

$thumb_width = $_POST['w'] / $ratio;
$thumb_height = $_POST['h'] / $ratio;

$width = imagesx($image);
$height = imagesy($image);

$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );

// Resize and crop
imagecopyresampled($thumb,
                   $image,
                   0,
                   0, 
                   $_POST['x'] / $ratio, $_POST['y'] / $ratio,
                   $width, $height,
                   $width, $height);

imagejpeg($thumb, $target, $jpeg_quality);
$fileName = $_POST['file'];
$jpeg_quality = 100;
$ratio = $_POST['r'];

$src = '/var/www/admin/public_html/images/'.$fileName;
$image = imagecreatefrompng($src);
$target = '/var/www/admin/public_html/images/crop/'.$fileName;

$thumb_width = $_POST['w'] / $ratio;
$thumb_height = $_POST['h'] / $ratio;

$width = imagesx($image);
$height = imagesy($image);

$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );

// Resize and crop
imagecopyresampled($thumb,
                   $image,
                   0,
                   0, 
                   $_POST['x'] / $ratio, $_POST['y'] / $ratio,
                   $width, $height,
                   $width, $height);

imagepng($thumb, $target, $jpeg_quality);
破损的PNG代码如下所示:

$fileName = $_POST['file'];
$jpeg_quality = 100;
$ratio = $_POST['r'];

$src = '/var/www/admin/public_html/images/'.$fileName;
$image = imagecreatefromjpeg($src);
$target = '/var/www/admin/public_html/images/crop/'.$fileName;

$thumb_width = $_POST['w'] / $ratio;
$thumb_height = $_POST['h'] / $ratio;

$width = imagesx($image);
$height = imagesy($image);

$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );

// Resize and crop
imagecopyresampled($thumb,
                   $image,
                   0,
                   0, 
                   $_POST['x'] / $ratio, $_POST['y'] / $ratio,
                   $width, $height,
                   $width, $height);

imagejpeg($thumb, $target, $jpeg_quality);
$fileName = $_POST['file'];
$jpeg_quality = 100;
$ratio = $_POST['r'];

$src = '/var/www/admin/public_html/images/'.$fileName;
$image = imagecreatefrompng($src);
$target = '/var/www/admin/public_html/images/crop/'.$fileName;

$thumb_width = $_POST['w'] / $ratio;
$thumb_height = $_POST['h'] / $ratio;

$width = imagesx($image);
$height = imagesy($image);

$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );

// Resize and crop
imagecopyresampled($thumb,
                   $image,
                   0,
                   0, 
                   $_POST['x'] / $ratio, $_POST['y'] / $ratio,
                   $width, $height,
                   $width, $height);

imagepng($thumb, $target, $jpeg_quality);

我回答了我自己的问题。 函数的取值范围为0到9
imagejpeg()函数的质量参数从0到100

这是一个JS错误…您需要显示该代码。我知道这是一个JS错误,但没有代码,这是我访问图像URL时发生的。@MarcB