New module - EXIF Auto-rotate
|
dmolavi
![]()
Joined: 2002-12-05
Posts: 569 |
Posted: Thu, 2010-08-05 19:09
|
|
General G3 question, not specific to RC2: Also, if I have a bash script go and rotate the images via the command line after they have been uploaded and added, will that present any issues when Gallery tries to display the images after I tweak them? -- |
|



Posts: 25960
One of the issues with auto rotate is: We have to flag the image as already rotated some how if we do this. This could be done in the DB or rewrite the EXIF.
I would go for the DB method in a new table or a new column for the items table. We don't want to screw around with the original, or we could have the 'keep original' module as a requirement & go with the EXIF alteration.
We need to do that because if the user wants to run, say a maintenance task, to rotate images, we need to know if they have been rotated already, or the task might rotate an already rotated image.
What do we do with items that are added that have been rotated already and have the wrong orientation? Do we rotate them again and notify the user or do we blindly rotate them without notification?
Just some of the points to consider.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 569
Very good point re: multiple rotations.
Let's attack this from another point of view: most of the complaints surrounding this basically come from folks (like me) that have large existing galleries, and rotating individually would be painful. It's been awhile since i've poked at the G2 structure, but how about modifying the g2import to take rotation into affect (ie, if the image in g2 was rotated, rotate as it's brought into g3).
ack, it's not stored in the db in g2, is it? it's all in the derivatives. CRAP. that negates all of this too.
EDIT: Wait..it's in g2_Derivative.g_derivativeOperations...hmmm...i'm not comfy tinkering w/ a core module, but it might be a way to go.
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 7985
This is a good topic to explore. Some thoughts:
If the plan is to preserve whatever they had in G2, then we can just replay any rotation operations in the derivativeOperations, right? Doesn't matter if they kept the original or not, once we replay all the rotations we have reproduced whatever they had in G2. The downside to that is that it's a destructive operation for the G3 copy, but then again they have the original from G2 if they need to go back. So that seems doable.
For newly uploaded images, I think we could write an "autorotate" module that intercepts the original at upload time and rotates it. In that case we don't care what's in the EXIF cause we're only doing it once at upload time. I bet that's pretty easy to do as well, and it can be done as a 3rd party module.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git
Posts: 569
Did you just volunteer?
I'm not familiar enough with the hooks between g2 and g3 to be comfortable making this change to a "core" module.
Are there other modules that intercept the uploads that I can look at as a starting point? From there, it's just reading the EXIF and performing the appropriate rotation. I've looked at the code in G2 for that and it seems pretty straightforward.
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 7985
https://sourceforge.net/apps/trac/gallery/ticket/1274 -- I'll take care of that.
I don't think that we have a specific module for this, but you can create a module that listens for the add_photos_form_completed event. At that point if the EXIF module is available, you'll have the exif info and you can call grallery_graphics::rotate on the image if you need to.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git
Posts: 569
OK, i'll tackle the autorotate module when i get back from vacation in a week.
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 7985
The G2 import rotation issue (ticket https://sourceforge.net/apps/trac/gallery/ticket/1274) is fixed in git.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git
Posts: 569
I'm back, and this is back on my honey-do list. I'll tackle it ASAP.
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 569
EDIT: Ignore this, I think I've got it working.
OK, I'm stumped. I've tried everything I can think of to listen for the add_photos_form_completed event, but can't get it to fire off. I'm basing my initial listener on the notification_event.php file, creating an autorotate_event.php file, with
static function add_photos_form_completed($item). However, it doesn't appear to trigger at all...any suggestions would be appreciated.--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 569
I'm sooooooo close, it's killing me. I've got 2 camera models that I shoot with, a point and shoot and a DSLR, both Canon. It looks like the point and shoot rotates correctly, but I'm getting the following when I upload and try to autorotate the DSLR images:
2010-08-17 10:48:28 -07:00 --- error: @todo autorotate_event::item_created() failed 2010-08-17 10:48:28 -07:00 --- error: ORM Validation has failed for items model #0 /home/dmolavi/public_html/www.xxx.com/gallery3/system/libraries/ORM.php(755): ORM_Validation_Exception_Core::handle_validation('items', Object(Validation)) #1 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/models/item.php(787): ORM_Core->validate(NULL) #2 /home/dmolavi/public_html/www.xxx.com/gallery3/system/libraries/ORM.php(778): Item_Model->validate() #3 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/libraries/MY_ORM.php(23): ORM_Core->save() #4 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/libraries/ORM_MPTT.php(79): ORM->save() #5 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/models/item.php(428): ORM_MPTT_Core->save() #6 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/autorotate/helpers/autorotate.php(42): Item_Model->save() #7 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/autorotate/helpers/autorotate_event.php(26): autorotate::rotate_item(Object(Item_Model)) #8 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/helpers/module.php(392): autorotate_event_Core::add_photos_form_completed(Object(Item_Model), Object(Forge)) #9 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/controllers/uploader.php(79): module_Core::event(Array, Array) #10 [internal function]: Uploader_Controller->add_photo('add_photos_form...', Object(Item_Model), Object(Forge)) #11 /home/dmolavi/public_html/www.xxx.com/gallery3/system/core/Kohana.php(331): ReflectionMethod->invokeArgs('4910') #12 /home/dmolavi/public_html/www.xxx.com/gallery3/system/core/Event.php(208): Kohana_Core::instance(Object(Uploader_Controller), Array) #13 /home/dmolavi/public_html/www.xxx.com/gallery3/application/Bootstrap.php(67): Event_Core::run(NULL) #14 /home/dmolavi/public_html/www.xxx.com/gallery3/index.php(94): require('/home/dmolavi/p...') #15 {main}I've attached the code to this post. Thanks for any help. I don't think it's a camera model related thing, as the rotation amounts are properly detected.
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 569
Here's more info:
The insufficient memory worries me, though uploads w/ autorotate of the same file to my G2 install work just fine on the same server...
More info here...when I try to rotate one of these photos via the "rotate" option in the photo menu, I get the following in /var/logs:
2010-08-17 13:23:07 -07:00 --- error: ORM_Validation_Exception [ 44 ]: ORM Validation has failed for items model /home/dmolavi/public_html/www.xxx.com/gallery3/system/libraries/ORM_Validation_Exception.php [ 20 ] #0 /home/dmolavi/public_html/www.xxx.com/gallery3/system/libraries/ORM.php(755): ORM_Validation_Exception_Core::handle_validation('items', Object(Validation)) #1 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/models/item.php(787): ORM_Core->validate(NULL) #2 /home/dmolavi/public_html/www.xxx.com/gallery3/system/libraries/ORM.php(778): Item_Model->validate() #3 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/libraries/MY_ORM.php(23): ORM_Core->save() #4 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/libraries/ORM_MPTT.php(79): ORM->save() #5 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/models/item.php(428): ORM_MPTT_Core->save() #6 /home/dmolavi/public_html/www.xxx.com/gallery3/modules/gallery/controllers/quick.php(42): Item_Model->save() #7 [internal function]: Quick_Controller->rotate('4950', 'cw') #8 /home/dmolavi/public_html/www.xxx.com/gallery3/system/core/Kohana.php(331): ReflectionMethod->invokeArgs(Object(Quick_Controller), Array) #9 /home/dmolavi/public_html/www.xxx.com/gallery3/system/core/Event.php(208): Kohana_Core::instance(NULL) #10 /home/dmolavi/public_html/www.xxx.com/gallery3/application/Bootstrap.php(67): Event_Core::run(Array, Array) #11 /home/dmolavi/public_html/www.xxx.com/gallery3/index.php(94): require('/home/dmolavi/p...') #12 {main} 2010-08-17 13:23:07 -07:00 --- error: Validation errors: Array ( [name] => cant_change_mime_type )Additionally, the errors at the top of this reply also appear in my server log.
These errors appear only when trying to autorotate (or rotate via the photo menu) the shots from my DSLR (a Canon EOS Rebel XT). I don't know why it doesn't work w/ G3, but it does work w/ G2...bharat?
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 7985
Check your code into git and I'll do a pass over it.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git
Posts: 569
cripes, at work now and won't be able to drop it into git until tonight, but i attached it to this post: http://gallery.menalto.com/node/97270#comment-350904 .
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 569
In G2, when autorotating, the following is the command that is executed:
I can't get G3 to dump the corresponding command, but I wonder if the "nice" is the difference. Or, possibly the "jpg:" on the temp file name...
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 569
I checked it into my fork.
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 7985
I just tested out the code from your fork on my dev gallery and it worked just fine. Woot! I pulled the code into gallery3-contrib so that others can try it out. Not sure what's going wrong in your install
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git
Posts: 569
Bharat, for shits and giggles, try it with the photo I emailed to you. If it still works, it must be a hostgator thing, still can't figure out what's different between the G2 and G3 convert call though. I'll update the codex page, as well.
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 569
The "flatten" option in the IM convert command is the killer here. It takes memory usage on my WinXP machine (not the server I'm running G3 on) up to 63.7MB (according to the -debug all option in IM). This probably hits the 64MB limit imposed by my host and they shut down the process. Adding "nice" to the beginning of the command resolved the issue, even w/ the "flatten" option.
Should we make that change to the file provided w/ G3 so others on shared hosts don't have this problem? It probably should be made to all "convert" calls in the IM file...
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 569
actually, it looks like the "nice" produces inconsistent results. removing "flatten" in addition to adding "nice" is probably the best option.
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 21
Just tested autorotate on my hosted/shared linux server. I installed and activated the plugin, and tested using the individual upload feature. The images I uploaded are not rotating during upload. Manual rotation works fine.
I'm new to G3, so I haven't found the logs. I could check them if that would help.
* Operating system: Linux 2.6.28.5-grsec-sg2
* Apache: Unknown
* PHP: 5.2.9
* MySQL: 5.0.91mm-log
-- Dick
Posts: 569
I've found the cause of this problem on shared hosts. It's two-fold:
1. The use of the "flatten" option.
2. The lack of "nice" before the convert command.
To get this working, you will need to modify gallery3/system/libraries/drivers/Image/ImageMagick.php .
Replace:
public function rotate($amt) { if ($error = exec(escapeshellcmd($this->dir.'convert'.$this->ext).' -background '.$this->background.' -flatten -rotate '.escapeshellarg($amt).' -background transparent '.$this->cmd_image.' '.$this->cmd_image)) { $this->errors[] = $error; return FALSE; } return TRUE; }with this:
public function rotate($amt) { if ($error = exec('nice '.escapeshellcmd($this->dir.'convert'.$this->ext).' -background '.$this->background.' -rotate '.escapeshellarg($amt).' -background transparent '.$this->cmd_image.' '.$this->cmd_image)) { $this->errors[] = $error; return FALSE; } return TRUE; }--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 21
I installed this patch, but I am seeing the same behavior. Manual rotations are working but images are not being rotated upon upload. I verified that I was changing the correct file by intentionally munging the syntax and watching it fail and then putting it right.
Not a big deal for me - just FYI.
-- Dick
Posts: 569
Not sure if it matters, but the module was written against the latest code in git, not RC2...
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 57
Have upgraded to the last Master release of G3 and applied the patch but no way to rotate images here too.
regards all
guanche
Posts: 569
are you referring to the "nice" patch above?
who is your host? this is not a G3 problem as much as it is a Kohana problem (G3 uses their image processing framework to handle this).
--

For PHPNuke, phpBB2, and phpBB3 integration help, please visit NukedGallery.net.
Posts: 57
It happens to me with a Nikon D70s camera.
Now i have rotated them before uploading them.
But "rotate clockwise" option at each pic menu dosent work.
Regards
guanche
Posts: 9
Hi all,
I added autorotate module on my Gallery3, and seems like it's not working.
Checked the log and it showed this:
2010-11-10 23:49:53 +08:00 --- error: @todo autorotate_event::item_created() failed
2010-11-10 23:49:53 +08:00 --- error: The specified image, C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/gallery/var/tmp/rotC3.tmp, is not an allowed image type.
It seems like it's changed to a .tmp file, which autorotate just doesn't recognize it.
Does anyone have idea on this? Thank you very much.....
Posts: 3
For Gallery-3.0 the following hack works for my jpeg files, though it probably need to be a bit more intelligent..
Posts: 569
hmm...the tempnam call just creates a random file name...appending .jpg shouldn't be required, as it's in the file header itself, and the same logic is used in gallery 2 (no .jpg appended to the filename). did you have to make this same change there?
--
For Gallery 3 modules and themes, visit GalleryModules.com.
For PHPNuke, phpBB2, and phpBB3 integration help, visit NukedGallery.net.
Posts: 3
Actually I'm just coming back to Gallery after a long hiatus so I haven't tested with any recent version of Gallery2. The only thing I can say is that autorotate only works after I added the .jpg suffix.
Posts: 569
are you using imagemagik? what version? i wonder if there's something going on there...
--
For Gallery 3 modules and themes, visit GalleryModules.com.
For PHPNuke, phpBB2, and phpBB3 integration help, visit NukedGallery.net.
Posts: 3
Only GD:
Posts: 569
Hmm..ok. I don't know why this didn't pop up in G2, but I'll have to mull over the change before committing it.
--
For Gallery 3 modules and themes, visit GalleryModules.com.
For PHPNuke, phpBB2, and phpBB3 integration help, visit NukedGallery.net.
Posts: 10
I'm trying to use the 3.0 version of the autorotate module with a Fuji F500 EXR camera. I've tried GD, Imagemagick and Graphicsmagick, and none of them are rotating properly. I looked and the images' exif data is proper and this camera DOES have an orientation sensor. So what gives? There is no error in the apache error log and no other indications of why it's not working.
How can I debug why it doesn't rotate properly? I just bought this camera in part since our old one doesn't have an orientation sensor, so I really want to get this working.
Thanks!
*edit* And just to confirm, I went to "more information" on one of the images that is rotated CCW 90 degrees and sure enough I see:
"Orientation 6: 90 deg CCW"
So it SHOULD work. I need to know how to debug why it's not rotating.
Posts: 10
Well, I found the problem. I'm not sure why my particular PHP is complaining about it, but I had issues being reported in the logs about split() being deprecated. I fixed those (replaced with comparable preg_split() calls) and then I found a couple more split() calls in the keeporiginal module that I had to fix. Then I had to install the php5 calendar extension which I lacked. Finally, unixtojd() was complaining about being passed a string, so I had to change line to this:
$this->day_count = unixtojd(strtotime($timestamp));
That seems to have done the trick. Images are now being automatically rotated when adding them to an album!
Hopefully anyone else seeing strange errors will benefit from this. Watching the log files in <g3dir>/var/log and knowing enough PHP (or another similar language) to find and debug the calls was all I needed to fix it, but it'd be nice if the upstream (e.g. git) sources were updated to perhaps handle PHP installs where split() usage causes an error?
Posts: 4
I get this error:
2011-07-21 17:13:16 -04:00 --- error: @todo autorotate_event::item_created() failed
2011-07-21 17:13:16 -04:00 --- error: The specified image, /home/USER/gallery3/var/tmp/rotateouvY4y, is not an allowed image type.
I'm using Gallery 3.0.2 and the latest autorotate module from http://www.gallerymodules.com/
I have GD version bundled (2.0.34 compatible)
I changed to imagemagik and it worked fine, I didn't see anything in the documentation that says GD is not compatible.