您好我添加了一个简单的图片大小调整,这会破坏我的GIF动画。有人可以帮我解释一下我需要从现有代码中删除哪些内容以允许上传图像然后以GIF格式动画...感谢您的任何输入。
case 'addgift':
if($adminLevel == 4)
{
if ($_FILES['uploadedfile']['tmp_name'] != "")
{
$image = new SimpleImage();
$image->load($_FILES['uploadedfile']['tmp_name']);
$width = $image->getWidth();
$height = $image->getHeight();
if($width > 64) {
$height = (64/$width)*$height;
$width = 64;
}
if($height > 64) {
$width = (64/$height)*$width;
$height = 64;
}
$image->resize($width,$height);
if(preg_match("/\.(png)$/i", $_FILES['uploadedfile']['name']))
$type = IMAGETYPE_PNG;
else if(preg_match("/\.(gif)$/i", $_FILES['uploadedfile']['name']))
$type = IMAGETYPE_GIF;
else
$type = IMAGETYPE_JPEG;
$image->save("images/gifts/".$_FILES['uploadedfile']['name'], $type);
unlink($_FILES['uploadedfile']['tmp_name']);
mysql_query("INSERT INTO gifts
(name, image, cash, tokens)
VALUES ('".mysql_real_escape_string($_POST['name'])."', '".$_FILES['uploadedfile']['name']."', ".intval($_POST['cash']).", ".intval($_POST['tokens']).")");
mysql_query("INSERT INTO admin_actions
(id1, id2, action, extra, time)
VALUES($userid, 0, '{id1} added gift \"{extra}\".', '".mysql_real_escape_string($_POST['name'])."', UNIX_TIMESTAMP())");
}
}
break;
答案 0 :(得分:0)
答案 1 :(得分:0)
我不知道你的lib是否支持这样的事情。您可以做的是检查图像是否已达到尺寸限制,并保持不变,以防万一。
- $image->resize($width,$height);
- $image->save("images/gifts/".$_FILES['uploadedfile']['name'], $type);
- unlink($_FILES['uploadedfile']['tmp_name']);
+ if ($image->getWidth() == $width && $image->getHeight() == $height)
+ move_uploaded_file($_FILES['uploadedfile']['tmp_name'], "images/gifts/".$_FILES['uploadedfile']['name']);
+ else
+ {
+ $image->resize($width,$height);
+ $image->save("images/gifts/".$_FILES['uploadedfile']['name'], $type);
+ unlink($_FILES['uploadedfile']['tmp_name']);
+ }