I’ve added the ability to extract and upload images to my post-with-markdown script. Unfortunately, markdown doesn’t have short codes for setting the size of a displayed I could solve this problem by using a full image tag in the post. Or, I can upload multiply sized versions of the image, and call in the post the one that I want. As a coding experiment, I decided to do the latter. Also, for the simplicity of the script it’s easier to upload a single mime type. Since I’m most often, though not exclusively, uploading screen shots, it just seems easier to use .png files.
Both of these tasks — resizing images and switching formats — are easy to accomplish using the Python Imaging Library. Getting PIL up and running on Snow Leopard, not so much. I first installed using
easy_install, and everything seemed to be working fine except for jpeg encoding/decoding. I apparently didn’t have
libjpg installed. So, I used macports to install the library with
$ sudo port install jpeg. After that, I needed to reinstall PIL. I uninstalled the library using
pip (I don’t know why I did it that way instead of with
easy_install.) Then, I reinstalled PIL with
pip and, low and behold, jpeg encoding was available and fine, but PIL’s _imaging C libraries stopped working. Grrr. I tried tons of ways around this, but simply couldn’t figure out one that worked.
What finally worked was a two-step process in Emotu Balogun’s comment on the top rated answer to this stackoverflow question. Apparently the problem has to do with incompatibilities of the gcc version, libjpeg, and PIL. At any rate, this worked for me:
Reinstall libjpeg with Macports and adding the +universal argument to the command:
$ sudo port install jpeg +universal.
Install PIL with Macports in the same manner:
$ sudo port install py26-pil +universal.
I use Snow Leopard’s default 2.6.1 python installation, so I copied the PIL package from Macports’ site-packages folder in
/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packagesto Snow Leopard’s default site-packages library.
After doing that, PIL is working. Worth it? Not so sure. But, with PIL I can convert all of my images for this blog to .png files, and also resize the images to upload one that will fit in the dimensions of my posts.