iPhone图像方向-旋转图像自动与PHP, PEL, Image_moo


iPhone image orientation- Rotating images automatically with PHP, PEL, Image_moo

我试图在保存之前旋转上传的图像,基于EXIF ORIENTATION标签。

我已经分别检查了代码的每个部分,一切似乎都在它自己的工作。

$new是正确的路径和文件名。

Image_moo已加载。

PEL(PHP EXIF Library) [http://lsolesen.github.com/pel/]已加载。

图像具有EXIF数据,包括旋转。

我相信我的switch语句是正确的。

代码不会导致任何错误,它只是不会旋转图像。

我错过了什么或做错了什么?

标记
 $new = the file that was just uploaded
 ...
 $ext = strtolower($path_parts['extension']);
 ...
  if($ext == 'jpg'){
  $input_jpg = new PelJpeg($new);
  $exif = $input_jpg->getExif();
  if($exif !== NULL){
  $tiff = $exif->getTiff();
  $ifd0 = $tiff->getIfd();
  if($orient = $ifd0->getEntry(PelTag::ORIENTATION)){
     $this->image_moo->load($new);
     $orient = str_replace(' ', '', $orient);
     if (($tmp = strstr($orient, 'Value:')) !== false) {
          $str = substr($tmp, 6, 1);//Get the value of the ORIENTATION tag
     }
     $this->image_moo->load($new);
     switch ($str)
     {
     case 8:
        $this->image_moo->rotate(270);
        break;
     case 3:
        $this->image_moo->rotate(180);
        break;
     case 6:
        $this->image_moo->rotate(90);
        break;
     case 1:
        break;
     }
     $this->image_moo->save($new, TRUE);
 }
 $output_jpg = new PelJpeg($new);
 $output_jpg->setExif($exif);
 $output_jpg->saveFile($new);
}
}

我不确定PelJpeg,但在Imagick我做:

...
switch( $imagick->getImageOrientation() ){
    case 6:
        $imagick->rotateImage(new ImagickPixel(), 90);
        $imagick->setImageOrientation(1);
    break;
    case 8:
        $imagick->rotateImage(new ImagickPixel(), 270);
        $imagick->setImageOrientation(1);
    break;
}
...