Export to Gallery2: rotation patch



Hi guys,

Gallery2 is not yet able to autorotate pictures with information from
the EXIF part of the file.
So, I made a patch to f-spot to rotate pictures BEFORE exporting them.
You just need to check the checkbox (check the screenshot:
http://www.delcroix.org/rotate-patch.jpg )
The attached patch if against the latest CVS.

Hope it's useful for a lot of gallery2 / f-spot users...

Stephane


-- 
Stephane Delcroix
stephane delcroix org
? FlickrNet/Makefile
? FlickrNet/Makefile.in
? po/stamp-it
? src/f-spot.gladep
? tools/Makefile
? tools/Makefile.in
? tools/NONE
? tools/f-spot-screensaver.desktop
Index: src/GalleryExport.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/GalleryExport.cs,v
retrieving revision 1.36
diff -u -r1.36 GalleryExport.cs
--- src/GalleryExport.cs	22 Mar 2006 16:57:27 -0000	1.36
+++ src/GalleryExport.cs	7 Apr 2006 14:51:48 -0000
@@ -497,11 +497,13 @@
 			LoadPreference (Preferences.EXPORT_GALLERY_SIZE);
 			LoadPreference (Preferences.EXPORT_GALLERY_BROWSER);
 			LoadPreference (Preferences.EXPORT_GALLERY_META);
+			LoadPreference (Preferences.EXPORT_GALLERY_ROTATE);
 		}
 		
 		Gtk.ResponseHandler rh;
 		
 		private bool scale;
+		private bool rotate;
 		private int size;
 		private bool browser;
 		private bool meta;
@@ -531,6 +533,7 @@
 		[Glade.Widget] Gtk.CheckButton browser_check;
 		[Glade.Widget] Gtk.CheckButton scale_check;
 		[Glade.Widget] Gtk.CheckButton meta_check;
+		[Glade.Widget] Gtk.CheckButton rotate_check;
 		
 		[Glade.Widget] Gtk.SpinButton size_spin;
 
@@ -547,6 +550,7 @@
 
 		private void HandleResponse (object sender, Gtk.ResponseArgs args)
 		{
+
 			if (args.ResponseId != Gtk.ResponseType.Ok) {
 				Dialog.Destroy ();
 				return;
@@ -557,9 +561,11 @@
 				size = size_spin.ValueAsInt;
 			} else
 				scale = false;
+			
 
 			browser = browser_check.Active;
 			meta = meta_check.Active;
+			rotate = rotate_check.Active;
 
 			if (account != null) { 
 				//System.Console.WriteLine ("history = {0}", album_optionmenu.History);
@@ -579,6 +585,7 @@
 				Preferences.Set (Preferences.EXPORT_GALLERY_SIZE, size);
 				Preferences.Set (Preferences.EXPORT_GALLERY_BROWSER, browser);
 				Preferences.Set (Preferences.EXPORT_GALLERY_META, meta);
+				Preferences.Set (Preferences.EXPORT_GALLERY_ROTATE, rotate);
 			}
 		}
 		
@@ -619,6 +626,15 @@
 						System.IO.File.Move (path, final);
 						album.Add (photo, final);
 						System.IO.File.Delete (final);
+					} else if (rotate) {
+						System.Console.WriteLine ("DEBUG: rotating photo");
+						string orig = photo.DefaultVersionUri.LocalPath;
+						string path = PixbufUtils.Rotate (orig, true);
+						string final = path + System.IO.Path.GetExtension (orig);
+						System.IO.File.Move (path, final);
+						album.Add (photo, final);
+						System.IO.File.Delete (final);
+						
 					} else {
 						album.Add (photo);
 					}
@@ -794,6 +810,10 @@
 			case Preferences.EXPORT_GALLERY_META:
 				if (meta_check.Active != (bool) val)
 					meta_check.Active = (bool) val;
+				break;
+			case Preferences.EXPORT_GALLERY_ROTATE:
+				if (rotate_check.Active != (bool) val)
+					rotate_check.Active = (bool) val;
 				break;
 			}
 		}
