Thursday, March 3, 2011

Thumbnail images and php

Ever since I found out that photographs from my digital camera contain extra information, I have been trying to figure out how to exploit it. I like the idea of information about an image being contained in the image. In particular, the actual date that a photograph is taken is often lost when I am copying and cleaning up. Sometimes the creation date is the date that I copied it from the camera. For example, my last trip to Colorado resulted in lots of landscape images. I had to label one of them "notsure.jpg" because somehow, in my sorting, it lost its connection with the others. But I can find the "date taken" and its nearest neighbors in time will help me find its location.

Creating a thumbnail from the EXIF data (using exif_thumbnail()) caused a black bar to appear above and below my image.This I could not live with. After an hour or two of intense searching, I found some alternatives but I could not get the image to be displayed. Mostly, the name of the file would appear in its place (in Firebug, one can see that this is the alt value for the image).

By google'ing the word "gibberish", I found the answer. (By gibberish, I mean that the code was printing out the image in text format rather than a nice photo.) Responses to the questioners spoke about the header, white space and separate files. The following code produces a smaller image than the original if I call it from another php file. The only thing I need to figure out now is how to make the name of the file a variable for input.

header('Content-type: image/jpeg');
$image = new Imagick('landscape_gallery/skyline_drive/tr_valley5.jpg');
$image->thumbnailImage(100, 0);
echo $image;
?>

Just found this working example for image gallery. I am sure I was at this website yesterday but I did not understand the goal of the code. When the code is activated ( I have an href link from another file), it creates a file structure in the directory in which it is physically located, including an html file and subdirectory with thumbnails. ONLY AFTER this is done, can I go back and open the html file and display the images. These display the original image (on a new page) when clicked. Since I know what the name of the html file is, I can hard code the link to it (even if its contents are different).

No comments:

Post a Comment