My first GitHub project – PySmile

I launched a new FOSS project – PySmile. As the name suggests, the project written in Python. It’s a part of my learning process with Python and PIL (Python Imaging Library). The current version is 0.2. The application is able to do conversion of images to any of types [‘png’, ‘gif’, ‘jpg’, ‘bmp’, ‘pdf’]. Feel free to browse http://github.com/vietlq/PySmile and give me suggestions, even join me 🙂 . If you have not installed PIL, visit my previous post: http://blog.simpleit.us/2010/02/25/installing-pil-python-image-library-on-leopard/.

Installing PIL (Python Image Library) on Leopard

PIL is a simple yet powerful image processing library for Python which has both low level and high-level features. In this tutorial I will demonstrate installation of PIL on for Python 2.5 and 2.6 on Leopard. Below are steps:

0. Set up folder for installation

[cc lang=”bash”]
cd ~
mkdir -p simpleit/temp
cd simpleit/temp
[/cc]

1. Install Python 2.6

By default Leopard comes with Python 2.5.1 so we need to install Python 2.6. Let’s download Python 2.6 from ActiveState website: http://www.activestate.com/activepython/downloads/.

[cc lang=”bash”]
curl -C – -O http://downloads.activestate.com/ActivePython/releases/2.6.4.10/ActivePython-2.6.4.10-macosx.dmg
open ActivePython-2.6.4.10-macosx.dmg
[/cc]

Proceed with normal installation (don’t change any default configurations).

2. Install ZLIB

Grab ZLIB from its website http://www.zlib.net/ and do simple installation (both static & dynamic):

[cc lang=”bash”]
curl -C – -O http://www.zlib.net/zlib-1.2.3.tar.gz
tar zxvf zlib-1.2.3.tar.gz
cd zlib-1.2.3
./configure
make
sudo make install
./configure –shared
make
sudo make install
[/cc]

3. Install FreeType2

Get FreeType2 from its main site: http://www.freetype.org/:

[cc lang=”bash”]
curl -L -C – -O http://downloads.sourceforge.net/project/freetype/freetype2/2.3.12/freetype-2.3.12.tar.gz
tar zxvf freetype-2.3.12.tar.gz
cd freetype-2.3.12
./configure –with-zlib=/usr/local
make
sudo make install
[/cc]

4. Install jpeg

Get JPEG (now it’s version 8) from its main site: http://www.ijg.org/:

[cc lang=”bash”]
curl -L -C – -O http://www.ijg.org/files/jpegsrc.v8.tar.gz
tar zxvf jpegsrc.v8.tar.gz
cd jpeg-8
./configure –enable-shared –enable-static
make
sudo make install
[/cc]

5. Install TIFF

Get TIFF from its main site: http://www.libtiff.org/:

[cc lang=”bash”]
curl -L -C – -O ftp://ftp.remotesensing.org/pub/libtiff/tiff-3.9.2.tar.gz
tar zxvf tiff-3.9.2.tar.gz
cd tiff-3.9.2
./configure –with-zlib-include-dir=/usr/local/include –with-zlib-lib-dir=/usr/local/lib –with-jpeg-include-dir=/usr/local/include –with-jpeg-lib-dir=/usr/local/lib –enable-cxx –enable-jpeg –enable-zlib
make
sudo make install
[/cc]

6. Amend Python config Makefile

The easy part is over. Now read carefully. By default ActiveState Python assumes that you can build Universal binaries (x86 + PPC), which is wrong in most of cases. There is high chance that you are running Leopard on Intel Mac (x86). So you need to amend this file: /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/Makefile. You need to remove 3 occurrences of ‘-arch ppc’ to build smoothly (or leave it to try your luck):

[cc lang=”bash”]
cp /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/Makefile /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/Makefile.BAK
sudo sed -e ‘/-arch ppc//g’ /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/Makefile.BAK > /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/config/Makefile
[/cc]

7. Install PIL

Now you are ready to download PIL. There is a bit of configuration involved but you can do it quickly. Grab latest stable PIL source package from http://www.pythonware.com/products/pil/.

[cc lang=”bash”]
curl -L -C – -O http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
tar zxvf Imaging-1.1.7.tar.gz
cd Imaging-1.1.7
emacs setup.py
[/cc]

Replace the following chunk with the one below:

[cc lang=”python”]
TCL_ROOT = None
JPEG_ROOT = None
ZLIB_ROOT = None
TIFF_ROOT = None
FREETYPE_ROOT = None
LCMS_ROOT = None
[/cc]

[cc lang=”python”]
TCL_ROOT = None
JPEG_ROOT = libinclude(‘/usr/local’)
ZLIB_ROOT = libinclude(‘/usr/local’)
TIFF_ROOT = libinclude(‘/usr/local’)
FREETYPE_ROOT = libinclude(‘/usr/local’)
LCMS_ROOT = None
[/cc]

Save and close the emacs and run the commands:

[cc lang=”bash”]
sudo python2.6 setup.py install

sudo python2.5 setup.py install
[/cc]

