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).

Wednesday, March 2, 2011

Natural selection

I have never been a good theorist. I can't read a book and then apply its principles to a problem that I am trying to solve. I am more like nature, I try many different applications before the one that solves my problem makes it into my program. Sometimes I take parts of one application and add it to another. Sometimes I create a new one consisting mostly of spare parts. I guess you could call me a junkyard mechanic.

Is this an efficient way to work? A hundred years ago it would not be. But the internet and contributions of many people offer a smorgasbord of options and solutions. Some patience and a good internet  connection are all I need.

This is just a collection of the bookmarks I created just this week. I am truly grateful to the people who publish their work for all to see.
What am I trying to do? I am working on a web travel journal. I want to display images and add tags to the metadata (exif). I also use a camera set to Dutch time and need to change the dates on the photographs to the location time. This needs html, php, xml and javascript. CSS will provide the finishing touches. I also want to create a family ancestry website, for which I'll need to create metadata for scanned photographs. Stay tuned.

    Thursday, February 17, 2011

    Mail in PhP

    I have started and stopped working with PhP several times. Security and mail were my reasons. Today I actually got the sample code for w3schools working. In particular, the code with the form in it with the action mailform.php.  I searched and I searched, looking for this code called mailform.php and could not find it. Then I had an epiphany. What if the process was recursive and the file I was editing had to be called mailform.php? An hour later, after correcting errors which seemed to come out of nowhere, I got it to work.

    Independent of my discussion above, is the mail which is used by my OS. I initially used sendmail, for lack of any other ideas. I got the simple mail php code working by changing the email addresses from rose@domain to rose in the code. When I typed mail at the command line, I was able to see the message after exactly one minute.  I thought this odd and searched around and tried some other things. I reached one responder who simply said, stop using sendmail and use postfix instead. The writer sounded so sure that I  just tried it and it worked. (Alas, I cannot find the link, I had on the order of 10 tags open with the same number of google search combinations). The only problem after that was to stop the sendmail process. For some reason, my tried and true "sudo kill -9 processid" refused to work. and I had to "sudo /etc/init.d/sendmail stop". 

    On to security.

    Wednesday, February 16, 2011

    jUploadr and Flickr

    Many of my recent photographs have a resolution of 3264x1832, which is twice the size of the monitor at which I am sitting. So, I am going to use jUploadr preferences to limit the size of the longest edge to 400 or so pixels. Here is a sample at 100 percent. There's a message from jUploadr that the photos are being rescaled.




    Tuesday, February 15, 2011

    Flickr

    Well, it has been a while since I have added anything to this blog. I have recently tried using php to create a travel journal for Flickr. I have recently added a serious of landscape photographs and I wanted to make some sort of php-based viewer. I got sidetracked by several irritating things that I am going to write here because I am sure that I will forget which notebook I wrote them down in (linux from scratch notebook).

    So, to start, I am working with Ubuntu 10 and apache/php.  First, I added ServerName=localhost to the httpd.conf file, to get rid of that message about "reliable determination". Then I changed all the permissions until I removed the 403 error. I ran into an odd php problem with my subdirectories, where files with the name index.php were being opened by an editor instead of in the browser. Actually, it turns out that I just had a few typos (symbols outside of html tags) that for some reason were preventing proper opening of the webpage.

    I am using  phpflickr as described by Paul Burgess in his tutorial. I am still using the 3.0 version so that I can follow the tutorial. Since I asked for an API key awhile ago, I went in search of where I might find it. (you-> your account->sharing and extending ->your API keys, at the bottom). I have two of them but will use the one associated with my landscape photos. This I put key and ID into the config.php file. I am asked to upload this, but since I am working on Apache  localhost, I should just leave it in the working directory.

    The tutorial is a bit unclear in some places, especially since I unpacked the code  a few months ago. The thing that surprised me is that the php code started at the top and the html code followed underneath. For the first tutorial, there is index.php, which calls phpflickr.php and config.php. Opening index.php in the browser produces a grid of thu http://localhost/vacation_2010/index.phpmbnail photographs. Nice. This is the address:

     http://localhost/vacation_2010/index.php

    When I click on one image, a larger image appears with  paging through the gallery, this appears in the web address window:

    http://localhost/vacation_2010/photo.php?id=5416188716

    I think that I will have to scale the images because they are quite large. But this is already a nice success.

    Made by index.php
    Made by photo.php

    Tuesday, June 15, 2010

    Dutch PhP

     Conference 10 - 12 June 2010 Amsterdam

    I won a ticket to the Dutch PhP conference from the PhP Women forum. This was my first time at a coding language conference. I've been to a few linux and open source conferences, as well as meteorological conferences (when I was working).  My first impression of the PhP talks is that they had a lot of text. It's the first conference where I ever saw code up on a screen.

    I attended 10 out of 30 talks, plus the two keynotes. Some presented text with nice photograph backgrounds.  Those with diagrams included Geographical PhP, Cairo and web services for mobile devices (a device which measured temperature and was able to upload the results to the web).

    Speakers interacted very well with the audiences. Almost all used audience answers in their discussion. 

    Talks which I attended, along with my scribbled notes which consisted mostly of words and acronyms that I needed to look up and web sites to visit:
    • Derick Rethans talk, reusable software: singleton, multiple inheritance, traits, refactoring, Active Record, joelonsoftware.
    • Rob Allen Zend Forms: akrabat.com
    • Michael MacLean: Cairo. Demonstrations of code output, not cheesy at all. very instructive and clear about what is being done. Look up what PECL means.
    • Harrie Verveer: Database version control, "Never modify patch files once  under version control", sql,phing,dbdeploy.com, liquibase (java), xml(good documentation), zend akrabat.,github.com,doctrine, layer between app and db, yaml,update-to_version
    • Melanie R. Lewis: STBs, midp,gprs,3g, xml parsers, binary data MIME/ASCII, Servers: XML-RPC, SOAP,JSON-RPC,RESI (mechanism not protocol?), iOS, Android, Restful services, ping API, security, does not use session, challenge response, temperature data uploaded to web server, binary data.
    • Thorsten Rinne, Agile PhP Software development.Concept of paired programmers. I am myself a solitary programmer and would find it odd to have someone next to me checking my work and vice versa.
    • Sebastion Schuermann: Web services, php and nodes.js.
    • Marcus Deglos: PhP and Geolocation. Nice talk,lots of illustrative pictures. Coming from satellite data analysis background, I was familiar with the topic.
    • Ian Barber: Site Searching, Swish-e, Apache Lucene, Solr, Xapian.
    • Sebastion Bergmann, reviewing PhP code. Interesting debugging techniques by studying text statistics of code. Over the shoulder code checking. 

    Introduction

    I have begun studying PhP programming many times. My first attempt ended because PhP is a server side program, which means one needs to upload the code to a server in order to visualize it in a browser. My server at the time was way to slow to use for testing. So, I decided to install Apache on my linux box.  I have installed and uninstalled Apache many times, even on Windows XP.  But it eventually worked and I was even able to display some PhP, something akin to calling the operator for date and time.


    date_default_timezone_set('Europe/Amsterdam');
    echo '
    Today is ',date('l'),', The current time is ',date('H

    :i ') ;
    '.
    ' ;
    ?>

    Which produces: Today is Tuesday, The current time is 15:21

    A lot of the references about php are associated with the  mysql database. PhPmyAdmin is the most common, and involves a lot of security features which I found very annoying because I did not understand them. But this all had to do with the database and not php.

    Anyway, I plan to pursue my php learning a bit more vigorously since I just returned from the Dutch PhP Conference last weekend. I put my observations and notes in a separate entry.