Final step for non-force-conversion to jpeg
authorChristopher Allan Webber <cwebber@dustycloud.org>
Sat, 12 Nov 2011 21:12:39 +0000 (15:12 -0600)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Sat, 12 Nov 2011 21:12:39 +0000 (15:12 -0600)
mediagoblin/process_media/__init__.py

index 85bdcbeab6803a8ef857a2e866402d7f3c097625..f63fb2b0237f7b5224b95f1df86582c082d7fcd6 100644 (file)
@@ -14,8 +14,9 @@
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-import Image
+import os
 
+import Image
 from celery.task import Task
 from celery import registry
 
@@ -122,17 +123,16 @@ def process_image(entry):
         mgg.queue_store, queued_filepath,
         'source')
 
+    extension = os.path.splitext(queued_filename)[1]
+
     try:
         thumb = Image.open(queued_filename)
     except IOError:
         raise BadMediaFail()
 
     thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
-    # ensure color mode is compatible with jpg
-    if thumb.mode != "RGB":
-        thumb = thumb.convert("RGB")
 
-    thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg')
+    thumb_filepath = create_pub_filepath(entry, 'thumbnail' + extension)
     thumb_file = mgg.public_store.get_file(thumb_filepath, 'w')
 
     with thumb_file:
@@ -147,10 +147,7 @@ def process_image(entry):
     if medium.size[0] > MEDIUM_SIZE[0] or medium.size[1] > MEDIUM_SIZE[1]:
         medium.thumbnail(MEDIUM_SIZE, Image.ANTIALIAS)
 
-        if medium.mode != "RGB":
-            medium = medium.convert("RGB")
-
-        medium_filepath = create_pub_filepath(entry, 'medium.jpg')
+        medium_filepath = create_pub_filepath(entry, 'medium' + extension)
         medium_file = mgg.public_store.get_file(medium_filepath, 'w')
 
         with medium_file: