# Phatch - Photo Batch Processor # Copyright (C) 2007-2008 www.stani.be # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see http://www.gnu.org/licenses/ # # Phatch recommends SPE (http://pythonide.stani.be) for editing python files. # Embedded icon is taken from www.openclipart.org (public domain) from core import models from core.translation import _t, new # constants ANGLE_90CW = _t( '90 clock-wise' ) ANGLE_90CCW = _t( '90 contra clock-wise' ) ANGLE_180 = _t( '180' ) FLIP_V = _t( 'flip left to right' ) FLIP_H = _t( 'flip top to bottom' ) ANGLES = [ ANGLE_90CW, ANGLE_90CCW, ANGLE_180, FLIP_V, FLIP_H ] CONDITION_WtH = _t('if wider than high') CONDITION_HtW = _t('if higher than wide') CONDITIONS = [ CONDITION_WtH, CONDITION_HtW ] # PIL function def init(cls=None): global Image import Image def conditionaltranspose( image, width, height, angle=ANGLE_90CCW, condition=CONDITION_WtH ): dorotate = 0; if condition == CONDITION_WtH and width > height: dorotate = 1; elif condition == CONDITION_HtW and height > width: dorotate = 1; if dorotate: if angle == ANGLE_90CW: mode = Image.ROTATE_270 elif angle == ANGLE_90CCW: mode = Image.ROTATE_90 elif angle == ANGLE_180: mode = Image.ROTATA_180 elif angle == FLIP_V: mode = Image.FLIP_LEFT_RIGHT elif angle == FLIP_H: mode = Image.FLIP_TOP_BOTTOM else: mode = -1 image = image.transpose( mode ) return image class Action(models.Action): label = _t('Conditional Transpose') author = 'nEJC' email = 'nejc@nejc.info' init = staticmethod(init) pil = staticmethod(conditionaltranspose) version = '0.1' tags = [_t('condition'),_t('transpose')] __doc__ = _t('This action will transpose image with specified angle if set condition is met') def interface(self,fields): fields[_t('Angle')] = self.ChoiceField(ANGLES[0],ANGLES) fields[_t('Condition')] = self.ChoiceField(CONDITIONS[0],CONDITIONS) def values(self,info): width, height = info[new('Pil','Size')] angle = self.get_field( _t('Angle'), info ) condition = self.get_field( _t('Condition'), info ) return { 'width' : width, 'height' : height, 'angle' : angle, 'condition' : condition } icon = \ 'x\xda\x01`\t\x9f\xf6\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x000\x00\ \x00\x000\x08\x06\x00\x00\x00W\x02\xf9\x87\x00\x00\x00\x04sBIT\x08\x08\x08\ \x08|\x08d\x88\x00\x00\t\x17IDATh\x81\xed\xd9{\x8c\x9c\xd5y\x06\xf0\xdf\x99o\ \xee3{\xb7Y_\xd6\xd8\xd8\xa6\xc4.\x94\xe2[q\xa0\x01\n\xa8n\xa4\xc4$\xa2T\t\ \xa9ZE\x15\x94^\x94J\xf9\xa3\x89Z\xb5RD\xa4\xa4Q/\x8a\x8aZH\xa2DjU\x13\xa5\ \x8dTTD\x1b \x89"\x07\x1a\xb0MK|\xc7\xb0x\xb1\x8d\xbd\xbe\xad\xed\xf5\xce^f\ \xe6\xeb\x1f\xdf7\xde\xf5\xb2\xbe\x82eU\xf2;:\xfaFG\xe7;\xf3<\xefy\xcf{\x9e\ \xf7L\x88\xe3\xd8\xffg\xcb\\m\x00\xef\xd7\xae\x11\xb8\xdav\x8d\xc0\xd5\xb6\ \x0f\x8c@\x08!\x84\xef\x85(\xbc\x1bz\xc2\xa9\xb0$\x8c\x86\x15\xeb\xeb\xf7\ \xaf\xfe\xa0\xe6?\x97e/\xf7\xc5 T5\xdd#\xb6J\xb0R\xc3J\x19\xbd\x08\xad1\x1d\ \xa7\xdb\x07C.\xf4\xa1\x1e_\xa1|}I\x04\x82P\xc4G\xc5>-\xf8\xa8\x8c\xd2L\xe3\ \xf2r\xe6\x98-;\x92\x9b\x85v\x9c\xc4\xc4\xfb\x87\xfb^\xbb(\x02A\xc8\xe3Q\xfc\ \x19z\'}\xccrK\xac\xf3\x11\xd7\x9b\xaf\xcf\\\x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