[kupfer] plugin.image: Detect if Autorotate makes sense or not
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer] plugin.image: Detect if Autorotate makes sense or not
- Date: Wed, 16 Sep 2009 14:22:43 +0000 (UTC)
commit cf781bb338dc31f12276e96920bd1a52d05409be
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Tue Sep 15 16:41:52 2009 +0200
plugin.image: Detect if Autorotate makes sense or not
We simply launch jhead and check the file's headers. If jhead is not
installed, or Orientation is as it should, the action does not apply.
kupfer/plugin/image.py | 17 +++++++++++++----
1 files changed, 13 insertions(+), 4 deletions(-)
---
diff --git a/kupfer/plugin/image.py b/kupfer/plugin/image.py
index f4c6113..e48af33 100644
--- a/kupfer/plugin/image.py
+++ b/kupfer/plugin/image.py
@@ -4,7 +4,7 @@ from os import path as os_path
import subprocess
from kupfer.objects import Leaf, Action, FileLeaf, TextLeaf
-from kupfer import utils
+from kupfer import utils, pretty
__kupfer_name__ = _("Image Tools")
__kupfer_sources__ = ()
@@ -135,10 +135,19 @@ class Autorotate (Action):
yield FileLeaf
def valid_for_item(self, item):
- # FIXME: Make this detection smarter
root, ext = os_path.splitext(item.object)
- return ext.lower() in (".jpeg", ".jpg")
+ if not ext.lower() in (".jpeg", ".jpg"):
+ return False
+ # Launch jhead to see if 1) it is installed, 2) Orientation nondefault
+ try:
+ cmdargs = ("jhead", item.object)
+ proc = subprocess.Popen(cmdargs, stdout=subprocess.PIPE)
+ except OSError:
+ pretty.print_debug(__name__ , "Action %s needs 'jhead'" % self)
+ else:
+ out, err = proc.communicate()
+ return any(li.startswith("Orientation") for li in out.splitlines())
def get_description(self):
- return _("Rotate JPEG image (in-place) according to its EXIF metadata")
+ return _("Rotate JPEG (in-place) according to its EXIF metadata")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]