Skip to content

Commit

Permalink
Add a script to convert gifs/jpgs to pngs; bug 593267
Browse files Browse the repository at this point in the history
  • Loading branch information
clouserw committed Sep 9, 2010
1 parent a99f543 commit d3a8a4a
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions apps/users/management/commands/fix_user_images.py
@@ -0,0 +1,39 @@
import os
import sys

from django.core.management.base import BaseCommand


class Command(BaseCommand):

help = """Convert non-png files to png files. One time script,
see bug 593267."""

def handle(self, *args, **options):
from django.conf import settings
from users.tasks import delete_photo, resize_photo

if not os.path.isdir(settings.USERPICS_PATH):
sys.exit("Can't read pics path: %s" % settings.USERPICS_PATH)

converted = 0
for root, dirs, files in os.walk(settings.USERPICS_PATH):
for file in files:
if file[-4:] in ('.jpg', '.gif'):
name, _ = os.path.splitext(file)
oldfile = "%s/%s" % (root, file)
newfile = "%s/%s.png" % (root, name)

if os.path.isfile(newfile):
delete_photo(oldfile)
else:
resize_photo(oldfile, newfile)
converted += 1
if converted % 100 == 0:
print "Converted %s images..." % converted

elif file.endswith('.png') or file.endswith('__unconverted'):
pass
else:
print "Not sure what to do with: %s" % file
print "All done."

0 comments on commit d3a8a4a

Please sign in to comment.