Whitespacing and PEP8-ing.

This commit is contained in:
Bryan Veloso 2011-10-11 02:13:47 +09:00
parent f0269831fd
commit 2d4f116e57
5 changed files with 23 additions and 18 deletions

View file

@ -3,23 +3,28 @@
from imagekit.specs import ImageSpec
from imagekit import processors
class ResizeThumbnail(processors.Resize):
width = 100
height = 50
crop = True
class EnhanceSmall(processors.Adjustment):
contrast = 1.2
sharpness = 1.1
class SampleReflection(processors.Reflection):
size = 0.5
background_color = "#000000"
class PNGFormat(processors.Format):
format = 'PNG'
extension = 'png'
class DjangoAdminThumbnail(ImageSpec):
access_as = 'admin_thumbnail'
processors = [ResizeThumbnail, EnhanceSmall, SampleReflection, PNGFormat]

View file

@ -14,6 +14,7 @@ class Command(BaseCommand):
def handle(self, *args, **options):
return flush_cache(args, options)
def flush_cache(apps, options):
""" Clears the image cache

View file

@ -154,5 +154,3 @@ class ImageModel(models.Model):
post_delete.connect(ImageModel.clear_cache, sender=ImageModel)

View file

@ -1,9 +1,9 @@
""" Imagekit Image "ImageProcessors"
A processor defines a set of class variables (optional) and a
class method named "process" which processes the supplied image using
the class properties as settings. The process method can be overridden as well allowing user to define their
own effects/processes entirely.
A processor defines a set of class variables (optional) and a class method
named "process" which processes the supplied image using the class properties
as settings. The process method can be overridden as well allowing user to
define their own effects/processes entirely.
"""
from imagekit.lib import Image, ImageEnhance, ImageColor
@ -61,8 +61,8 @@ class Reflection(ImageProcessor):
# create a new image filled with the bgcolor the same size
background = Image.new("RGB", img.size, background_color)
# calculate our alpha mask
start = int(255 - (255 * cls.opacity)) # The start of our gradient
steps = int(255 * cls.size) # the number of intermedite values
start = int(255 - (255 * cls.opacity)) # The start of our gradient
steps = int(255 * cls.size) # The number of intermedite values
increment = (255 - start) / float(steps)
mask = Image.new('L', (1, 255))
for y in range(255):
@ -100,7 +100,7 @@ class Resize(ImageProcessor):
if cls.crop:
crop_horz = getattr(obj, obj._ik.crop_horz_field, 1)
crop_vert = getattr(obj, obj._ik.crop_vert_field, 1)
ratio = max(float(cls.width)/cur_width, float(cls.height)/cur_height)
ratio = max(float(cls.width) / cur_width, float(cls.height) / cur_height)
resize_x, resize_y = ((cur_width * ratio), (cur_height * ratio))
crop_x, crop_y = (abs(cls.width - resize_x), abs(cls.height - resize_y))
x_diff, y_diff = (int(crop_x / 2), int(crop_y / 2))
@ -118,15 +118,15 @@ class Resize(ImageProcessor):
img = img.resize((int(resize_x), int(resize_y)), Image.ANTIALIAS).crop(box)
else:
if not cls.width is None and not cls.height is None:
ratio = min(float(cls.width)/cur_width,
float(cls.height)/cur_height)
ratio = min(float(cls.width) / cur_width,
float(cls.height) / cur_height)
else:
if cls.width is None:
ratio = float(cls.height)/cur_height
ratio = float(cls.height) / cur_height
else:
ratio = float(cls.width)/cur_width
new_dimensions = (int(round(cur_width*ratio)),
int(round(cur_height*ratio)))
ratio = float(cls.width) / cur_width
new_dimensions = (int(round(cur_width * ratio)),
int(round(cur_height * ratio)))
if new_dimensions[0] > cur_width or \
new_dimensions[1] > cur_height:
if not cls.upscale:

View file

@ -2,15 +2,16 @@
import tempfile
def img_to_fobj(img, format, **kwargs):
tmp = tempfile.TemporaryFile()
#preserve transparency if the image is in Pallette (P) mode
# Preserve transparency if the image is in Pallette (P) mode.
if img.mode == 'P':
kwargs['transparency'] = len(img.split()[-1].getcolors())
else:
img.convert('RGB')
img.save(tmp, format, **kwargs)
tmp.seek(0)
return tmp