changeset 5:413a64b78621

text_x_arnica: factored out create_thumbnail_and_webnail from format
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Sat, 08 Mar 2008 21:18:36 +0100
parents ccc40ffe14fc
children 756cb845ddad
files data/plugin/parser/text_x_arnica.py
diffstat 1 files changed, 39 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/parser/text_x_arnica.py	Sat Mar 08 18:50:11 2008 +0100
+++ b/data/plugin/parser/text_x_arnica.py	Sat Mar 08 21:18:36 2008 +0100
@@ -528,6 +528,37 @@
         
         return all_files
     
+    def create_thumbnail_and_webnail(self, image, webnail, thumbnail, image_type):
+        """creates thumbnails and webnails for given image type
+        @param image: filename of image
+        @param webnail: filename of webnail file
+        @param thumbnail: filename of thumbnail file
+        @param image_type: filetype of image
+        """
+        imagef = os.path.join(self.static_path, image)
+        webf = os.path.join(self.static_path, webnail)
+        thumbf = os.path.join(self.static_path, thumbnail) 
+        
+        if self.renew == '1':
+            if os.path.exists(thumbf):
+                os.unlink(thumbf)
+            if os.path.exists(webf):
+                os.unlink(webf)
+                    
+        if not os.path.exists(webf) or not os.path.exists(thumbf):
+            im_obj = Image.open(imagef)
+            if not os.path.exists(webf):
+                im_obj.thumbnail((int(self.webnail_width), int(self.webnail_width)), Image.ANTIALIAS)
+                if self.image_for_webnail == '1':
+                    os.link(imagef, webf)
+                else:
+                    im_obj.save(webf, image_type)
+            if not os.path.exists(thumbf):
+                im_obj.thumbnail(((int(self.thumbnail_width)), ((int(self.thumbnail_width)))),
+                               Image.ANTIALIAS)
+                im_obj.save(thumbf, image_type)
+
+                
     def format(self, formatter):
         """ does the format """
         _ = self._
@@ -547,9 +578,9 @@
         if self.template_itemlist == '1':
             self.request.write(_("Copy the following listitems into the script. Replace alias with the label you want. Afterwards disable template_itemlist by setting it to 0:"))
             self.request.write('<br>')
-            for attfile in self.full:
-                self.request.write(' * [[%(attfile)s|%(alias)s]]<br>\n' % {
-                                   'attfile': attfile,
+            for image in self.full:
+                self.request.write(' * [[%(image)s|%(alias)s]]<br>\n' % {
+                                   'image': image,
                                    'alias': 'alias'
                                     })
 
@@ -564,51 +595,13 @@
                 self.request.write('<tr valign="top">')
                 self.request.write('<td%s>' % self.td_style)
 
-
         if self.album == '1':
-            front_image = self.front_image
-            if self.front_image == '':
-                front_image = self.full[0]
-
-            ii = 0
-            for tst in self.full:
-                if tst == front_image:
-                    break
-                ii += 1
-
-        for attfile in self.full:
-            if self.album == '1':
-                if tst == front_image:
-                    i = ii
-
-            this_webnail = self.web[i]
-            this_imgtype = self.imgtype[i]
-            this_thumbfile = self.thumb[i]
+            front_image = self.front_image or self.full[0]
+            i = self.full.index(front_image)
 
-            thumbf = os.path.join(self.static_path, this_thumbfile)
-            webf = os.path.join(self.static_path, this_webnail)
-
-            if self.renew == '1':
-                if os.path.exists(thumbf):
-                    os.unlink(thumbf)
-                if os.path.exists(webf):
-                    os.unlink(webf)
-
-            if not os.path.exists(webf) or not os.path.exists(thumbf):
-                infile = os.path.join(self.static_path, attfile)
-                im = Image.open(infile)
-
-                if not os.path.exists(webf):
-                    im.thumbnail((int(self.webnail_width), int(self.webnail_width)), Image.ANTIALIAS)
-                    if self.image_for_webnail == '1':
-                        os.link(os.path.join(self.static_path, attfile), webf)
-                    else:
-                        im.save(webf, this_imgtype)
-                if not os.path.exists(thumbf):
-                    im.thumbnail(((int(self.thumbnail_width)), ((int(self.thumbnail_width)))),
-                                   Image.ANTIALIAS)
-                    im.save(thumbf, this_imgtype)
-
+        for image in self.full:
+            self.create_thumbnail_and_webnail(image, self.web[i], self.thumb[i], self.imgtype[i])
+            
             if self.image_for_webnail == '1':
                 self.webimg = self.full
             else: