Archive for the 'Tips and Tricks' Category

Quick Update on installing ImageMagick on OS X

I’ve updated the tutorial on how to install ImageMagick from source on OS X, with links to the latest libraries and commands updated to reflect some changes for Leopard.

Trick your computer into finding web sites on other servers

Quite often I’ve dealt with moving sites from one hosting situation to another. One issue that comes up is checking to make sure the site works on the new server, but you can’t check it because the domain is still pointing to the old server. Most clients are not okay with just waiting until the DNS switches over to the new server before finding out if their site is broken or not, so what to do? It turns out you can trick your computer into thinking the site really does live on the new server, so you can check it and verify everything is working correctly. Here’s how.

Whether you are on Windows, Linux or OS X, you can tell your computer to look for web sites at alternate IP addresses regardless of what DNS servers tell it. There is a hosts file that you can modify to do just that.

On Linux and OS X, this file is /etc/hosts, while on Windows it is the C:\WINDOWS\system32\drivers\etc\hosts file. The format is the same on both platforms, so you can use this trick no matter what OS you use. Here is the default one from OS X:

  ##
  # Host Database
  #
  # localhost is used to configure the loopback interface
  # when the system is booting.  Do not change this entry.
  ##
  127.0.0.1       localhost
  255.255.255.255 broadcasthost
  ::1             localhost

The setup is pretty simple. Enter the IP that you want your computer to point to, with the domain name you want it to use. So if you are in the process of moving www.clientwebsite.com from Dreamhost to Bluehost, then you’d find out the IP of the new server at Bluehost and enter at the end of the file like so:

  123.123.123.123 www.clientwebsite.com

Now clear out the DNS cache on your computer to make sure you’re not viewing the site from your DNS cache. On windows, open up the command line and type ipconfig /flushdns. In OS X, open up Terminal and type lookupd -flushcache. I also recommend clearing your browser cache.

Open up your browser and go to the web site you just entered in the hosts file. It should now point to the new server. If not, make sure you remembered to flush your DNS cache.

Now you can save yourself some trouble with moving sites and make sure they work before you switch them over. Your clients will be happy, and more importantly you’ll have peace of mind that you won’t be getting calls from panicking clients that their site is broken.

Install ImageMagick from source on OS X Tiger (and Leopard)

Update Feb. 10, 2008: I’ve tested and verified this also works on OS X Leopard. An additional command was needed to make the JPEG library install without errors, noted below. I’ve also updated the commands outlined below for the latest versions of the software.

If you’re like me and use mini_magick or (or RMagick) Ruby gems on OS X for building Rails apps, installing ImageMagick can be a pain. There is a universal binary package which works alright, but I prefer to build apps from source when possible. Also, I run a few web sites on my G5 Power Mac and I want ImageMagick to be compiled specifically for the PowerPC platform, which will get me a bit of an advantage in speed and reliability. I ran into a few roadblocks while getting it all compiled and installed, so I thought I’d share how I did it.

First off, I should mention that I only added in JPEG and PNG support for ImageMagick, so if you need more formats supported, this article doesn’t cover it. You’ll also need the OS X Developer Tools installed on your system. Finally, I did this on the latest version of OS X (Tiger 10.4.9) for PowerPC and Intel Macs. Both tested working. Update: Also tested on OS X Leopard on Intel.

Here is a list of packages you’ll need to download. Get all of these and place them in one directory.

Once you’re done downloading, open the Terminal app and go to the folder you downloaded the files to. For example if you downloaded them do your Desktop, type the following in the command line and hit enter:

  cd Desktop

Step One: Compile and Install JPEG Libraries

Installing the JPEG libraries is actually the trickiest part of the install. By default on OS X building and installing the JPEG libraries won’t install any libraries at all, only some binaries that allow you to manipulate JPEG files.

Update: I also discovered while installing the JPEG library on Leopard that it needs the /usr/local/man/man1 directory to install without errors. I added the command below to create it.

