【问题标题】:image not uploading properly when uploading from ios device camera in php从 php 中的 ios 设备相机上传时图像无法正确上传
【发布时间】:2018-03-23 17:30:23
【问题描述】:

我正在 codeigniter 中创建一个项目,用户可以在其中上传他的个人资料图片。我正在使用图像库上传它。当我在 IOS 设备中使用相机上传图像时,上传的图像带有一些灰色区域。库中的代码是

function createImage($iMageName,$folderName){
$width = 500; $height = true;
$data=base64_decode($iMageName);
$f = finfo_open();
$mime_type = finfo_buffer($f, $data, FILEINFO_MIME_TYPE);
$image = imagecreatefromstring($data);
$height = $height === true ? (ImageSY($image) * $width / ImageSX($image)) : $height;
$output = ImageCreateTrueColor($width, $height);
$imgThumb=uniqid().strtotime(date("Y-m-d H:i:s")).'.jpg';
$imageName=$folderName.$imgThumb;
$fullpath=FCPATH.$imageName;
ImageCopyResampled($output, $image, 0, 0, 0, 0, $width, $height, ImageSX($image), ImageSY($image));
imagejpeg($output, $fullpath, 90);
return $imageName;
}

在 web 和 android 设备上运行良好,但在 ios 设备中出现问题,请参阅上传的图片

【问题讨论】:

    标签: php ios image-uploading


    【解决方案1】:

    我也遇到了同样的问题。 以下情况会出现问题:

    1. 文件大小。请验证文件大小。

    2. 请编写以下代码并检查它是否正常工作。

       function createImage($iMageName,$folderName){
            ini_set ('gd.jpeg_ignore_warning', 1);
            $width = 500; $height = true;
            $data=base64_decode($iMageName);
            $f = finfo_open();
            $mime_type = finfo_buffer($f, $data, FILEINFO_MIME_TYPE);
            $image = @imagecreatefromstring($data);
            $height = $height === true ? (ImageSY($image) * $width / 
            ImageSX($image)) : $height;
            $output = @ImageCreateTrueColor($width, $height);
            $imgThumb=uniqid().strtotime(date("Y-m-d H:i:s")).'.jpg';
            $imageName=$folderName.$imgThumb;
            $fullpath=FCPATH.$imageName;
            @ImageCopyResampled($output, $image, 0, 0, 0, 0, $width, 
            $height, ImageSX($image), ImageSY($image));
            imagejpeg($output, $fullpath, 90);
            return $imageName;
        }
      

    谢谢,对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-08
      • 2018-12-21
      相关资源
      最近更新 更多