« Date Night | Main | In Search of Pepsi iTunes »

New Pictures

I have some new twins pictures uploaded! Only 2 weeks late.

The batch of pictures is momentous because I was able to use my new Applescript method I mentioned to get the pictures up on my website. Read on to hear all the technical and gory details.

For those who can't wait, here is the Applescript program I developed to do this for me:
Send Pictures to robreid.com.txt

OK. So what I wanted to do is to develop a process that would automate uploading pictures from iPhoto to my website. I had developed a convoluted PHP program that parses the HTML code that iPhoto creates when exporting web pages. This was OK, but since I have all my pictures data stored in a MySQL database, I didn't need the HTML code anymore - it was just known source of the data I wanted (shutter speed, picture title, etc.) to get into my database.

So instead of all that, it would be great just to get the data I need directly from iPhoto, upload the pictures, and insert the data into the MySQL database. There would be no useless HTML picture pages floating around my website with their own subfolders to store the pictures, thumbnails, and HTML pages. This would be much cleaner.

The problem was that the only tool that could get the picture data from iPhoto, Applescript, could not do everything I wanted. The steps I needed to happen were:

  1. Take the selected photos from iPhoto
  2. Resize them to a standard size
  3. Create a thumbnail image
  4. Get the picture data including title, comments, date, and technical camera details
  5. Upload the pictures and thumbnails to my website
  6. Insert the picture data into my MySQL database
Applescript could only do (1), (4), and (5) for me, and I had to use Applescript to get at the iPhoto pictures easily.

Suddenly, though, I realized that Mac OS X has a UNIX command line built into it, and that I can run UNIX script from Applescript! So, I just needed to find some UNIX tools to perform the remaining steps for me.

I had already installed ImageMagik on my computer, since Movable Type uses it to create its thumbnail images when upoading photos. I could use this to create the resized main image as well as the small thumbnail image.

I thought I could get at the EXIF data via Applescript from iPhoto, but I did not have much success with this. Instead, I used the jhead UNIX tool to get that data directly from the picture file. This worked well, but I had to write an Applescript function to parse the text the jhead command returned.

The only thing I did not find a way to directly automate was the insertion of data into my web-located MySQL database. I use phpMyAdmin to work with my database, and I couldn't determine how to send it SQL commands automatically. That's OK. I had Applescript create the insert statements and place them on the clipboard, so all I have to do is paste it into the web form and voila!

So here's the steps now:

  1. Take the selected photos from iPhoto using the native iPhoto/Applescript integration
  2. Save 2 copies of each selected picture to a temporary area on my hard drive via the UNIX "cp" command
  3. Resize 1 of them to a standard size (800 max width or height) via ImageMagik's "mogrify" command
  4. Create a thumbnail image, again with ImageMagik's "mogrify" command
  5. Get the picture data including title, comments, date, and technical camera details via Photo/Applescript (for the title, comments, and date) and jhead (everything else)
  6. Upload the pictures and thumbnails to my website using the UNIX FTP command
  7. Insert the picture data into my MySQL database, a manual process but Applescript pulls up the phpMyAdmin page for me and supplied the insert command in the clipboard, so I just have to paste them into the web form

There are lots of little details that the Applescript process handles, but that's always the case with this sort of programming. Knowing that I had tools that could do it all, it was just working thorough all those details before I could get it to work. And this most recent batch of pictures was my pilot case to work out the bugs.

Ultimately, it worked. It's biggest problem is speed. It takes about 30 seconds per picture to do all the copying, resizing, and uploading. That's acceptable to me, though, since I can just start it going and walk away. I can come back in 10 minutes or so to complete the final manual step.

All this work was intended to make it easier and quicker for me to upload photos to my web site. Now the biggest hurdle is actually titling and commenting on the photos in iPhoto. The technical aspects of getting the pictures up to my website are now reduced to nearly a one-click process. We'll see if this really does help me post pictures faster.

About

This page contains a single entry from the blog posted on March 14, 2004 11:34 AM.

The previous post in this blog was Date Night.

The next post in this blog is In Search of Pepsi iTunes.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33