Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which has the better memory footprint, ImageMagick or Pillow (PIL)?

Our Heroku-hosted Django app does some simple image processing on images our users upload to Amazon S3—mostly resizing to the sizes we will display on the site. For this we use Pillow (the fork of the Python Imaging Library), running in a Celery task.

We have seen the time for this operation change from a fraction of a second to half a minute or more. My best guess for why is that we are now often getting memory-quota (R14) conditions (just because the application is bigger), which I would naïvely expect to make resizing particularly slow.

So I am considering refactoring the tasks to use an external ImageMagick process to do the processing rather than in-memory PIL. The thinking is that this will at least guarantee that memory used during resizing is released when the convert process terminates.

So my question is, is this going to help? Is ImageMagick’s convert going to have a smaller memory footprint than Pillow?

like image 731
pdc Avatar asked Dec 15 '25 13:12

pdc


1 Answers

I have had a similar experience (alas in Java) which might help make a decision .

Calling the ImageMagick library binding from Java (using JNI) seemed like a good idea, but turned out to leak memory by the tons.

We ended up moving to an external command-line invocation of ImageMagick - which worked a lot better, for the reason you mentioned- guarantee the release of memory.

like image 81
AssafR Avatar answered Dec 19 '25 11:12

AssafR