I'm trying to rotate uploaded images before saving, based on the EXIF ORIENTATION tag.
I've checked each portion of the code separately and everything seems to work on it's own.
$new is the correct path and filename.
Image_moo has been loaded.
PEL(PHP EXIF Library) [http://lsolesen.github.com/pel/] has been loaded.
Images have EXIF data including rotation.
I believe I got the switch statement correct.
The code doesn't cause any errors, it just doesn't rotate the image.
What am I missing or doing wrong?
Mark
$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);
}
}