Use a wikimedia image on my website

682 views Asked by At

So I have a wikimedia commons URL(which is really just a wrapper for the actual image), like this: https://commons.wikimedia.org/wiki/File:Nine_inch_nails_-_Staples_Center_-11-8-13(10755555065_16053de956_o).jpg

If I go to that page, I can see that the actual image is at: https://upload.wikimedia.org/wikipedia/commons/thumb/5/5b/Nine_inch_nails_-_Staples_Center_-11-8-13%2810755555065_16053de956_o%29.jpg/800px-Nine_inch_nails_-_Staples_Center_-11-8-13%2810755555065_16053de956_o%29.jpg

I'd like to get the actual file(s), so that I can use it in an <img> tag.

I'd suspected that they'd give you a url parameter to return the location, but I can't find anything about it.

Thanks in advance.

EDIT:

I think I found the answer here: https://commons.wikimedia.org/wiki/Commons:FAQ#What_are_the_strangely_named_components_in_file_paths.3F

The strange paths in the upload are letters from an MD5 hash of the filename.

1

There are 1 answers

1
dessalines On

Figured it out, here's a little java I wrote to do this correctly:

public static String convertWikimediaCommonsURLToImageUrl(String wmLink) {  

    String fileName = wmLink.split("File:")[1];

    String md5 = Hashing.md5().hashString(fileName, Charsets.UTF_8).toString();

    String weirdPathString = md5.substring(0, 1) + "/" + md5.substring(0, 2) + "/";
    String imageURL = "https://upload.wikimedia.org/wikipedia/commons/" + weirdPathString + 
            fileName;

    return imageURL;
}