Rotating / Flipping pictures / photos Rotating / Flipping pictures / photos
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Rotating / Flipping pictures / photos

Started by jasendorf, September 23, 2003, 10:38:20 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Is the ability to rotate/flip pictures using Coppermine necessary?

Necessary
23 (53.5%)
Would be nice to have, but not all that important
18 (41.9%)
Not necessary
2 (4.7%)

Total Members Voted: 43

Voting closed: September 23, 2003, 10:38:20 PM

jasendorf

Since people are going to ask for this I thought I'd post it.  I'm working a bit on rotating and flipping photos using Coppermine.  Yes, I know that better quality would be achieved if users would do this before they upload the pictures, but some users don't have that ability and it would be a nice feature for "keeping up with the Jones" of gallery suites.

More info will be available after I've finished painting our bathroom according to my wife's orders.
Read the Online DOCs,FAQ, and SEARCH the board BEFORE posting questions for help.

boii

jason,

if youd like i can email you some code i worked on (its probably real ugly/dirty compared to the quality of the rest of coppermine) for rotating photos using imagemagick for a client of mine. it does work if you want to reference it.

though my process was .. select the direction (90 clock, 180, 90 counter), feed that variable and the fullpath/imagename to a mogrify command and drop it in a temp/ dir. then if user liked it, 'save' moves it back to the reg dir and overwrites it and cancel destroys it.

though theres probably a more intuitive way.

let me know.

cheers.
ken

jasendorf

That would be spectacular since I don't have any background in ImageMagick...  I'll drop you a pm with my address.
Read the Online DOCs,FAQ, and SEARCH the board BEFORE posting questions for help.

flex

I managed to do this fairly easily and I added a button below the "Delete this picture" button when you're viewing a picture in admin mode.

The reason I decided to add it in was while I was travelling around Europe, I managed to find a few internet cafes that would let me plug my cf reader in and upload the pictures. Obviously these standard workstations didn't have any kind of imaging software on them so I couldn't rotate them myself.

Clicking the button simply rotates the thumb, normal and fullsize image by 90 degrees clockwise. I didn't bother with an option to change direction or angle since most of them I just needed 90 clockwise rotation.

I did however find it a very useful tool when using internet cafes abroad.

P.S. My code is dirty but it works! :p

boii

Quote from: "flex"The reason I decided to add it in was while I was travelling around Europe, I managed to find a few internet cafes that would let me plug my cf reader in and upload the pictures. Obviously these standard workstations didn't have any kind of imaging software on them so I couldn't rotate them myself.

thats the EXACT same reason i wrote my first imagemagick rotation function :D

cheers.
ken

majestyk

I hope that this will be added in the next release, but so far I added a quickfix to my CPG. You need ImageMagick for it, and it adds a checkbox in the "Edit Pics" page right next to the "Delete Pic" button. Checking this checkbox will rotate your picture 90 degrees to the right (which should suffice in most cases, else repeat as necessary).

The only downside is this function only works if the pictures on the server have the right permissions (which should be the case, normally). Details & Discussion down.

Now the code (This is a 'diff -uraN' of editpics.php, files with + are added. with - are removed)

--- editpics.php.backup Tue Sep 30 173158 2003
+++ editpics.php        Thu Oct  2 113301 2003
@@ -102,12 +102,13 @@
                $user3       = get_post_var('user3', $pid);
                $user4       = get_post_var('user4', $pid);
 
+               $rotate       = isset($HTTP_POST_VARS['rotate'.$pid]);
                $delete       = isset($HTTP_POST_VARS['delete'.$pid]);
                $reset_vcount = isset($HTTP_POST_VARS['reset_vcount'.$pid]);
                $reset_votes  = isset($HTTP_POST_VARS['reset_votes'.$pid]);
                $del_comments = isset($HTTP_POST_VARS['del_comments'.$pid]) || $delete;
 
-               $query = "SELECT category, filepath, filename FROM {$CONFIG['TABLE_PICTURES']}, {$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}
.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND pid='$pid'";
+               $query = "SELECT category, filepath, filename, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']}, {$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['
TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND pid='$pid'";
                $result = db_query($query);
                if (!mysql_num_rows($result)) cpg_die(CRITICAL_ERROR, $lang_errors['non_exist_ap'], __FILE__, __LINE__);
                $pic = mysql_fetch_array($result);
