changeset 36:3f042c1e2509

arnica_slides: image_rotate refactored to a function
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 24 May 2008 11:45:53 +0200
parents f8e8abce7208
children ad1d433589e4
files data/plugin/action/arnica_slides.py
diffstat 1 files changed, 27 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/arnica_slides.py	Sat May 24 11:33:28 2008 +0200
+++ b/data/plugin/action/arnica_slides.py	Sat May 24 11:45:53 2008 +0200
@@ -28,6 +28,31 @@
 
 action_name = __name__.split('.')[-1]
 
+def image_rotate(file_name, webf, thumbf, angle, img_type):
+    """ rotates the image and dependent images
+
+    @param file: the name of the attachment
+    @param webf: the name of the webnail
+    @param thumbf: the name of the thumbnail
+    @param angle: the angle to rotate to
+    @param img_type: type of image PNG or JPEG
+    """
+    # image
+    image_object = Image.open(file_name)
+    os.remove(file_name)
+    image_object.rotate(angle).save(file_name, img_type)
+
+    # image becomes webnail
+    new_image_object = Image.open(file_name)
+    new_image_object.thumbnail((640, 640), Image.ANTIALIAS)
+    os.remove(webf)
+    new_image_object.save(webf, img_type)
+
+    # image becomes thumbnail based on webnail
+    new_image_object.thumbnail((128, 128), Image.ANTIALIAS)
+    os.remove(thumbf)
+    new_image_object.save(thumbf, img_type)
+
 def html_js(request, counter):
     """ javscript for the slides
     @param request: request object
@@ -312,37 +337,6 @@
         """ Do the action and either return error msg or None, if there was no error. """
         return None
 
-    def image_rotate(self, file_name, webf, thumbf, angle, img_type):
-        """ rotates the image and dependent images
-
-        @param file: the name of the attachment
-        @param webf: the name of the webnail
-        @param thumbf: the name of the thumbnail
-        @param angle: the angle to rotate to
-        @param img_type: type of image PNG or JPEG
-        """
-        _ = self.request.getText
-        if not Image:
-            msg = _('The action %(action)s needs python imaging library (PIL) installed' % {'action': action_name})
-            self.request.theme.add_msg(msg, "error")
-            Page(self.request, self.pagename).send_page()
-            return
-        # image
-        image_object = Image.open(file_name)
-        os.remove(file_name)
-        image_object.rotate(angle).save(file_name, img_type)
-
-        # image becomes webnail
-        new_image_object = Image.open(file_name)
-        new_image_object.thumbnail((640, 640), Image.ANTIALIAS)
-        os.remove(webf)
-        new_image_object.save(webf, img_type)
-
-        # image becomes thumbnail based on webnail
-        new_image_object.thumbnail((128, 128), Image.ANTIALIAS)
-        os.remove(thumbf)
-        new_image_object.save(thumbf, img_type)
-
     def render(self):
         """ does execute the commands of the form data """
         _ = self.request.getText
@@ -476,12 +470,12 @@
                       'target': target})
             # rotate left
             elif command == 'RL':
-                self.image_rotate(infile, webf, thumbf, 90, img_type)
+                image_rotate(infile, webf, thumbf, 90, img_type)
                 msg = _('%(target)s rotated to left 90 degrees' % {'target': target})
 
             # rotate right
             elif command == 'RR':
-                self.image_rotate(infile, webf, thumbf, 270, img_type)
+                image_rotate(infile, webf, thumbf, 270, img_type)
                 msg = _('%(target)s rotated to right 90 degrees' % {'target': target})
 
             else: