I've uploaded a fix in the bazaar repository. I've tested this only one image, so a lot of good testing is required now. Droopy, I count on you ;-) I'll upload it to my PPA where it will be available as Phatch-0.2.0.bzr656 or a later version. https://launchpad.net/~stani/+archive/ppa
try:
from unicoding import ensure_unicode
@@ -82,6 +83,13 @@
raise Exception('Libtiff tools are needed for "%s" compression'\ %compression)
+def transpose(image, methods):
+ """Transpose with a sequence of transformations, mainly useful
+ for exif."""
+ for method in methods:
+ image = image.transpose(method)
+ return image
+
def treshold(a):
if a <= 128:
return 255
@@ -144,6 +152,7 @@
def extract_info_pexif(info,image):
"""pexif = Pil EXIF"""
+ info['Pexif'] = 1
#check if exif information is available through pil
if not hasattr(image,'_getexif'):
return info
@@ -345,6 +354,7 @@ self._rotate_exif_reverse = None self.metadata = {} self.init_info(layer,filename,image_index,save_metadata,folder)
+ self.rotate_exif()
def flush_metadata(self):
#is there something to be flushed?
@@ -352,8 +362,7 @@
return
#throw an error if pyexiv2 is not installed
if not exif:
- raise ImportError(_('pyexiv2 needs to be installed')\
- +' (%s)'%WWW_PYEXIV2)
+ raise ImportError(NEEDS_PYEXIV2)
self.log += exif.flush(self.info['path'],self.metadata)
#as metadata has changed, use new source self._exif_source = self.info['path']
@@ -403,7 +412,8 @@
def save(self,filename,**options):
"""Saves a flattened image"""
#todo: flatten layers
- image = self.get_layer().image
+ image = transpose(self.get_layer().image,
+ self._rotate_exif_reverse)
if image.mode == 'CMYK' and filename.lower().endswith('.png'): self.log = \ _('CMYK has been converted to RGB to save as PNG.')
@@ -467,13 +477,51 @@
I've uploaded a fix in the bazaar repository. I've tested this only one image, so a lot of good testing is required now. Droopy, I count on you ;-) I'll upload it to my PPA where it will be available as Phatch-0.2.0.bzr656 or a later version. /launchpad. net/~stani/ +archive/ ppa
https:/
$ bzr diff core/api. py' 'abort' ] = False
=== modified file 'phatch/
--- phatch/core/api.py 2009-06-05 00:29:01 +0000
+++ phatch/core/api.py 2009-06-05 17:59:27 +0000
@@ -274,7 +274,7 @@
result[
return photo, result
-def flush_log(photo):
log_error( photo.log, image_file, action, label=' Warning' )
result[ 'skip'] = False
result[ 'abort' ] = False split(ensure_ unicode( image_file) ) flush_metadata_ before:
photo. flush_metadata( )
# update progress
progress_ result = {}
send. progress_ update_ index(progress_ result, image_index, action_ index)
break
photo. flush_metadata( ) progress_ close()
+def flush_log(photo, image_file, action=None):
if photo.log:
photo.log = ''
@@ -285,7 +285,7 @@
#log non fatal errors/warnings
- flush_log(photo)
+ flush_log(photo, image_file, action)
return photo, result
except Exception, details:
folder, image = os.path.
@@ -382,7 +382,7 @@
for action_index, action in enumerate(actions):
if action.
- flush_log(photo)
+ flush_log(photo, image_file)
@@ -397,7 +397,7 @@
elif result['skip']:
- flush_log(photo)
+ flush_log(photo, image_file, action)
del photo, progress_result, action_index, action
send.
=== modified file 'phatch/ core/lib/ formField. py' core/lib/ formField. py 2009-06-05 13:59:16 +0000 core/lib/ formField. py 2009-06-05 17:49:18 +0000
BYSIZE+ '/'+SUBFOLDER,
DEFAULT_ FOLDER,
FOLDER_ PHATCH, '/'+SUBFOLDER,
--- phatch/
+++ phatch/
@@ -225,6 +225,7 @@
+ FOLDER+
FOLDER,
]
STAMPS = [
=== modified file 'phatch/ core/pil. py' tilloy. net/dev/ pyexiv2/ '
--- phatch/core/pil.py 2009-06-05 13:15:12 +0000
+++ phatch/core/pil.py 2009-06-05 17:54:49 +0000
@@ -39,6 +39,7 @@
pyexiv2 = None
exif = False
WWW_PYEXIV2 = 'http://
+NEEDS_PYEXIV2 = _('pyexiv2 needs to be installed')+' (%s)'%WWW_PYEXIV2
try:
% compression)
from unicoding import ensure_unicode
@@ -82,6 +83,13 @@
raise Exception('Libtiff tools are needed for "%s" compression'\
+def transpose(image, methods): (method)
+ """Transpose with a sequence of transformations, mainly useful
+ for exif."""
+ for method in methods:
+ image = image.transpose
+ return image
+
def treshold(a):
if a <= 128:
return 255
@@ -144,6 +152,7 @@
def extract_ info_pexif( info,image) : image,' _getexif' ):
self. _rotate_ exif_reverse = None
self. metadata = {}
self. init_info( layer,filename, image_index, save_metadata, folder)
"""pexif = Pil EXIF"""
+ info['Pexif'] = 1
#check if exif information is available through pil
if not hasattr(
return info
@@ -345,6 +354,7 @@
+ self.rotate_exif()
def flush_metadata( self): _('pyexiv2 needs to be installed')\ NEEDS_PYEXIV2) self.info[ 'path'] ,self.metadata)
self. _exif_source = self.info['path'] filename, **options) : layer() .image self.get_ layer() .image, exif_reverse) lower() .endswith( '.png') :
self. log = \
_('CMYK has been converted to RGB to save as PNG.')
#is there something to be flushed?
@@ -352,8 +362,7 @@
return
#throw an error if pyexiv2 is not installed
if not exif:
- raise ImportError(
- +' (%s)'%WWW_PYEXIV2)
+ raise ImportError(
self.log += exif.flush(
#as metadata has changed, use new source
@@ -403,7 +412,8 @@
def save(self,
"""Saves a flattened image"""
#todo: flatten layers
- image = self.get_
+ image = transpose(
+ self._rotate_
if image.mode == 'CMYK' and filename.
@@ -467,13 +477,51 @@
def rotate_ exif(self, reverse= False): _rotate_ exif_reverse is None): values( ): transpose( exif_reverse) exif_reverse = None exif_reverse exif_reverse = () orientation( ) exif_reverse = () LEFT_RIGHT, exif_reverse = Image.FLIP_ LEFT_RIGHT, exif_reverse = Image.ROTATE_180, TOP_BOTTOM, exif_reverse = Image.FLIP_ TOP_BOTTOM, LEFT_RIGHT, Image.ROTATE_ 90 exif_reverse = Image.ROTATE_ 270,Image. FLIP_LEFT_ RIGHT exif_reverse = Image.ROTATE_270, LEFT_RIGHT, Image.ROTATE_ 270 exif_reverse = Image.ROTATE_ 90,Image. FLIP_LEFT_ RIGHT exif_reverse = Image.ROTATE_270, _('Unknown orientation value (%s)')%orientation) values( ): layer.image, rotation) (self): 'Pexif. Orientation' ] info_pexif( self.info, layers[ 0]) 'Pexif. Orientation' ]
if reverse:
- if not(self.
- for layer in self.layers.
- layer.image = layer.image.
- self._rotate_
- self._rotate_
+ rotation = self._rotate_
+ self._rotate_
else:
- pass
+ orientation = self.get_
+ #see EXIF.py
+ if orientation == 1:
+ rotation = self._rotate_
+ elif orientation == 2:
+ rotation = Image.FLIP_
+ self._rotate_
+ elif orientation == 3:
+ rotation = Image.ROTATE_180,
+ self._rotate_
+ elif orientation == 4:
+ rotation = Image.FLIP_
+ self._rotate_
+ elif orientation == 5:
+ rotation = Image.FLIP_
+ self._rotate_
+ elif orientation == 6:
+ self._rotate_
+ rotation = Image.ROTATE_90,
+ elif orientation == 7:
+ rotation = Image.FLIP_
+ self._rotate_
+ elif orientation == 8:
+ rotation = Image.ROTATE_90,
+ self._rotate_
+ else:
+ raise Exception(
+ if rotation:
+ for layer in self.layers.
+ layer.image = transpose(
+
+ def get_orientation
+ try:
+ return self.info[
+ except KeyError:
+ if 'Pexif' in self.info:
+ return 1
+ extract_
+ try:
+ orientation = self.info[
+ except KeyError:
+ return 1
#---pil self,function, *arg,** keyw):
def apply_pil(
$ bzr commit -m "take exif orientation in account" sync/python/ phatch/ trunk/ core/lib/ formField. py
Committing to: /home/stani/
modified phatch/core/api.py
modified phatch/core/pil.py
modified phatch/
Committed revision 654.