Grabbing Images
-
-
Hey,
Simple and possibly stupid question... just wondering about grabbing images from entries in Freebase. I couldn't find any examples in the API documentation, but most articles now tend to have either a user-uploaded thumbnail, or a scrape of the equivalent Wikipedia article's image.
So does anyone have experience pulling images into your own apps and/or have an example of how to do so?
(Sorry if this has been answered before but I couldn't find anything...)
-
Check out the Metaweb Application Reference Guide and follow the link to §4.8, “Fetching Content with trans” in the Metaweb Read Services chapter.
-
I recently did this, and also, just fixed a bug in my program this morning. The bug happened because the code I copied from did not gracefully handle cases of multiple images. (Alas, I'm really just gluing together things without a lot of "understanding" and so these kinds of problems are happening to me a lot!)
Maybe this will help:
var query = { // This is our MQL query
type: "/music/artist", // Find a band
name: bandName, // With the specified name
id: null, // Fetch the ID of the band to link to their Freebase page
album: [{ // We want to know about albums
"/common/topic/image" : [{ // the images list on the album
"id" : null, // each image has an ID
"optional" : true // don't require an image to return a result
}]
};Once your query comes back, you should have a list of 0 or more images in the "/common/topic/image" field. Each image will have an ID. You can then pass that ID to Freebase's thumbnail API to generate a version of that image at any size you like:
http://www.freebase.com/view/guid/9202a8c04000641f8000000006cf560a
I'm not quite sure
-
At first glance, that query looks correct. You can test it out by throwing it into the queryeditor and testing it out.
-
Ooops, the "I'm not quite sure" was an accident, must have been scrolled off the bottom. I'm sure that's the query. :)
What I wasn't exactly sure about was how to get the dimensions of the original image, but I'm sure it's in there somewhere!!
-
/api/trans/image_thumb can return you the image in a specified height/width, but won't tell you anything about the original size. In your query, you can ask for the /common/image/size, which is a CVT that has the x/y sizes.
-