Keep Original Module

rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Tue, 2009-07-28 23:36

I've noticed that when rotating images, Gallery 3 will overwrite the original photo with the rotated version. Are there any other situations in which Gallery will modify the original photo?

Update:
The Keep Original Module will make a backup copy of the original uploaded photo before galllery rotates it. The lastest version can be found in this post, or on github.

---
Report Problems/Suggestions Here | Get latest version | Documentation | Coffee Fund | My Library | My GitHub

AttachmentSize
keeporiginal.zip4.51 KB
 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Wed, 2009-07-29 00:01

hrm, it does do that doesn't it? That's effecting the quality of the image, not a lot, but it does if you compare before and after (after a few dozen rotates). I certainly hope this isn't final. Heck, it's even noticable after 2 rotates, so this could effect image quality if you just accidentally click on the rotate button and "oops, I didn't mean to do that."

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2009-07-29 00:06
nivekiam wrote:
hrm, it does do that doesn't it? That's effecting the quality of the image, not a lot, but it does if you compare before and after (after a few dozen rotates). I certainly hope this isn't final.

This thread makes it sound like gallery is designed that way, but I don't know if that's just for the beta of its its final:
http://gallery.menalto.com/node/88837

nivekiam wrote:
Heck, it's even noticable after 2 rotates, so this could effect image quality if you just accidentally click on the rotate button and "oops, I didn't mean to do that."]

Yea, I did that by accident and turned a 4 megabyte photo into a 1 megabyte file, so I'm wondering if there are any other buttons that I need to be careful about too.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Wed, 2009-07-29 05:19

So far I believe the only editing that takes place in G3 is the rotation. Watermark doesn't because it doesn't get applied to the fullsize images.

talmdal wrote:
An if you truly need it, it would be very simple to write a module that adds a new directory to tmp (backup) and on the item add event, copies the file to the backup directory and creates a database table to index the backups.

Hmmm, maybe I'll write my first plugin if someone else doesn't get to it first. That could lay the path to having the watermark plugin also watermark the fullsize image without damaging the original. But I don't have any time, so who ever is reading this and would want it, better like waiting :)
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2009-07-29 14:54
Quote:
if someone else doesn't get to it first.

rWatcher, that was a hint. :-)
Seeing that you have a few under your belt already!

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2009-07-29 18:48
floridave wrote:
rWatcher, that was a hint. :-)
Seeing that you have a few under your belt already!

Oh, is that what that was? :) I'll see what I can think up.

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2009-09-30 20:12

I was thinking, rather then duplicate every photo as its uploaded, it'd be nice if full sizes were only duplicated before they were actually modified. Then, if later you decided to undo the modification, you could just click on a "restore" button and have the original put back. Kinda like this:
http://github.com/rWatcher/gallery3-contrib/tree/master/modules/keeporiginal
This should automatically copy a photo over to an "original" directory before it's rotated, and create a menu option for copying it back. As far as I know rotating is the only time the original is edited, but this could easily be extended to cover other areas (like watermarking) if necessary.

I would definitely not recommend trying this on anything other then Beta 2. As modifying the original image doesn't trigger any kind of event, I had to create a modified version of Gallery's graphics library and I don't know how that'll work against anything other then the version it was based off of.

Comments/Thoughts/Suggestions?

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Thu, 2009-07-30 17:40

Pulled! And I tweaked it to move the _menu code into _event to match recent API changes.

So one way that we could avoid having to modify the graphics.php code would be to have each graphics function publish an event and then your code could listen for it. Perhaps something like:

graphics.php:
  static function rotate($input_file, $output_file, $options) {
    ...
    module::event("graphics_rotate", array($input_file, $output_file, $options));
    ...
    module::event("graphics_rotate_completed", array($input_file, $output_file, $options));
  }

Then you could move your code into keeporiginal_event::graphics_rotate(). Try that out in your fork and if it works out, I'll make the change in the main repo's graphics.php.

---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Thu, 2009-07-30 21:16

Cool, thanks :)

