Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

I use the PHP Development Server for all of my local App Engine development work on my Mac and one of the features that's built into the app I'm working on at the moment is serving images. Out of the box this works just fine locally bar one small caveat - dynamic image resizing is not supported. If you do try and make use of image resizing, warnings like the following are displayed...
 GAE Dev Server Output
WARNING 2018-05-16 10:29:06,169 blob_image.py:208] Serving resized images requires a working Python "PIL" module. The image is served without resizing.


When deployed to App Engine it all works fine and this catch is explained in Google's documentation...
Note: When running your app locally on the development server, you'll need to install PIL if you wish to use the image sizing options described in this page.


Well no big deal, just install PIL right? Unfortunately at the time of writing there was no compiled version available for macOS and for the system Python version I was running. This meant I had to do a bit more work.

First I made sure of the Python version...
 Terminal
> python --version
Python 2.7.10


Alright, version 2.7, the only pre-compiled download I saw was for 2.5. I went ahead and got the source version of PIL 1.7. The following steps require Xcode and command line tools to be installed, I've already done this a long time ago, but here's a nice article that describes how to do it just in case.

I had a look at the README and got as far as the "If you're in a hurry" section...
--------------------------------------------------------------------
Build instructions (all platforms)
--------------------------------------------------------------------

For a list of changes in this release, see the CHANGES document.

0. If you're in a hurry, try this:

$ tar xvfz Imaging-1.1.7.tar.gz
$ cd Imaging-1.1.7
$ python setup.py install




Unfortunately that caused the build to fail, doh!
 Terminal
Imaging-1.1.7 > python setup.py install
...
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/usr/include/tk.h:78:11: fatal error: 'X11/Xlib.h' file not found
# include <X11/Xlib.h>


No matter, this was not a big deal. All I had to do was tell make where to look for the X11 headers. Below were the commands I used to build and finally install PIL...
 Terminal
export CFLAGS=-I/opt/X11/include
python setup.py build
sudo python setup.py install


That was all that was required. PIL installed correctly and after restarting the dev server I didn't see any more of the warnings about image resizing.

-i

Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...