Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, PIL and JPEG on Heroku

I have a Django site, hosted on Heroku. One of the models has an image field, that takes uploaded images, resizes them, and pushes them to Amazon S3 so that they can be stored persistently.

This is working well, using PIL

def save(self, *args, **kwargs):


    # Save this one
    super(Product, self).save(*args,**kwargs)

    # resize on file system
    size = 200, 200
    filename = str(self.thumbnail.path)
    image = Image.open(filename)
    image.thumbnail(size, Image.ANTIALIAS)
    image.save(filename)

    # send to amazon and remove from ephemeral file system
    if put_s3(filename):
        os.remove(filename)
        return True

However, PIL seems to work fine for PNGs and GIFs, but is not compliled with libjpeg. On a local development environment or a fully controlled 'nix server, it is simply a case of installing the jpeg extension.

But does anyone know whether Jpeg manipulation is possible using the Cedar Heroku stack? Is there something else that can be added to requirements.txt?

Among other unrelated packages, the requirements.txt for this virtualenv includes:

Django==1.3.1
PIL==1.1.7
distribute==0.6.24
django-queued-storage==0.5
django-storages==1.1.4
psycopg2==2.4.4
python-dateutil==1.5
wsgiref==0.1.2

Thanks

like image 369
errkk Avatar asked Apr 18 '12 16:04

errkk


1 Answers

I use this PIL fork in requirements.txt:

-e hg+https://bitbucket.org/etienned/pil-2009-raclette/#egg=PIL

and can use JPEG without issues:

       --------------------------------------------------------------------
       PIL 1.2a0 SETUP SUMMARY
       --------------------------------------------------------------------
       version       1.2a0
       platform      Python 2.7.2 (default, Oct 31 2011, 16:22:04)
                     [GCC 4.4.3] on linux2
       --------------------------------------------------------------------
       *** TKINTER support not available
       --- JPEG support available
       *** WEBP support not available
       --- ZLIB (PNG/ZIP) support available
       --- FREETYPE2 support available
       --- LITTLECMS support available
       --------------------------------------------------------------------
like image 51
Mike Avatar answered Oct 02 '22 20:10

Mike