0

Ok.. now I have been trying this for long time now.

I am trying to rotate image if it has some orientation . I got reference from Here

I also refered this

Here is function I am using

function adjustPicOrientation($full_filename){        
$exif = exif_read_data($full_filename);
if($exif && isset($exif['Orientation'])) {
    $orientation = $exif['Orientation'];
    if($orientation != 1){
        $img = imagecreatefromjpeg($full_filename);

        $mirror = false;
        $deg    = 0;

        switch ($orientation) {
          case 2:
            $mirror = true;
            break;
          case 3:
            $deg = 180;
            break;
          case 4:
            $deg = 180;
            $mirror = true;  
            break;
          case 5:
            $deg = 270;
            $mirror = true; 
            break;
          case 6:
            $deg = 270;
            break;
          case 7:
            $deg = 90;
            $mirror = true; 
            break;
          case 8:
            $deg = 90;
            break;
        }
        if ($deg) $img = imagerotate($img, $deg, 0);    
        $full_filename = str_replace('.jpg', "-O$orientation.jpg",  $full_filename); 
        imagejpeg($img, $full_filename, 95);
    }
}
return $full_filename;
}

A new image with new name is getting saved but there is no rotation change.

Actually I am facing very unexpected issue .. when I rotate image with static rotation angle it is working fine .. but it is not working for the rotation angles mentioned in conditions .. I am no able to figure it out ...

Can I body suggest me what went wrong .. Any help will be appreciated

Thanks

Community
  • 1
  • 1
alwaysLearn
  • 6,882
  • 7
  • 39
  • 67
  • Do all parts of code execute properly (like `if($exif && isset($exif['Orientation']))` and `if($orientation != 1){`)? – Voitcus May 16 '13 at 09:08
  • @Voitcus yes code is running properly . and coming in proper conditions .. but I am unable to get why I am not getting any rotation – alwaysLearn May 16 '13 at 09:09
  • 1
    try to not use same variable for old and new image. it may help to find the problem – Phantom May 16 '13 at 09:10
  • Try what @Phantom suggests and if not, try if `imagerotate` works at all. – Voitcus May 16 '13 at 09:13
  • Use `$img2 = imagerotate($img, $deg, 0);` and then `imagejpeg($img2, $full_filename, 95);` – Voitcus May 16 '13 at 09:13
  • @Voitcus tried but not working . – alwaysLearn May 16 '13 at 09:16
  • use some debug output for your $deg and make sure it is not 0 – Phantom May 16 '13 at 09:18
  • You don't use your `$mirror` variable, maybe you test the code using mirrors not rotations. – Voitcus May 16 '13 at 09:18
  • Does `imagerotate` work in other cases? Does it return resource? – Voitcus May 16 '13 at 09:21
  • Yes it is returning the resource – alwaysLearn May 16 '13 at 09:23
  • well ... try to replace this function body with something simplest (remove all conditions etc.). like this: `$new_img = imagerotate($old_img, 90, 0);` and check the result. if it works -start adding additional lines one by one. – Phantom May 16 '13 at 09:30
  • You may also try if this line really executes `if ($deg) $img = imagerotate($img, $deg, 0);` for example `if($deg){ $img = imagerotate($img, $deg, 0); echo 'Yes it does';}` – Voitcus May 16 '13 at 09:34
  • @Voitcus I tried `var_dump($img)` after `imagerotate($img, $deg, 0)`. it is giving `resource(65, gd)` – alwaysLearn May 16 '13 at 09:39
  • But we don't know if the picture has changed. This might be a problem with your GD library, with the file system (Maybe instead of saving the file output it to the browser to ensure it isn't the file problem), even in your code -- it seems ok, but maybe there is some stupid mistake. If some part of your code doesn't work, YOU are the first suspect, so I want to know this line really runs. Var_dumping will not help in this case, because we cannot compare the image before and after. You can also try other GD function like imageflip, test it if it would work with bitmaps or gifs, etc. – Voitcus May 16 '13 at 09:48

0 Answers0