I don't know if this is because I'm using beta 2 instead of git, but the event lines don't seem to work as an array. If I modify graphics.php like this though:

  static function rotate($input_file, $output_file, $options) {
    if (!self::$init) {
      self::init_toolkit();
    }

    module::event("graphics_rotate", $input_file, $output_file, $options);

    Image::factory($input_file)
      ->quality(module::get_var("gallery", "image_quality"))
      ->rotate($options["degrees"])
      ->save($output_file);

    module::event("graphics_rotate_completed", $input_file, $output_file, $options);
  }

I can then delete the keeporiginals graphics.php file and do everything from within keeporiginal_event.php like this:
http://github.com/rWatcher/gallery3-contrib/tree/master/modules/keeporiginal/helpers/keeporiginal_event.php

 
Toshik

Joined: 2009-07-29
Posts: 3
Posted: Fri, 2009-07-31 07:54

Maybe better to use jpegtran for looseless image rotation?
But i do not see way to make G3 use it...

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Fri, 2009-07-31 20:33

@Toshik: http://sourceforge.net/apps/trac/gallery/ticket/607

@rWatcher: I just committed those new events to the main repo, and pulled your new module. Great work!
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Sat, 2009-08-01 06:00

Cool, thanks :)

Question: The keeporiginal_events.php files doesn't seem to work right against the current git code. It looks like the problem is that the item_updated event changed between Beta 2 (where it had separate old item and new item parameters) and git (where it seems to just have a single item parameter). I was using this function in keeporiginal to change the file name of the picture/album in the "original" photo when the fullsize in the "albums" folder was changed. Is it still possible to compare the old and new file names with the new code?

 
VENCO
VENCO's picture

Joined: 2004-03-01
Posts: 78
Posted: Sat, 2009-08-01 08:33

Very nice work rWatcher!
I am extremely happy to see this module as I always used my galleries as a kind of backup of my pictures (therefore needing to preserve the originals).

Although I haven't been able to see it work yet (probably due to the problem you state above) I am very enthusiastic about your module. Thanks so much!

_________________________
[img]http://indefik.com/pics/forumrandom.jpg[/img] (Random picture from my G2)
[img]http://indefik.com/pics/lyricsrepositorysmall.jpg[/img]

 
Toshik

Joined: 2009-07-29
Posts: 3
Posted: Sun, 2009-08-02 12:24

I've modified ImageMagick driver to use jpegtran for rotating, cropping and flipping. Should I provide it for you and how?

 
Shai

Joined: 2003-12-10
Posts: 61
Posted: Sun, 2009-08-02 15:25

Since you already know of some problems, I don't see any reason to post them.
But if at some point you think you need some tests done, don't hesitate to ask.

I already have the module installed, but it won't work just yet...

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sun, 2009-08-02 16:38

@Toshik, Yes. Post a diff here or better yet create your own fork in GIT.
http://codex.gallery2.org/Gallery:Using_Git and we can merge your chanages to the main repository.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Sun, 2009-08-02 19:28
rWatcher wrote:
Question: The keeporiginal_events.php files doesn't seem to work right against the current git code. It looks like the problem is that the item_updated event changed between Beta 2 (where it had separate old item and new item parameters) and git (where it seems to just have a single item parameter). I was using this function in keeporiginal to change the file name of the picture/album in the "original" photo when the fullsize in the "albums" folder was changed. Is it still possible to compare the old and new file names with the new code?

Sorry, I had changed the API out from under you. But I didn't like the new API and I've done the necessary magic to change it back. Your event handling code should work properly now.
---
Problems? Check gallery3/var/logs
bugs/feature req's | upgrade to the latest code | use git | help! vote!

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Mon, 2009-08-03 03:12

rWatcher,

bug report:
If you uninstall the module, delete var/original then reinstall the module it doesn't seem to recreate the var/original directory and won't create backups.

feature request:
Could the restore original option also be added to the Quick Pane menu? The same spot where you'd rotate it, under the same drop down where you can select Delete this photo

Also, to go along with G3's naming convention, you should probably rename the restore option to Restore original (no uppercase for original
http://codex.gallery2.org/Gallery3:Coding_Standards#Capitalization_of_Strings

Though it looks like the standard/default menu needs cleaning up still :)

____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Mon, 2009-08-03 04:12
nivekiam wrote:
rWatcher,

bug report:
If you uninstall the module, delete var/original then reinstall the module it doesn't seem to recreate the var/original directory and won't create backups.

