Search code examples
mediawiki-apiwikimedia

MediaWiki API: Download smaller versions of images


I want to download all images matching a certain criteria from the Wikimedia commons.

This API call gives me the image URLs of 5 images matching the search term "Programming":

http://commons.wikimedia.org/w/api.php?action=query&list=allimages&ailimit=5&aifrom=Programming&aiprop=dimensions|url

However, the URLs refer to the full-size images. How can I access the smaller versions programmatically?


Solution

  • Well, you need to change your query from list=allimages to prop=imageinfo and instead use the list as a generator. Then for the imageinfo you can specify iiurlwidth as desired.

    Example with width 500: http://commons.wikimedia.org/w/api.php?action=query&prop=imageinfo&format=json&iiprop=url%7Cdimensions&iiurlwidth=500&titles=Programming&generator=allimages