Congrats! Now you have the latest PIL installed for both Python 2.5 and 2.6.

8. Test PIL for fun 😀

You can test your PIL by following this awesome tutorial written by a very beautiful Python engineer: http://nadiana.com/pil-tutorial-basic-advanced-drawing.

Enable caching for WordPress on Apache

I’m running WordPress on Apache. I enabled 2 level caching: at Apache level for static media (css, js, images) and at WP level for dynamic data. Here how the things are done:

1. Apache

This part is a bit tricky. You need to install and enable mod_expires and then update .htaccess file at the top folder of WP blog.

mod_expires comes with your regular Apache 2.0 and 2.2 installation.

  • Enable with “sudo a2enmod expires”
  • Restart apache with “sudo /etc/init.d/apache2 restart” or “sudo apache2ctl restart”
  • Open your .htaccess at the top folder of WP blog folder and append to the end of the file the following part (make sure you remove extra spaces after < and before > for Apache directives):

[cc lang=”apache”]

< IfModule mod_expires.c >
ExpiresActive on
ExpiresDefault “access plus 1 month”
ExpiresByType image/png “access plus 1 month”
ExpiresByType image/gif “access plus 1 month”
ExpiresByType image/jpeg “access plus 1 month”
ExpiresByType image/bmp “access plus 1 month”

ExpiresByType text/css “access plus 1 month”

ExpiresByType text/js “access plus 1 month”

AddType image/vnd.microsoft.icon .ico
ExpiresByType image/vnd.microsoft.icon “access plus 3 months”
< /IfModule >

[/cc]

Read more on mod_expires at http://httpd.apache.org/docs/1.3/mod/mod_expires.html and http://httpd.apache.org/docs/2.0/mod/mod_expires.html.

2. WordPress

WP Super Cache plug-in doesn’t give me much clue how things work and it’s rather complicated. I installed WP-Cache instead. Pretty simple.

Here are the results after enabling caching:

Code highlighting on WordPress

I was seeking a code highlighter. I found some great ones but those are not compatible with WP 2.9.2. Users always must make trade off: Security + Usability of the blog engine back-end (either to upgrade) or usability of the front-end and compatibility with old plug-ins & themes (keep the old version). Since it’s my fresh install, I’d prefer to go for the latest WP 2.9.2 and I was happy with it’s back-end. The tricky part comes when I want to add code highlighting. The highlighters on the top of this page make me drool: http://speckyboy.com/2009/02/19/12-wordpress-plugins-to-display-and-highlight-code-within-your-blog/. Unfortunately they are not compatible. I searched around and found a quite decent one: http://wordpress.org/extend/plugins/codecolorer/. Let’s test it here:

[cc lang=”php”]
phpinfo();
[/cc]

[cc lang=”php”]
class PriceFetcher()
{
function __construct()
{
}

function __destruct()
{
}
}
[/cc]

Yes, I know, space is being eaten and without spaces, the code looks quite boring. Trying other alternatives for now. This one is simple but not yet perfect.

Keeping Leopard slim

My MacBook was shipped with Tiger and then I upgraded to Leopard. Both of them were too fat: 15GB or more.

The default set up installs all printer drivers and languages as they don’t know my (and yours too) specific needs. So I ended up wasting space for those languages that I wish I knew. This time, when I put in my install DVD, I removed all languages and drivers (English is the default so you can’t remove). Surprisingly, it took me only 6.1GB to do full installation, instead of 15GB+ (I saved ~9GB man)! If you have DVD with you, plug it in, navigate to Optional Installs, run it and un-check those unnecessary languages and printer drivers. And you are done, your Leopard now is very slim.

Installing Vietnamese Input on Mac (Leopard + Tiger)

One of my top priorities when installing a system is to make it home by installing Vietnamese input and fonts. There are a few options to install Vietnamese input. I got accustomed to Telex input style so I’ll cover it here. Screenshots were taken from Leopard but installing on Tiger is the same. Here are the steps:

  1. Download from Vietnamese-2.0.1.dmg (or any later version available) http://homepage.mac.com/herr/
  2. Do normal installation (see attached screenshots)
  3. Log out as shown on the screenshot
  4. Log in and go to System Preferences, Click on International
  5. And then choose the Right-most tab “Input Menu”
  6. Scroll down and find “Vietnamese Telex”, tick it
  7. Close the System Preferences
  8. From the menu bar, choose Vietnamese and enjoy typying:

Xin chào các bạn. Gõ tiếng Việt thật là thích phải không 😀 ?


Back to blogging on WordPress engine :)

For customizable & self-hosted blogging, WordPress is one of the best engines. So I’m coming back to WordPress. Must say that WP 2.9.2 is great improvement since 2.5 that I used 2 years ago. Installing Themese and Plug-ins was never as simple as now. Dashboard rocks, and tastes much better than the front-end default theme! After seeking around themes, I chose “Vermillon” by http://www.my-tapestry.com/. Caching is enabled via WP-Cache. Seeking plug-ins for code highlight.