Hmmm. Okay, what I think is happening is that you're not actually uninstalling the module. You're just deactivating it, which means that when you reactivate it Gallery is assuming that its still installed properly thus does not run the install code again (even though that's not the case). It looks like I definitely need to write some error handling code to display a message if something doesn't copy properly, although I'm not sure if the module should worry about re-creating the original directory if it goes missing, as that's not the sort of thing any of the other modules do...

nivekiam wrote:
feature request:
Could the restore original option also be added to the Quick Pane menu? The same spot where you'd rotate it, under the same drop down where you can select Delete this photo

I've never tried to mess around with the quick menu before, so I'm not sure if there's a module API for that or not, but I'll definitely look into it.

nivekiam wrote:
Also, to go along with G3's naming convention, you should probably rename the restore option to Restore original (no uppercase for original
http://codex.gallery2.org/Gallery3:Coding_Standards#Capitalization_of_Strings

Sure, I can do that.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Mon, 2009-08-03 04:25
Quote:
Hmmm. Okay, what I think is happening is that you're not actually uninstalling the module. You're just deactivating it, which means that when you reactivate it Gallery is assuming that its still installed properly thus does not run the install code again (even though that's not the case). It looks like I definitely need to write some error handling code to display a message if something doesn't copy properly, although I'm not sure if the module should worry about re-creating the original directory if it goes missing, as that's not the sort of thing any of the other modules do...

You're right, I just unchecked the check box under Admin > Modules and clicked update. Didn't think about this before, but how the heck do you uninstall a module? Not really a question for you necessarily, but just tossing it out there. Has that functionality just not been built yet?

Which makes sense why this is happening :) I think error handling to display an error message would be fine, but I don't see why it couldn't recreate the directory if it doesn't exist.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Mon, 2009-08-03 05:01
nivekiam wrote:
You're right, I just unchecked the check box under Admin > Modules and clicked update. Didn't think about this before, but how the heck do you uninstall a module? Not really a question for you necessarily, but just tossing it out there. Has that functionality just not been built yet?

My guess is this hasn't been built yet. Although I've found that if you need to "fake" an uninstall, deleting the corresponding record from the modules table will force Gallery to run the modules install script again (not really the same thing though as some modules have custom uninstall code for things like deleting their tables).

nivekiam wrote:
Which makes sense why this is happening :) I think error handling to display an error message would be fine, but I don't see why it couldn't recreate the directory if it doesn't exist.

Mostly because it's extra code that'll make the script take a little bit longer to run. Although given that the copy function is already checking for sub-album related directories I guess one extra check isn't going to make much of a difference.

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Mon, 2009-08-03 05:04
Quote:
Mostly because it's extra code that'll make the script take a little bit longer to run. Although given that the copy function is already checking for sub-album related directories I guess one extra check isn't going to make much of a difference.

Especially since it's not something that's run on every page load or view of every little item. Just when an action happens, so I think the impact should be very small.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2009-09-30 20:12

I couldn't find anything that looked like an API for adding to the quick menu, but everything else is done:
- "Restore Original" renamed to "Restore original".
- Added some error messages for when things don't copy right.
- Added code to re-create the "original" directory in the event it goes missing (I'm pretty sure the module now handles missing directories better then Gallery itself :) )
- Added code to deal with moving photos/sub-albums to a different parent album (it seems I somehow forgot about this one the first time).
- Everything tested and appears to work fine against the current Gallery 3 git.

 
Shai

Joined: 2003-12-10
Posts: 61
Posted: Sat, 2009-08-08 10:00

Hi,

Great tool! Love'n it!
Tell me, can you modify the code so that I (and others) would be able to translate it?

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Wed, 2009-09-30 20:13
Shai wrote:
Hi,

Great tool! Love'n it!
Tell me, can you modify the code so that I (and others) would be able to translate it?

Sorry about that, the translation code was mostly there it looks like I just missed one spot. It should be good now.

 
rWatcher
rWatcher's picture

Joined: 2005-09-06
Posts: 722
Posted: Thu, 2010-01-21 01:09

New version of the module :)

- I've located and fixed an issue that causes "original" photos to occasionally become misplaced when moving the item from one album to another.
- I am aware of an issue that causes the original photo to become misplaced when renaming the item or one of the parent albums, this is currently unfixed: http://gallery.menalto.com/node/91522