Index: src/PixbufUtils.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/PixbufUtils.cs,v
retrieving revision 1.69
diff -u -r1.69 PixbufUtils.cs
--- src/PixbufUtils.cs	28 Feb 2006 17:50:22 -0000	1.69
+++ src/PixbufUtils.cs	7 Apr 2006 14:51:48 -0000
@@ -413,6 +413,7 @@
 		return version_path;
 	}
 
+	
 	public static void Resize (string orig_path, string dest_path, int size, bool copy_meta)
 	{
 		Exif.ExifData exif_data;
@@ -424,8 +425,28 @@
 		Gdk.Pixbuf image = PixbufUtils.LoadAtMaxSize (orig_path, size, size);
 		PixbufUtils.SaveJpeg (image, dest_path, 95, exif_data);
 	}
-	
 
+	public static string Rotate (string orig_path, bool copy_meta)
+	{
+		string version_path = System.IO.Path.GetTempFileName ();
+		Rotate (orig_path, version_path, copy_meta);
+		return version_path;
+	}
+		
+	public static void Rotate (string orig_path, string dest_path, bool copy_meta)
+	{
+		Exif.ExifData exif_data;
+		if (copy_meta)
+			exif_data = new Exif.ExifData (orig_path);
+		else 
+			exif_data = new Exif.ExifData ();
+		
+		PixbufOrientation orientation = GetOrientation (exif_data);
+		Gdk.Pixbuf orig = new Gdk.Pixbuf(orig_path);
+		Gdk.Pixbuf image = PixbufUtils.TransformOrientation (orig, orientation, copy_meta);
+		PixbufUtils.SaveJpeg (image, dest_path, 95, exif_data);
+	}
+	
 	[StructLayout(LayoutKind.Sequential)]
 	public unsafe struct FPixbufJpegMarker {
 		public int type;
Index: src/Preferences.cs
===================================================================
RCS file: /cvs/gnome/f-spot/src/Preferences.cs,v
retrieving revision 1.12
diff -u -r1.12 Preferences.cs
--- src/Preferences.cs	22 Mar 2006 23:53:36 -0000	1.12
+++ src/Preferences.cs	7 Apr 2006 14:51:48 -0000
@@ -70,6 +70,7 @@
 		public const string EXPORT_GALLERY_SIZE = "/apps/f-spot/export/gallery/size";
 		public const string EXPORT_GALLERY_BROWSER = "/apps/f-spot/export/gallery/browser";
 		public const string EXPORT_GALLERY_META = "/apps/f-spot/export/gallery/meta";
+		public const string EXPORT_GALLERY_ROTATE = "/apps/f-spot/export/gallery/rotate";
 
 		public const string SCREENSAVER_TAG = "/apps/f-spot/screensaver/tag_id";
 
Index: src/f-spot.glade
===================================================================
RCS file: /cvs/gnome/f-spot/src/f-spot.glade,v
retrieving revision 1.159
diff -u -r1.159 f-spot.glade
--- src/f-spot.glade	25 Feb 2006 08:54:05 -0000	1.159
+++ src/f-spot.glade	7 Apr 2006 14:51:57 -0000
@@ -3694,6 +3694,25 @@
 			      <property name="fill">False</property>
 			    </packing>
 			  </child>
+
+			  <child>
+			    <widget class="GtkCheckButton" id="rotate_check">
+			      <property name="visible">True</property>
+			      <property name="can_focus">True</property>
+			      <property name="label" translatable="yes">Rotate when required</property>
+			      <property name="use_underline">True</property>
+			      <property name="relief">GTK_RELIEF_NORMAL</property>
+			      <property name="focus_on_click">True</property>
+			      <property name="active">True</property>
+			      <property name="inconsistent">False</property>
+			      <property name="draw_indicator">True</property>
+			    </widget>
+			    <packing>
+			      <property name="padding">0</property>
+			      <property name="expand">False</property>
+			      <property name="fill">False</property>
+			    </packing>
+			  </child>
 			</widget>
 		      </child>
 		    </widget>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]