Ive created an image gallery with php and mysql, incorporating several ways to add images & ability to sort by addition method and/or category. After noticing some images from apple devices showed up with the 'wrong' orientation, I created another page to edit orientation and other file info, then save said changes back to file and db. Only after I thought I had solved this problem did开发者_如何学JAVA I view the altered images on an apple device, only to realize that image was now in 'wrong' orientation on said device. I've been googling this, but can't quite figure out exactly what I need to learn now to deal with images from apple devices in this situation. A shove in the right direction would be greatly appreciated.
Thanks!
Seeing the same problem on my "gallery3" photo gallery. Like machouinard, I am using "jhead -norot filename.jpg" to strip the orientation header from the images. This fixes the Apple rotation problem, and it does not seem to mess up the other browsers.
To edit a bunch of the files in place, I go directly to the album storage area in (gallerytop)/lib/albums and do find -type f | xargs sudo jhead -norot
. It is smart enough to only modify the files that need to be modified, and it'll print out a list of them to stdout as it is working.
To get gallery3 to update the thumbnails, I go into the database and set the "dirty" flags like this: echo "update items set thumb_dirty=1,resize_dirty=1 where relative_path_cache like 'ALBUMNAME/%';" | mysql -u root -p gallery3
. Then I go into the gallery maintenance mode and run the "rebuild images" utility.
Forgot I posted this. I figured out how to handle the orientation issue so I thought I'd share. Seems simple now. I've since recreated this project using Codeigniter. CI is great and saves a lot of time, but I'm glad I wrote it all myself the first time. I sure learned more that way.
First, if the file is a jpg, I get the EXIF data with PEL .
$new
is the uploaded file to be checked for orientation.
$this->load->library('pel/PelJpeg');
if($ext == 'jpg'){
$pdw= new PelDataWindow(file_get_contents($new));
if(PelJpeg::isValid($pdw)){
$input_jpg = new PelJpeg($new);
$exif = $input_jpg->getExif();
}
}
Then if EXIF exists, get the orientation value and run it through a switch statement, rotate it accordingly and then reset the orientation value. I'm using image_moo and Codeigniter, but this can obviously be changed to use any image manipulation library.
I'm honestly not sure if all those IF statements need to be there, but I kept running into trouble with jpg's that only included some EXIF info and would blow up the script without them.
if($exif !== NULL){
if($tiff = $exif->getTiff()){
if($ifd0 = $tiff->getIfd()){
if($orient = $ifd0->getEntry(PelTag::ORIENTATION)){
$this->image_moo->load($new);
//find the orientation value from the orientation tag. May be a better way, but this works for me.
$orientation = str_replace(' ', '', $orient);
//The orientation value from the orientation tag is after 'Value:'
if (($tmp = strstr($orientation, 'Value:')) !== false) {
$str = substr($tmp, 6, 1);
}
switch ($str)
{
// up is pointing to the right
case 8:
$this->image_moo->rotate(90);
$orient->setValue(1);
break;
// image is upside-down
case 3:
$this->image_moo->rotate(180);
$orient->setValue(1);
break;
// up is pointing to the left
case 6:
$this->image_moo->rotate(270);
$orient->setValue(1);
break;
// correct orientation
case 1:
break;
}
$this->image_moo->save($new,TRUE);
if ($this->image_moo->errors) print $this->image_moo->display_errors();
$this->image_moo->clear();
}
}
}
}
Hope this will be helpful to someone else struggling with the same issues. If you see anything that could be improved, please let me know. But this works great for me.
Mark
精彩评论