[Web4lib] Amazon image function

Cloutman, David DCloutman at co.marin.ca.us
Wed Jan 30 14:32:31 EST 2008


I think the better option is to do this on the server side. Between
curl, which will give you the ability to test the response status and
mime-type, and GD, which can tell you the size of the image, you can
code logic to output an img tag pointing to the placeholder image if
needed. This has the advantages of not passing extra data to the client,
not requiring JavaScript to be enabled (unless you have decided that
JavaScript is an absolute requirement for your application), and of
course not having to test debug more JavaScript. :)

Just my opinion. 

- David

---
David Cloutman <dcloutman at co.marin.ca.us>
Electronic Services Librarian
Marin County Free Library 

-----Original Message-----
From: web4lib-bounces at webjunction.org
[mailto:web4lib-bounces at webjunction.org] On Behalf Of Tim Spalding
Sent: Wednesday, January 30, 2008 11:09 AM
To: Walker, David
Cc: web4lib at webjunction.org
Subject: Re: [Web4lib] Amazon image function


You can do an onload on the img tag, and then test the size of the
resulting
image. So:
1. Try to load Amazon image
2. Image is 1x1
3. Javascript changes src to a default image of your choosing.

We did that for a while on LibraryThing, but we often had so many images
that it was running this stuff hundreds of times. Now we try to remember
if
Amazon has an image or not. But we don't store the image. Free
bandwidth?
Okay!

T

On 1/30/08, Walker, David <dwalker at calstate.edu> wrote:
>
> Glen, et al.,
>
> It seems to me that the advantage of querying Amazon to see if there
is a
> book jacket would be to put in place some type of dummy 'no image
available'
> image in the event Amazon doesn't have one.
>
> But if you're not going to do that, you could save yourself a lot of
extra
> work and potential problems by simply hard coding the image HTML into
the
> page like this:
>
> <img src="http://images.amazon.com/images/P/$isbn.01.THUMBZZZ.jpg" />
>
> If Amazon doesn't have a jacket for that book, it simply returns a
blank
> image, which your users won't see.  Ultimately, that's not all that
> different from what you have in your code now, and a lot less work.
>
> --Dave
>
> -------------------
> David Walker
> Library Web Services Manager
> California State University
> http://xerxes.calstate.edu
>
> ________________________________
>
> From: web4lib-bounces at webjunction.org on behalf of Glen Wiley
> Sent: Tue 1/29/2008 1:39 PM
> To: web4lib at webjunction.org
> Subject: [Web4lib] Amazon image function
>
>
>
> Hi everyone,
>
> I know people have discussed Amazon book images issues on this
listserv
> before, but here is a more technical question.
>
> I'm using this php code to pull Amazon book cover images into a new
book
> list.  It does work, but I wondered if anyone had a suggestion about
how
> to do it better.  We aren't getting very many successful image
displays
> because many of them time out or error out.  So out of 100 new books,
I
> get 10 images appear.  Any suggestions here?
>
> function RESTQuery($isbn){
>    //1VE157GS2Z7SMVS61G02
>    $base         = 'http://ecs.amazonaws.com/onca/xml';
>    $query_string = '';
>
>    $params = array(
>        'ItemId' => "$isbn",
>        'IdType' => "ASIN",
>        'Service' => 'AWSECommerceService',
>        'Operation' => 'ItemLookup',
>        #'SearchIndex' => 'Books',
>        #'sort'  => '+relevance',
>        'ResponseGroup'  => 'Images',
>        'AWSAccessKeyId' => '1VE157GS2Z7SMVS61G02',
>        'Style' =>    "XML",
>        'XMLEscaping' => "Double",
>        'Version'    => "2007-07-16"
>    );
>
>    foreach ($params as $key => $value) {
>        $query_string .= "$key=" . urlencode($value) . "&";
>    }
>
>    $url = "$base?$query_string";
>
>    $xmlstr = file_get_contents($url);
>    if($xmlstr == "") return;
>    $xml = new SimpleXMLElement($xmlstr);
>    #return $xml->asXml();
>    $imageURL = $xml->Items->Item->MediumImage->URL;
>
>    if($imageURL != ""){
>        return "<a href=\"http://www.amazon.com\"><img
src=\"$imageURL\"
> /></a>";
>    }
>    else{
>        return "";
>    }
> }
>
>
> --Glen
>
>
>
>
------------------------------------------------------------------------
>
> Glen Wiley
> Metadata Librarian
>
> Metadata Services <http://metadata.library.cornell.edu/>
>
> 107E Olin Library
> Cornell University
> Ithaca, NY 14853/
> /gsw55 at cornell.edu <mailto:gsw55 at cornell.edu>
> 607-254-5145
>
>
> --/ Our Vision is to be internationally recognized and respected as a
> center of metadata expertise. --/
>
>
>
> _______________________________________________
> Web4lib mailing list
> Web4lib at webjunction.org
> http://lists.webjunction.org/web4lib/
>
> _______________________________________________
> Web4lib mailing list
> Web4lib at webjunction.org
> http://lists.webjunction.org/web4lib/
>



-- 
Check out my library at http://www.librarything.com/profile/timspalding
_______________________________________________
Web4lib mailing list
Web4lib at webjunction.org
http://lists.webjunction.org/web4lib/

Email Disclaimer: http://www.co.marin.ca.us/nav/misc/EmailDisclaimer.cfm



More information about the Web4lib mailing list