So here’s the magic to force it to install JPEG libraries that ImageMagick will use while compiling:

  tar zxvf jpegsrc.v6b.tar.gz
  cd jpeg-6b
  cp /usr/share/libtool/config.sub .
  cp /usr/share/libtool/config.guess .
  sudo mkdir -p /usr/local/man/man1
  ./configure --enable-shared --enable-static
  make
  sudo make install
  sudo ranlib /usr/local/lib/libjpeg.a
  cd ../

Done! You shouldn’t have gotten any errors. If you did, then make sure you definitely have the OS X Developer Tools installed.

Step Two: Compile and Install LibPNG

This is pretty straightforward, and doesn’t require any weird tricks to get it to work.

  tar zxf libpng-1.2.24.tar.gz
  cd libpng-1.2.24
  ./configure
  make
  sudo make install
  cd ../

Step Three: Compile and Install ImageMagick

This is pretty simple too. We don’t have to pass any special options to ImageMagick either. It should automatically pick up that we have JPEG and PNG libraries installed and compile in support automatically.

  tar zxf ImageMagick.tar.gz
  cd ImageMagick-6.3.8/
  ./configure

After ./configure is done, you should check to make sure the following lines are present in the output that indicated JPEG and PNG support are in there:

  JPEG v1           --with-jpeg=yes               yes
  PNG               --with-png=yes                yes

If those are both set to yes, then you’re golden. Now finish him!

  make
  sudo make install

You now have ImageMagick install from source on OS X Tiger. Now you can use mini_magick or RMagick Ruby gems in your apps. If you found this useful or have any questions, leave me a comment below.

Validate all your HTML from a Google Sitemap

I was put in charge of going through an entire site to validate every HTML page, and the first thing I thought of was “how do I automate this?”. I noticed they had a Google sitemap, which makes it easier for Google to find and index content on a web site. Immediately I realized I could write a script to parse the sitemap file and go out and validate each page at the W3C Validator. As usual, someone has already thought about it and made a pretty web interface for it. Check out the Google Sitemap HTML Validator Tool that will open your Google sitemap and validate each page it finds and report the errors back to you. I love the Internet!

Google Maps + IE PNG Hack + IE 7 = Maps Asplode

Yesterday I went to show someone Unthirsty on their home PC. Of course their PC was riddled with malware and ran like a 3-legged dog. I groaned when I saw the IE7 icon on their desktop. I had tested the site a bunch of times in IE 6, but when I saw the IE7 icon I realized I had never tested it with Unthirsty. Reluctantly I opened it and typed in unthirsty.com in the address bar…and can you guess what happens next? The map comes up on the page completely blank. Why is it whenever you go to show someone a site you’re proud of, it doesn’t work?

Originally in Unthirsty I added in a great Javascript hack that makes transparent PNGs work in IE6. This worked great in IE 6, but as you now know, it caused some problems in IE7 when using Google Maps, causing the map to be blank upon loading. If I switched to satellite view it worked, then back to the regular view, the map corrected itself. But obviously that’s not the solution I wanted. So I changed this:

  <!--[if gte IE 5.5]>
  <script type="text/javascript" src="/lib/pngfix.js"></script>
  <![endif]-->

To this:

  <!--[if lt IE 7]>
  <script type="text/javascript" src="/lib/pngfix.js"></script>
  <![endif]-->

If you’re not familiar with the weird if gte IE 5.5, it’s Microsoft’s way of letting you tell versions of Internet Explorer to use what’s in between those comment blocks. Here I’m telling it to include the pngfix.js file if the version of IE is greater or equal to 5.5. Since this also includes IE7, I changed it to include it if the IE version is less than 7. Problem solved.

I hope this helps someone that is having the same problem, but at the same time this should be a wake up call to a lot of developers out there. CHECK YOUR SITES IN INTERNET EXPLORER 7! Especially if you made any hacks to accomodate IE 6 flaws.