Commits

Tomas Zulberti  committed 902c296

Added the value to copy the articles images files.

  • Participants
  • Parent commits 01ea37e

Comments (0)

Files changed (2)

File pet_builder/commands.py

 
 import os
 
+from PIL import Image
 from shutil import copy
 from pet_builder import settings
 from pet_builder.basic_structure import main, PAGE_ORIENTATIONS, PDF_PAGE_SIZES
 from pet_builder.utils import copy_render_template, create_folders
 
 
+IMAGE_SIZES = {
+    'landscape': (400, 400),
+    'portait': (400, 400)
+}
+
 def create_html():
     ''' Create the html structure and the articles files
     to the html folders.
             copy_render_template(pdf_master_template, destination_folder, additional_data)
 
             articles_destination_folder = os.path.join(destination_folder, 'articles')
+            images_destination = os.path.join(destination_folder, 'images')
+            create_folders([images_destination])
 
             for article in articles_files:
-                article_destination = os.path.join(articles_destination_folder, os.path.dirname(article))
+                article_folder = os.path.dirname(article)
+                article_destination = os.path.join(articles_destination_folder, article_folder)
                 create_folders([article_destination])
                 copy(article, article_destination)
 
+                # resize the image used by the article.
+                article_images_folder = os.path.join(article_folder, 'images')
+                size = IMAGE_SIZES[orientation]
+                for article_image in os.listdir(article_images_folder):
+                    image_name = os.path.join(article_images_folder, article_image)
+                    image_final_name = os.path.join(images_destination, os.path.basename(article_image))
+                    im = Image.open(image_name)
+                    im.thumbnail(size, Image.ANTIALIAS)
+
+                    final_image = os.path.join(article_destination, image_final_name)
+                    im.save(final_image)
+
+
 
 
 
     'pelican',
     'rst2pdf',
     'docutils==0.7', # see http://code.google.com/p/rst2pdf/issues/detail?id=423&q=get_language
+    'Pillow'
 ]