I am trying to get by media API query the url of thumbnail, image and description for all images in the following category web page: http://commons.wikimedia.org/wiki/Category:Coins_in_the_Walters_Art_Museum
I tried the following query:
http://commons.wikimedia.org/w/api.php?format=xml&action=query&list=...
which produced an XML output which gave me all the Image file names. With a file name I am able to construct the url for this file.
For example with "File:Ethiopian - Coin Depicting an Anonymous King - Walters 59793 - Reverse.jpg"
I am able to construct the URL for the image as http://commons.wikimedia.org/wiki/File:Ethiopian_-_Coin_Depicting_an_Anonymo....
However I would like to get the thumbnail url, Title and the description for the images in this category with a query and get the output in XML or JSON format . Is it possible to construct such a query? Thanks. The XML output is given below:
<?xml version="1.0"?> -<api>-<query>-<categorymembers><cm title="File:Ethiopian - Coin Depicting an Anonymous King - Walters 59793 - Obverse.jpg" ns="6" pageid="18842729"/><cm title="File:Ethiopian - Coin Depicting an Anonymous King - Walters 59793 - Reverse.jpg" ns="6" pageid="18842732"/><cm title="File:Ethiopian - One of Two Coins Depicting Ousanas and an Anonymous King - Walters 59794.jpg" ns="6" pageid="18809697"/><cm title="File:Greek - Apollo - Walters 59533.jpg" ns="6" pageid="18787772"/><cm title="File:Greek - Athena - Walters 59519 - Obverse.jpg" ns="6" pageid="18801612"/><cm title="File:Greek - Athena - Walters 59519 - Reverse.jpg" ns="6" pageid="18801616"/><cm title="File:Greek - Athena - Walters 59702 - Back.jpg" ns="6" pageid="18787788"/><cm title="File:Greek - Persephone - Walters 59693.jpg" ns="6" pageid="18787786"/><cm title="File:Greek - Tetradrachme with King Nicodemus II - Walters 59723 - Back.jpg" ns="6" pageid="18787795"/><cm title="File:Matthes Gebel - Medal of Arnold and Nicholas Wenck - Walters 59480 - Obverse.jpg" ns="6" pageid="18839416"/></categorymembers></query>-<query-continue><categorymembers cmcontinue="file|7e524f4d414e202d20434f494e2057495448204120484950504f504f54414d555320414e4420504f525452414954204f46204f544143494c494120534556455241202d2057414c54455253203539373531202d204241434b2e4a50470a524f4d414e202d20434f494e2057495448204120484950504f504f54414d555320414e4420504f525452414954204f46204f544143494c494120534556455241202d2057414c54455253203539373531202d204241434b2e4a5047|18787799"/></query-continue></api>
-- View this message in context: http://wikimedia.7.n6.nabble.com/Api-Query-for-thumbnail-images-title-etc-in... Sent from the WikiMedia Commons mailing list archive at Nabble.com.
Hi vjkumar,
On 06-Sep-2012, at 6:57 PM, vjkumar wrote:
I am able to construct the URL for the image as http://commons.wikimedia.org/wiki/File:Ethiopian_-_Coin_Depicting_an_Anonymo....
However I would like to get the thumbnail url, Title and the description for the images in this category with a query and get the output in XML or JSON format . Is it possible to construct such a query?
Yup! You need to use the 'imageinfo' API call (documentation available at http://www.mediawiki.org/wiki/API:Properties#imageinfo_.2F_ii). Try this URL: http://commons.wikimedia.org/w/api.php?action=query&titles=File:Ethiopia... (here's the tinyurl: http://tinyurl.com/8tgdjoc)
You can adjust iiurlwidth to the width of the thumbnail you need. This will give you the thumbnail URL and title in the XML it emits; to get the description, you will need to read the page content itself, via a http://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv request (e.g. http://commons.wikimedia.org/w/api.php?action=query&prop=revisions&t...) (here's the tinyurl: http://tinyurl.com/9fbg8q4)
Hope that helps!
cheers, Gaurav (User:Gaurav)
Sorry, my question might not have been clear. When the page
http://commons.wikimedia.org/wiki/Category:Coins_in_the_Walters_Art_Museum is opened, You get a gallery of 13 thumbnails with titles and links. When I looked at the source I see 13 list items. the first list item snippet is given below. I am trying to get all 13 list items info with a single query. My query
http://commons.wikimedia.org/w/api.php?format=xml&action=query&list=...
only gives me 13 file names. I would like to get the thumbnail url and title names of all 13 coins as displayed in the gallery (and in the source li item) in 1 query. Thanks. The list item snippet for first picture in the gallery.
<li class="gallerybox" style="width: 155px"><div style="width: 155px"> <div class="thumb" style="width: 150px;"><div style="margin:15px auto;"> /wiki/File:Ethiopian_-_Coin_Depicting_an_Anonymous_King_-_Walters_59793_-_Obverse.jpg //upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Ethiopian_-_Coin_Depicting_an_Anonymous_King_-_Walters_59793_-_Obverse.jpg/120px-Ethiopian_-_Coin_Depicting_an_Anonymous_King_-_Walters_59793_-_Obverse.jpg </div></div> <div class="gallerytext"> /wiki/File:Ethiopian_-_Coin_Depicting_an_Anonymous_King_-_Walters_59793_-_Obverse.jpg Ethiopian - Coin Depic... <br /> 289 KB<br />
</div> </div></li>
-- View this message in context: http://wikimedia.7.n6.nabble.com/Api-Query-for-thumbnail-images-title-etc-in... Sent from the WikiMedia Commons mailing list archive at Nabble.com.
I don't think you can do this in a single query. You want to do one query to get the titles of all the images in the category, and then do a second query to get all the thumbnail data for those titles.
Ryan Kaldari
On 9/7/12 6:02 AM, vjkumar wrote:
Sorry, my question might not have been clear. When the page
http://commons.wikimedia.org/wiki/Category:Coins_in_the_Walters_Art_Museum is opened, You get a gallery of 13 thumbnails with titles and links. When I looked at the source I see 13 list items. the first list item snippet is given below. I am trying to get all 13 list items info with a single query. My query
http://commons.wikimedia.org/w/api.php?format=xml&action=query&list=...
only gives me 13 file names. I would like to get the thumbnail url and title names of all 13 coins as displayed in the gallery (and in the source li item) in 1 query. Thanks. The list item snippet for first picture in the gallery.
<li class="gallerybox" style="width: 155px"><div style="width: 155px"> <div class="thumb" style="width: 150px;"><div style="margin:15px auto;"> /wiki/File:Ethiopian_-_Coin_Depicting_an_Anonymous_King_-_Walters_59793_-_Obverse.jpg //upload.wikimedia.org/wikipedia/commons/thumb/a/a5/Ethiopian_-_Coin_Depicting_an_Anonymous_King_-_Walters_59793_-_Obverse.jpg/120px-Ethiopian_-_Coin_Depicting_an_Anonymous_King_-_Walters_59793_-_Obverse.jpg </div></div> <div class="gallerytext"> /wiki/File:Ethiopian_-_Coin_Depicting_an_Anonymous_King_-_Walters_59793_-_Obverse.jpg Ethiopian - Coin Depic... <br /> 289 KB<br />
</div> </div></li>
-- View this message in context: http://wikimedia.7.n6.nabble.com/Api-Query-for-thumbnail-images-title-etc-in... Sent from the WikiMedia Commons mailing list archive at Nabble.com.
Commons-l mailing list Commons-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/commons-l
I am looking for help on how to structure the second query to get the image information. Can you help by giving an example? Thanks.
-- View this message in context: http://wikimedia.7.n6.nabble.com/Api-Query-for-thumbnail-images-title-etc-in... Sent from the WikiMedia Commons mailing list archive at Nabble.com.
Here's some PHP code that might be handy for retrieving thumbnails via the API. (Consider it public domain licensed.)
/** * Retrieve an image thumbnail from the server * @param $title The title of the page, e.g. 'File:Foobar.jpg' * @param $width The maximum width for the thumbnail * @param $height The maximum height for the thumbnail * @return array **/ function imagethumb ( $title, $width, $height ) { $title = str_replace( ' ', '_', $title ); $thumb = array(); $x = $this->query( '?action=query&prop=imageinfo&format=php&iiprop=url|size&titles='.$title.'&iiurlwidth='.$width.'&iiurlheight='.$height ); foreach ( $x['query']['pages'] as $ret ) { $thumb['url'] = $ret['imageinfo'][0]['thumburl']; $thumb['width'] = $ret['imageinfo'][0]['thumbwidth']; $thumb['height'] = $ret['imageinfo'][0]['thumbheight']; $thumb['originalurl'] = $ret['imageinfo'][0]['url']; $thumb['originalwidth'] = $ret['imageinfo'][0]['width']; $thumb['originalheight'] = $ret['imageinfo'][0]['height']; } return $thumb; }
Ryan Kaldari
On 9/7/12 1:53 PM, vjkumar wrote:
I am looking for help on how to structure the second query to get the image information. Can you help by giving an example? Thanks.
-- View this message in context: http://wikimedia.7.n6.nabble.com/Api-Query-for-thumbnail-images-title-etc-in... Sent from the WikiMedia Commons mailing list archive at Nabble.com.
Commons-l mailing list Commons-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/commons-l
Ryan, Thanks a lot. I modified your query as a XML query and had good success. Let me give the query I used and the information I was able to get for reference in case some one has a similar issue.
http://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&f... - Apollo - Walters 59533.jpg&iiurlwidth=100&iiurlheight=100 produces a XML response given below. The query response gives the URL of the image as well as URL of thumbnail created with the max width and height parameter maintaining the aspect ratio.
<?xml version="1.0"?> -<api>-<query>-<pages>-<page title="File:Greek - Apollo - Walters 59533.jpg" ns="6" pageid="18787772" imagerepository="local">-<imageinfo><ii descriptionurl="http://commons.wikimedia.org/wiki/File:Greek_-_Apollo_-_Walters_59533.jpg" url="http://upload.wikimedia.org/wikipedia/commons/3/37/Greek_-_Apollo_-_Walters_59533.jpg" thumbheight="100" thumbwidth="92" thumburl="http://upload.wikimedia.org/wikipedia/commons/thumb/3/37/Greek_-_Apollo_-_Walters_59533.jpg/92px-Greek_-_Apollo_-_Walters_59533.jpg" height="1800" width="1649" size="1734533"/></imageinfo></page></pages></query></api>
-- View this message in context: http://wikimedia.7.n6.nabble.com/Api-Query-for-thumbnail-images-title-etc-in... Sent from the WikiMedia Commons mailing list archive at Nabble.com.
Actually, it looks like I was wrong. According to Rillke, you can do it in a single query by using a generator: https://commons.wikimedia.org/w/api.php?action=query&generator=categorym...
Ryan Kaldari
On 9/6/12 5:57 PM, vjkumar wrote:
I am trying to get by media API query the url of thumbnail, image and description for all images in the following category web page: http://commons.wikimedia.org/wiki/Category:Coins_in_the_Walters_Art_Museum
I tried the following query:
http://commons.wikimedia.org/w/api.php?format=xml&action=query&list=...
which produced an XML output which gave me all the Image file names. With a file name I am able to construct the url for this file.
For example with "File:Ethiopian - Coin Depicting an Anonymous King - Walters 59793 - Reverse.jpg"
I am able to construct the URL for the image as http://commons.wikimedia.org/wiki/File:Ethiopian_-_Coin_Depicting_an_Anonymo....
However I would like to get the thumbnail url, Title and the description for the images in this category with a query and get the output in XML or JSON format . Is it possible to construct such a query? Thanks. The XML output is given below:
<?xml version="1.0"?>
-<api>-<query>-<categorymembers><cm title="File:Ethiopian - Coin Depicting an Anonymous King - Walters 59793 - Obverse.jpg" ns="6" pageid="18842729"/><cm title="File:Ethiopian - Coin Depicting an Anonymous King - Walters 59793 - Reverse.jpg" ns="6" pageid="18842732"/><cm title="File:Ethiopian - One of Two Coins Depicting Ousanas and an Anonymous King - Walters 59794.jpg" ns="6" pageid="18809697"/><cm title="File:Greek - Apollo - Walters 59533.jpg" ns="6" pageid="18787772"/><cm title="File:Greek
- Athena - Walters 59519 - Obverse.jpg" ns="6" pageid="18801612"/><cm
title="File:Greek - Athena - Walters 59519 - Reverse.jpg" ns="6" pageid="18801616"/><cm title="File:Greek - Athena - Walters 59702 - Back.jpg" ns="6" pageid="18787788"/><cm title="File:Greek - Persephone - Walters 59693.jpg" ns="6" pageid="18787786"/><cm title="File:Greek - Tetradrachme with King Nicodemus II - Walters 59723 - Back.jpg" ns="6" pageid="18787795"/><cm title="File:Matthes Gebel - Medal of Arnold and Nicholas Wenck - Walters 59480 - Obverse.jpg" ns="6" pageid="18839416"/></categorymembers></query>-<query-continue><categorymembers cmcontinue="file|7e524f4d414e202d20434f494e2057495448204120484950504f504f54414d555320414e4420504f525452414954204f46204f544143494c494120534556455241202d2057414c54455253203539373531202d204241434b2e4a50470a524f4d414e202d20434f494e2057495448204120484950504f504f54414d555320414e4420504f525452414954204f46204f544143494c494120534556455241202d2057414c54455253203539373531202d204241434b2e4a5047|18787799"/></query-continue></api>
-- View this message in context: http://wikimedia.7.n6.nabble.com/Api-Query-for-thumbnail-images-title-etc-in... Sent from the WikiMedia Commons mailing list archive at Nabble.com.
Commons-l mailing list Commons-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/commons-l