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