我使用一个脚本,帮助用户上传自己的个人资料图片,然后裁剪他们选择合适的位置 我有他们未显示 这与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);
}
}
?>
请查看'filter_var'并采用适当的编码风格。 – Gordon