If some Wikidata item (with ID: Qxxx) has image (P18) property, you can access it by MediaWiki API:
https://www.wikidata.org/w/api.php?action=wbgetclaims&property=P18&entity=Qxxx
The response will include:
"claims": {
"P18": [{ "mainsnak": { "datavalue": { "value": "img_name.ext" }}}]
}
where img_name.ext is the name of the image you are looking for (all whitespaces have to be replaced with _
).
The final image URL will be: https://upload.wikimedia.org/wikipedia/commons/a/ab/img_name.ext
, where a and b are the first and the second chars of md5sum of the img_name.ext.
For example, for item jaguar (Q35694) the API will returns image name "Junior-Jaguar-Belize-Zoo.jpg", which has md5sum: 213b31ec141dafebe457e49bcd7f9329, so a=2 and b=1, or the final image URL will be: https://upload.wikimedia.org/wikipedia/commons/2/21/Junior-Jaguar-Belize-Zoo.jpg
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…