[英]Data URI saved JPG images create black images on upload with php imagecreatefromjpeg
I am using following code to upload 我正在使用以下代码上传
//width,new_width,height,new_height are set
$tmp_filename = $_FILES['file']['tmp_name'];
$image_p = imagecreatetruecolor($new_width, $new_height); //resample image
if(($ext=='jpg') | ($ext=='jpeg')){
//if image to be uploaded is jpg
$image = imagecreatefromjpeg($tmp_filename);
}
else{
//if image to be uploaded is png
$image = imagecreatefrompng($tmp_filename);
}
//to convert to jpg
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
$done=imagejpeg($image_p, $output_dirrectory."/".$image_name.".jpg",95); //95% quality
Now, the problem is, when I save a image from any other website which was generated using Data URI, it get saved on my local machine as JPG image. 现在,问题是,当我保存使用Data URI生成的任何其他网站的图像时,该图像都会以JPG图像的形式保存在本地计算机上。 When I try to upload same image with following code, it created black image.
当我尝试使用以下代码上传同一张图片时,它创建了黑色图片。
I could't figure out the problem. 我不知道问题所在。 I hope solution lies in imagecreatefromstring, but I don't know how that will work out with following code?
我希望解决方案在于imagecreatefromstring,但是我不知道如何在下面的代码中解决? Please suggest any solution?
请提出任何解决方案?
try adding: 尝试添加:
$width = imageSX($image);
$height = imageSY($image);
before the call to imagecopyresampled 在调用imagecopy之前重新采样
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.