allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject allura git commit: [#2578] Add Convert bmp to jpeg screenshots when uploading
Date Thu, 27 Sep 2018 17:45:52 GMT
Repository: allura
Updated Branches:
  refs/heads/master b37c80570 -> 10b0d7586


[#2578] Add Convert bmp to jpeg screenshots when uploading


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/10b0d758
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/10b0d758
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/10b0d758

Branch: refs/heads/master
Commit: 10b0d7586fb726eb0eb51f19d605fa9c5ff7761f
Parents: b37c805
Author: Shalitha <shalithasuranga@gmail.com>
Authored: Tue Sep 25 22:12:03 2018 +0530
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Thu Sep 27 17:40:37 2018 +0000

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py | 12 ++++++++++--
 Allura/allura/model/filesystem.py     | 15 +++++++++++++--
 2 files changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/10b0d758/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index 1b61002..c2d8239 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -17,6 +17,7 @@
 
 import logging
 import re
+import os
 from random import randint
 from collections import OrderedDict
 from datetime import datetime
@@ -518,8 +519,15 @@ class ProjectAdminController(BaseController):
             flash('You may not have more than 6 screenshots per project.',
                   'error')
         elif screenshot is not None and screenshot != '':
+            future_bmp = False
+            e_filename, e_fileext = os.path.splitext(screenshot.filename)
             for screen in screenshots:
-                if screen.filename == screenshot.filename:
+                c_filename, c_fileext = os.path.splitext(screen.filename)
+                if c_fileext == '.png' and e_fileext.lower() == '.bmp' and e_filename ==
c_filename:
+                    future_bmp = True
+                    # If both filename(without ext.) equals and exiting file ext. is png
and given file ext is bmp, there will be two similar png files.
+
+                if screen.filename == screenshot.filename or future_bmp:
                     screenshot.filename = re.sub('(.*)\.(.*)', r'\1-' + str(randint(1000,9999))
+ r'.\2', screenshot.filename)
                     # if filename already exists append a random number
                     break
@@ -534,7 +542,7 @@ class ProjectAdminController(BaseController):
                     caption=caption,
                     sort=sort),
                 square=True, thumbnail_size=(150, 150),
-                thumbnail_meta=dict(project_id=c.project._id, category='screenshot_thumb'))
+                thumbnail_meta=dict(project_id=c.project._id, category='screenshot_thumb'),
convert_bmp=True)
             g.post_event('project_updated')
         redirect('screenshots')
 

http://git-wip-us.apache.org/repos/asf/allura/blob/10b0d758/Allura/allura/model/filesystem.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/filesystem.py b/Allura/allura/model/filesystem.py
index 00a306e..3f2824c 100644
--- a/Allura/allura/model/filesystem.py
+++ b/Allura/allura/model/filesystem.py
@@ -16,6 +16,7 @@
 #       under the License.
 
 import os
+import re
 from cStringIO import StringIO
 import logging
 
@@ -37,7 +38,8 @@ SUPPORTED_BY_PIL = set([
     'image/pjpeg',
     'image/png',
     'image/x-png',
-    'image/gif'])
+    'image/gif',
+    'image/bmp'])
 
 
 class File(MappedClass):
@@ -151,6 +153,8 @@ class File(MappedClass):
         thumbnail = cls(
             filename=filename, content_type=content_type, **thumbnail_meta)
         format = image.format or 'png'
+        if format == 'BMP': # use jpg format if bmp is provided
+            format = 'PNG'
         with thumbnail.wfile() as fp_w:
             if 'transparency' in image.info:
                 image.save(fp_w,
@@ -167,7 +171,8 @@ class File(MappedClass):
                    thumbnail_meta=None,
                    square=False,
                    save_original=False,
-                   original_meta=None):
+                   original_meta=None,
+                   convert_bmp=False):
         if content_type is None:
             content_type = utils.guess_mime_type(filename)
         if not content_type.lower() in SUPPORTED_BY_PIL:
@@ -182,6 +187,12 @@ class File(MappedClass):
             return None, None
 
         format = image.format
+
+        if format == 'BMP' and convert_bmp: # use jpg format if bitmap is provided
+            format = 'PNG'
+            content_type = 'image/png'
+            filename = re.sub('.bmp$', '.png', filename, flags=re.IGNORECASE)
+ 
         if save_original:
             original_meta = original_meta or {}
             original = cls(


Mime
View raw message