Monday 15 March 2010

Websiting

This morning I converted the Crocus and Snowdrop photos I took yesterday, then uploaded a couple of okay ones to my photo website. I added them to this weeks Macro thread in the dpreview Canon lens forum.

At the moment the way I upload photos to my photo website is one at a time through a web form, and upload the full size original JPEGs. The server then gets the metadata and stores it in the database, and makes resized and sharpened versions of the image for displaying on the website.

This way of working is very slow, and the sharpening algorithm used on the web server is just a simple USM. So I thought it would be better if I could resize the images in Photoshop and sharpen them using Smart Sharpen, then upload these to the server. This would be much quicker than uploading the full size original images, and Photoshop's Smart Sharpen should give better image quality than ImageMagick's USM.

So I started modifying my upload processing script so that it could be used in a loop running through a directory of images instead of just processing the one image as it does currently. After modifying the script a bit, I thought I should get the local copy of my website up to date, so I synced the image folders on my local website to the folders on the live website, and also deleted the local database, then added a copy of the database from the live website.

The images took quite a long time to download, so while I was waiting I read a bit about scripting Photoshop. Since I need to resize images based on their longest side e.g. I want portrait orientated images to be 720px high, but landscape orientated images to be 720px wide, this means I can't use a simple Photoshop action since the action can't tell the orientation of the image, and so I'll have to use scripting instead.

When the images had finished downloading, I tried out my updated upload script for uploading a single file via the web form, but it didn't work. I tried to find out what the problem was, and in the process found my error logs for the static subdomains seemed to be full of info about files being gzipped, and it didn't seem to have anything to do with any error. Looking into this, I found it was because I had set the error log level as debug. So I removed debug from the error log directive of all my site configs in my local environment and on the web server.

After lunch I managed to fix the problems with my updated single image upload script, and so started to work on the directory processing script. However, after writing a few lines of it I realised that uploading the images already processed and resized by Photoshop wouldn't be that great, as I wouldn't be able to get the info about the original image like its size and color space.

So I think for the moment I'm going to have to continue to upload the full size images, and process them with ImageMagick on the web server. (Well, I guess I could do the resizing in Photoshop, and then upload the originals and resized images, but that would make the upload process even slower). I'll still try and work on a script that will process a directory though, since FTPing the images to a directory, then running a process script should still be much faster than uploading the images individually though a web form.

I wrote this blog post so far, then carried on with my batch process script.

I first had problems that turned out to be because when you use scandir in PHP, the first two entries are . and .. (so you have to use unshift to get rid of the first two entries, so you're left with an array of the actual files in the directory.

Then I had some trouble with not being able to extract the metadata from a file. Eventually I found that the problem was due to using single quotes, it seems that you can't escape characters inside single quotes in the bash shell. It took me quite a long time to work out that that was what the problem was. So the solution is to use double quotes instead and escape any double quotes in the quoted string:
djeyewater@rusty-ubuntu:~$ echo \'abc\'
'abc'
djeyewater@rusty-ubuntu:~$ echo 'ab\'c'
> '
ab\c

djeyewater@rusty-ubuntu:~$ echo "ab\"c"
ab"c
djeyewater@rusty-ubuntu:~$ echo 'ab'c'
> '
abc


After dinner I watched an episode of Star Trek TOS and Waterworld with Mauser and L.

The weather was sunny all morning then overcast most of the afternoon.

Food
Breakfast: Strawberry Jam Toast Sandwich; Cup o' Tea.
Lunch: Roast Chicken with Mayonnaise and sliced Cherry Tomatoes Sandwich; Slice of Angel Cake; Banana; Cup o' Tea; 6x pieces of Aero.
Dinner: Slice of Bacon Quiche; Potatoes; Peas. Pudding was a Home-made Chocolate Caramel centered Muffin. Coffee; 5x pieces of Aero.

No comments: