Python, PIL and JPEG on Heroku

孤人 提交于 2019-12-03 11:42:29

问题


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


回答1:


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
       --------------------------------------------------------------------



回答2:


Also please consider using Pillow, the "friendly" PIL fork which offers:

  • Setuptools compatibility
  • Python 3 compatibility
  • Frequent release cycle
  • Many bug fixes


来源:https://stackoverflow.com/questions/10213509/python-pil-and-jpeg-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!