【问题标题】:Wrong photo orientation after uploading from mac os从 mac os 上传后照片方向错误
【发布时间】:2013-06-07 14:54:12
【问题描述】:

我不确定是否有任何修复,但问题如下。

问题: 我的客户用iphone拍了一张照片。由于方向错误,他使用手机中的内置照片编辑器将其翻转到正确的方向。但是,当他从他的 mac 上传照片时,照片实际上返回到错误的方向。

在 mac 上,可以在正确的方向上看到更正后的图片。但是当发送到windows pc或上传到linux服务器时,图片又回到了原来的错误方向。

这是 mac 问题还是其他问题?或者是否有任何可以在 PHP 脚本中完成的修复。下面是上传照片的php脚本。

 $file=array();
    $listingid=$_POST['listing'];
    if(!empty($_FILES['file'])){
        foreach($_FILES['file']['name'] as $key=>$name){
            $extt=pathinfo($name, PATHINFO_EXTENSION);
            $name=$this->mediacontrol->generateUniqueKey(32);
            $name.=".".$extt;
            if($_FILES['file']['error'][$key]==0 && move_uploaded_file($_FILES['file']['tmp_name'][$key],"uploads/{$name}")){
                $file['file_name']=$name;
                $file['file_type']=$_FILES['file']['type'][$key];
                $file['file_path']="uploads/{$name}";
                $file['full_path']=  base_url()."uploads/{$name}";
                $ext=explode(".",$name);
                $file['thumb_path']=base_url()."uploads/thumbnails/250/".$ext[0]."_thumb.".$ext[1];
                $file['thumb_short']="uploads/thumbnails/250/".$ext[0]."_thumb.".$ext[1];
                $file['link_folder']="uploads/";
                $file['raw_name']="null";
                $file['orig_name']="$name";
                $file['client_name']="null";
                $file['file_size']=$_FILES['file']['size'][$key];
                $file['is_image']="1";
                $file['image_width']="0";
                $file['image_height']="0";
                $file['image_type']=$_FILES['file']['type'][$key];
                $file['image_size_str']="width:0px;height:0px;";

                $id=$this->mediacontrol->insertData($file);
                $file_id[]=$id;

                    $config['image_library'] = 'GD2';
                    $config['source_image'] = "".$file['file_path'];
                    $config['new_image']="uploads/thumbnails/250/";
                    $config['create_thumb'] = TRUE;
                    $config['maintain_ratio'] = TRUE;
                    $config['width']     = 250;
                    $config['height']   = 250;

                    $this->image_lib->initialize($config);
                    $this->image_lib->resize();
                    $this->image_lib->clear();

                            $this->listing_model->matchMedia($id,$listingid);  
                    $this->listing_model->updateStage(1,$id);
                    echo "Successfully uploaded ".$name."<br>";
            }
            else{
                echo "Something went terribly wrong when uploading".$name;
            }
        }
    }

请指教。

谢谢。

【问题讨论】:

  • 如果 image_lib 使用 imagemagick,这可能适用,请查看 stackoverflow.com/questions/4266656/…
  • 非常接近。但我没有使用 imagemagick 库,我使用的是 GD2。这相关吗?无论如何,谢谢,因为现在我知道原因可能是方向标志。

标签: php macos codeigniter


【解决方案1】:

很抱歉浪费了任何人的时间。我找到了问题并解决了我的问题。

问题: 用户使用的一些照片编辑器不会物理旋转照片,它们基本上只是更新附加到图像的元数据。这会导致问题,因为某些环境不读取该数据。这在 Windows 和我的情况下非常明显。

解决办法: 所以只能在上传图片的时候多做一步。也就是检查图片的exif数据,做必要的调整。我正在使用带有 GD2 图像处理库的 codeigniter。解决我的问题的代码如下。

$config['image_library'] = 'GD2';
                    $config['source_image'] = "../rentura/".$file['file_path'];
                    $config['new_image']="../rentura/uploads/thumbnails/250/";
                    $config['create_thumb'] = TRUE;
                    $config['maintain_ratio'] = TRUE;
                    $config['width']     = 250;
                    $config['height']   = 250;
                    $imgdata=exif_read_data($file['full_path'], 'IFD0');
                                        switch($imgdata['Orientation']) {
                    case 3:
                        $config['rotation_angle']=180;
                        break;
                    case 6:
                        $config['rotation_angle']=-90;
                        break;
                    case 8:
                        $config['rotation_angle']=90;
                        break;
                }

                    $this->image_lib->initialize($config);

                    if(!$this->image_lib->resize()){

                        echo $this->image_lib->display_errors();
                    }
                    $this->image_lib->rotate();
                    $this->image_lib->clear();

不太确定您将如何评价此解决方案。但如果有更好的解决方案,请告诉我。谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-02
    • 2011-10-13
    • 2012-03-30
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 2015-07-20
    • 2013-06-01
    相关资源
    最近更新 更多