-1

我正在使用一个脚本来帮助用户上传他们的个人资料图像,然后裁剪它们以选择方便的位置 我对未显示的 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);
     }
      }
     ?>
4

1 回答 1

0

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

如果输入文件是 jpeg,则调用imagecreatefromjpegimagejpeg.
如果输入文件是 png,则调用imagecreatefrompngimagepng.
如果输入文件是 gif,则调用imagecreatefromjpegimagegif.

于 2012-09-30T22:07:53.157 回答