8 from PIL
import Image, ImageOps
9 from pyramid.asset
import abspath_from_asset_spec
22 outpath = abspath_from_asset_spec(outpath)
23 if isinstance(size, int):
25 image = Image.open(infile)
26 if image.mode
not in (
'L',
'RGB'):
27 image = image.convert(
'RGB')
28 image = ImageOps.fit(image, size, Image.ANTIALIAS)
29 image.save(outpath, quality=100)
39 filepath = os.path.join(upload_dir, filename)
40 if os.path.exists(filepath):
42 shutil.copyfileobj(infile, open(filepath,
'wb'))
44 for subdir, size
in versions.items():
45 filepath = os.path.join(upload_dir, subdir, filename)
56 def __new__(self, root_dir, filename, versions=None):
60 return unicode.__new__(self, os.path.join(root_dir, filename))
64 raise AttributeError(
'Image does not have a %s version' % name)