@@ -162,6 +163,26 @@
                        $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET $update WHERE pid='$pid' LIMIT 1";
                        $result = db_query($query);
                }
+
+               if ($rotate) {
+                       $dir=$CONFIG['fullpath'].$pic['filepath'];
+                       $file=$pic['filename'];
+                       if(isset($pic['pwidth'])) $oldwidth=$pic['pwidth'];
+                       if(isset($pic['pheight'])) $oldheight=$pic['pheight'];
+
+                       if (!is_writable($dir)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['directory_ro'], $dir), __FILE__, __LINE__);
+
+                       $files=array($dir.$file, $dir.$CONFIG['normal_pfx'].$file, $dir.$CONFIG['thumb_pfx'].$file);
+                       foreach ($files as $currFile){
+                               if (is_file($currFile)) {
+                                       system("{$CONFIG['impath']}convert -rotate 90 $currFile $currFile");    
+                               }
+                               # php > 4.3.0
+                               #if (is_file($currFile)) @ImageRotate($currFile,90,0);
+                       }
+                       $query = "UPDATE {$CONFIG['TABLE_PICTURES']} SET pwidth='$oldheight', pheight='$oldwidth' WHERE pid='$pid' LIMIT 1";
+                       $result = db_query($query);
+               }
        }
 }
@@ -237,6 +258,7 @@
                echo <<<EOT
        <tr>
                <td class="tableb" colspan="3" align="center">
+                       <b><input type="checkbox" name="rotate{$CURRENT_PIC['pid']}" value="1" class="checkbox">{$lang_editpics_php['rotate_pic']}</b>&nbsp
;
                        <b><input type="checkbox" name="delete{$CURRENT_PIC['pid']}" value="1" class="checkbox">{$lang_editpics_php['del_pic']}</b>&nbsp;
                        <b><input type="checkbox" name="reset_vcount{$CURRENT_PIC['pid']}" value="1" class="checkbox">{$lang_editpics_php['reset_view_count
']}</b>&nbsp;
                        <b><input type="checkbox" name="reset_votes{$CURRENT_PIC['pid']}" value="1" class="checkbox">{$lang_editpics_php['reset_votes']}</b
>&nbsp;


This is the diff of the english language file (needed if you want to have a labeled button ;) )

--- lang/english.php.backup     Tue Sep 30 190905 2003
+++ lang/english.php    Tue Sep 30 174532 2003
@@ -528,6 +528,7 @@
        'approve' => 'Approve picture',
        'postpone_app' => 'Postpone approval',
        'del_pic' => 'Delete picture',
+       'rotate_pic' => 'Rotate picture',
        'reset_view_count' => 'Reset view counter',
        'reset_votes' => 'Reset votes',
        'del_comm' => 'Delete comments',


Details and discussion (for the development team)
 I uploaded the pictures via scp and unpacked them into an special made directory reflecting the name of my gallery album, because I hate to have all  my pictures in a single directory. As a result. the pictures had my users' permissions (and uid/gid) instead those of the webserver, which resulted in rotated thumbs, but not the original pic.
For the next version, I would appreciate a more flexible approach where pictures are physically stored, e.g. folder names reflecting the album names and maybe the category/album hierarchy. Moving a picture should not only affect the db entry, it should move the file physically, too. It would be cool to have a special "upload" directory, where CPG fetches it's pictures, moves them into the right album folder and creates thumbs there.

So far, and thanks for the great gallery you've made,
/majestyk

jasendorf

It will not be available in 1.2 yet.  But, it is a high priority for 1.3 (or whatever the subsequent release will be).

Your code will be helpful.  We have snippets for GD and GD2 and Imagemagick which will all be helpful for using in the final version.

Thanks!  John
Read the Online DOCs,FAQ, and SEARCH the board BEFORE posting questions for help.

jim_patterson

Does anyone know if ImageMagick is lossless when rotating?

jpegtran is easy to use to perform lossless rotations (90, 180, 270).  The only time an issue comes up is when the image can not be divided evenly into macroblocks.  In that case there are some options to choose the desired behavior.

Just a thought.

Jim P.

sashaobrok

thanks majestyk for the code diff
i repeated the same things for rotate right vs rotate left
got it working in a minute