Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.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 显示裁剪图像_Php_Crop_Php Gd - Fatal编程技术网

Php 显示裁剪图像

Php 显示裁剪图像,php,crop,php-gd,Php,Crop,Php Gd,我正在使用一个脚本,帮助用户上传他们的个人资料图像,然后裁剪它们以选择方便的位置 我对未显示的PNG和GIF图像有问题 这是裁剪文件代码,请修改它以使其能够显示PNG、JPF和GIF图像 <?php sleep(1); $url = $_GET['url']; $type = $_GET['type']; if ($type='jpg') { if(file_exists($url) AND preg_match('/^[a-z0-9\/_\-.]+$/i',$url)){

我正在使用一个脚本,帮助用户上传他们的个人资料图像,然后裁剪它们以选择方便的位置 我对未显示的PNG和GIF图像有问题 这是裁剪文件代码,请修改它以使其能够显示PNG、JPF和GIF图像

<?php
 sleep(1);
 $url = $_GET['url'];
 $type = $_GET['type'];
 if ($type='jpg') {
    if(file_exists($url) AND preg_match('/^[a-z0-9\/_\-.]+$/i',$url)){
$width  =   (isset($_GET['width'])  AND preg_match('/^[0-9]{2,}$/', $_GET['width']))    ? $_GET['width']    : 300;
$height =   (isset($_GET['height']) AND preg_match('/^[0-9]{2,}$/', $_GET['height']))   ? $_GET['height']   : 300;
$left   =   (isset($_GET['left'])   AND is_numeric($_GET['left']))  ? $_GET['left']     : 0;
$top    =   (isset($_GET['top'])    AND is_numeric($_GET['top']))       ? $_GET['top']      : 0;
header ("Content-type: image/jpg");
$src    =   @imagecreatefromjpeg($url);
$im     =   @imagecreatetruecolor($width, $height);
imagecopy($im,$src,0,0,-$left,-$top,$width,$height);
imagejpeg($im,"",300);
imagedestroy($im);}}

    elseif ($type='png') {

     if(file_exists($url) AND preg_match('/^[a-z0-9\/_\-.]+$/i',$url)){
$width  =   (isset($_GET['width'])  AND preg_match('/^[0-9]{2,}$/', $_GET['width']))    ? $_GET['width']    : 300;
$height =   (isset($_GET['height']) AND preg_match('/^[0-9]{2,}$/', $_GET['height']))   ? $_GET['height']   : 300;
$left   =   (isset($_GET['left'])   AND is_numeric($_GET['left']))  ? $_GET['left']     : 0;
$top    =   (isset($_GET['top'])    AND is_numeric($_GET['top']))       ? $_GET['top']      : 0;
header ("Content-type: image/png");
$src    =   @imagecreatefrompng($url);
$im     =   @imagecreatetruecolor($width, $height);
imagecopy($im,$src,0,0,-$left,-$top,$width,$height);
imagepng($im,"",300);
imagedestroy($im);
     }
      }
     ?>

您必须检查输入文件的格式,然后调用支持的函数

如果输入文件是jpeg,请调用
imagecreatefromjpeg
imagejpeg

如果输入文件是png,请调用
imagecreatefrompng
imagepng


如果输入文件是gif,请调用
imagecreatefromjpeg
imagegif

或者从图像数据中使用
imagecreatefromstring()
,并在确定其类型后使用
imageTYPE()
函数之一。不起作用我添加了$type=$\u GET['type'];和elseif($type='png')$\u GET['type']的值是多少?你100%确定它是正确的吗?另外,您应该使用
switch(){}
而不是巨大的
elseif
块将获得图像的扩展。这是完整的url:data/result\u crop\u img.php?tr=crop.php?url=img\u upload\u profile/6348877.jpg&top=0&left=-175&type=png移动
内容类型
标题,查看是否输出错误。查看
过滤器变量
并采用适当的编码样式。