Php 对于某些PNG图像文件,imagecreatefromstring返回false
我有一个图像库,用户可以上传图像,上传图像后,PHP脚本创建它的两个副本-一个用于缩略图,另一个用于在库中显示更大的尺寸 该应用程序运行良好,只是在上传一些PNG图片时,语句Php 对于某些PNG图像文件,imagecreatefromstring返回false,php,image-processing,return-value,image-gallery,false-positive,Php,Image Processing,Return Value,Image Gallery,False Positive,我有一个图像库,用户可以上传图像,上传图像后,PHP脚本创建它的两个副本-一个用于缩略图,另一个用于在库中显示更大的尺寸 该应用程序运行良好,只是在上传一些PNG图片时,语句 if($image=@imagecreatefromstring($filedata)) 返回false 下面是脚本。请帮忙 <!---------------Processing uploaded image-----------------> <?php if (isset($_FILES
if($image=@imagecreatefromstring($filedata))
返回false
下面是脚本。请帮忙
<!---------------Processing uploaded image----------------->
<?php
if (isset($_FILES['file1']))
{
if($fgmembersite->CheckLogin())
{
if($_FILES['file1']['error']>0)
{
echo "file upload error".$_FILES['file1']['error'];
}
else
{
$allowedtype=array('image/jpg','image/jpeg','image/pjpeg','image/gif','image/png');
$maxsize=10*1024*1024;
$filename= mysql_real_escape_string($_FILES['file1']['name']);
$tmp_name=$_FILES['file1']['tmp_name'];
$size=$_FILES['file1']['size'];
$type=$_FILES['file1']['type'];
$ext=$filename;
if (!in_array($type,$allowedtype))
{
die ('Invalid file type');
}
if ($size>$maxsize)
{
die ('error- file size must be less than'.($maxsize/1024/1024).'MB');
}
filedata=file_get_contents($tmp_name);
if($image=@imagecreatefromstring($filedata))
{
$width=imagesx($image);
$height=imagesy($image);
//creating images
$large=imagecreatetruecolor(445,380);
imagecopyresampled($large,$image,0,0,0,0,445,380,$width,$height);
$largepath = 'image/large/' . uniqid('img',true) . '.jpg' ; //assigning file location and path
$thumb=imagecreatetruecolor(54,54);
imagecopyresampled($thumb,$image,0,0,0,0,54,54,$width,$height);
$thumbpath = 'image/thumb/' . uniqid('thumb',true) . '.jpg' ;
if (imagejpeg($thumb,$thumbpath) && imagejpeg($large,$largepath))
{
$con = connect();
query("INSERT INTO gallery (caption,thumbpath,largepath) values ('$caption','$thumbpath','$largepath')");
}
header('location:'.$_SERVER["PHP_SELF"]);
}
else
echo "failed";
}
}
}
?>
检查上的手册,它采用可选的第三个参数,即质量(0-100):
检查上的手册,它采用可选的第三个参数,即质量(0-100):
@HYDERALI您确定看到的是修改后的图像,而不是缓存的版本吗?你应该尝试以不同的质量生成大量相同的图像,并比较文件大小和视觉质量。文件大小和质量都增加了。但即使使用100作为质量参数,也没有原始图像的质量和文件大小。@HYDERALI如果GD库不符合您的要求,您可能必须查看其他库,如imagemagick。@HYDERALI是否确实看到的是修改后的图像而不是缓存的版本?你应该尝试以不同的质量生成大量相同的图像,并比较文件大小和视觉质量。文件大小和质量都增加了。但即使使用100作为质量参数,也没有原始图像的质量和文件大小。@HYDERALI如果GD库不符合您的要求,您可能需要查看其他库,如imagemagick。
if (imagejpeg($thumb,$thumbpath, 92) && imagejpeg($large,$largepath, 96))