What is the URL schema of Tumblr images?

Jimmy T. picture Jimmy T. · May 30, 2013 · Viewed 43.4k times · Source

What is the schema of a image-file at Tumblr? (I don't mean HTTP) I've only figured out that the domain of the servers where images are stored is <n>.media.tumblr.com, where n is a number between 1 and 31 and the name of the image file is prefixed with "tumblr_.

I'm asking because I want to find URLs that refer to the same image.

EDIT: I'm also processing URLs from other sources, not only Tumblr.

Answer

mikedidthis picture mikedidthis · May 30, 2013

Overview

When you upload an image to Tumblr, multiple sizes (of the same image) are generated and stored across their network.

Once uploaded, you can use template tags to request this image at the following sizes: 75, 100, 250, 400, 500 and 1280.

It's worth mentioning the following:

  1. The value in the template tag is the maximum size the requested image will be. Example: A 400 version of an image could be anywhere between 251px and 400px wide / high.
  2. There may not be a high res or 1280 version of an image available. If the original image is 500px or less, a 1280 version isn't generated.
  3. Photosets don't produce a 100 version.

Image URL

The image URL will be either of the two below. The first URL seems to be associated with images upload more than 6 months ago (this is a guess), the second URL seems to be for newer images:

http://36.media.tumblr.com/tumblr_o4qxa0n2BP1r6ec7zo1_500.jpg

or

http://36.media.tumblr.com/83099a60d4e0cbeeb30d90394e222878/tumblr_o4qxa0n2BP1r6ec7zo1_500.jpg

URL Schema

This can be split into three parts, two variables, one constant.

  1. http://36
  2. .media.tumblr.com/83099a60d4e0cbeeb30d90394e222878/tumblr_o4qxa0n2BP1r6ec7zo1
  3. _500.jpg

1 This is a server number and can differ for each image size. AFAIK there is no guarantee that an image size will be available on all servers. @Ally mentioned in the comments you can remove this part from the URL and the image will still be found.
2 This is the Tumblr subdomain, directory (if applicable) and partial file name. This will be the same for all sizes.
3 This is the requested size (which matches the template tag) and file extension.

Generating URLs for all sizes available using template tags.

The only foolproof method I have found is to use the corresponding template tags and assign them to a data- attribute.

Example Template Code:

<img src="{PhotoURL-100}" data-250u="{PhotoURL-250}" data-400u="{PhotoURL-400}" data-500u="{PhotoURL-500}" data-1280u="{block:HighRes}{PhotoURL-HighRes}{/block:HighRes}" />

Example Rendered Code:

<img src="http://36.media.tumblr.com/83099a60d4e0cbeeb30d90394e222878/tumblr_o4qxa0n2BP1r6ec7zo1_100.jpg" data-250u="http://36.media.tumblr.com/83099a60d4e0cbeeb30d90394e222878/tumblr_o4qxa0n2BP1r6ec7zo1_250.jpg" data-400u="http://36.media.tumblr.com/83099a60d4e0cbeeb30d90394e222878/tumblr_o4qxa0n2BP1r6ec7zo1_400.jpg" data-500u="http://36.media.tumblr.com/83099a60d4e0cbeeb30d90394e222878/tumblr_o4qxa0n2BP1r6ec7zo1_500.jpg" data-1280u="http://36.media.tumblr.com/83099a60d4e0cbeeb30d90394e222878/tumblr_o4qxa0n2BP1r6ec7zo1_1280.jpg" >

With this method, you can be certain you have the correct URLs and you know what sizes are available.

Hacking all size URLs based on just one URL.

Using this information the URL would become:

http://36.media.tumblr.com/83099a60d4e0cbeeb30d90394e222878/tumblr_o4qxa0n2BP1r6ec7zo1_500.jpg

Below is a test to confirm we access all the available sizes:

You still wouldn't know if the 1280 size has been generated, but its a step closer. With this method you could replace the value (part 3) with an new size and you should be able to get the image.