Warning: Tumblr randomly serving JPEGs instead of PNGs

LostPone
Solar Supporter - Fought against the New Lunar Republic rebellion on the side of the Solar Deity (April Fools 2023).
Notoriously Divine Tagger - Consistently uploads images above and beyond the minimum tag requirements. And/or additionally, bringing over the original description from the source if the image has one. Does NOT apply to the uploader adding several to a dozen tags after originally uploading with minimum to bare tagging.
Fine Arts - Two hundred uploads with a score of over a hundred (Safe/Suggestive)
Perfect Pony Plot Provider - Uploader of 10+ images with 350 upvotes or more (Questionable/Explicit)

Ctrl+S
At the time of writing this post, it seems that Tumblr started serving JPEGs randomly when the expected pic was a PNG.
 
Here’s an NSFW example, the pics in this post:  
http://piesaucy.tumblr.com/post/166229190077/h-honey-a-very-nice-and-relaxing-zeppelin (again, NSFW)  
I know that both pics are already on Derpibooru, I’m just using it as an example because it’s a post with two PNG pics.
 
The pic with Night Light,  
https://66.media.tumblr.com/0d62f431bb952c3907d895e739caf0c2/tumblr_oxkot6NuK11u2sl0oo2_r1_1280.png  
is actually a 310733 byte JPEG, despite the extension, while  
https://78.media.tumblr.com/0d62f431bb952c3907d895e739caf0c2/tumblr_oxkot6NuK11u2sl0oo2_r1_1280.png  
is a 1233687 byte PNG.  
However, with the pic with Shining Armor,  
https://78.media.tumblr.com/0fe55cb425dd123cd6fb9d229f3e4df7/tumblr_oxkot6NuK11u2sl0oo1_r1_1280.png  
is a 311107 byte JPEG, and you’d need to download  
https://68.media.tumblr.com/0fe55cb425dd123cd6fb9d229f3e4df7/tumblr_oxkot6NuK11u2sl0oo1_r1_1280.png  
to get a 1258683 byte PNG.  
I mean, the numbers before .media.tumblr.com seem to be completely unrelated to the format of the image served, and it’s the same when using just media.tumblr.com, without numbers, the server returns randomly JPEGs or PNGs. It seems to be a cache thing, so maybe the links here will even return different images after the cache expires.  
At least the images with the wrong format return the appropriate Content-Type: image/jpeg header, so this behavior is easy to detect programmatically.
 
I’ve been completely unable to find any query parameter or any header that would force the server to return always a PNG, but I think that the cache at a.tumblr.com always serves the right format. It uses CloudFront recompression though, for example, the pic with Night Light,  
https://a.tumblr.com/0d62f431bb952c3907d895e739caf0c2/tumblr_oxkot6NuK11u2sl0oo2_r1_1280.png  
is a 1197225 byte PNG (while Tumblr’s original copy was 1233687 bytes), and the pic with Shining Armor,  
https://a.tumblr.com/0fe55cb425dd123cd6fb9d229f3e4df7/tumblr_oxkot6NuK11u2sl0oo1_r1_1280.png  
is a 1222339 byte PNG (while Tumblr’s original copy was 1258683 bytes).  
Again, I’m not sure if this server will always return the right format, but maybe it’s worth checking the pic returned by this server, in case the first attempt at downloading the image from *.media.tumblr.com gets a JPEG instead.
 
After a quick search, I found that there are already some of these JPEGs on Derpibooru, such as >>1841565 (merged), >>1841432, or >>1841383 (merged). They all should be PNGs, media. serves JPEG versions for them, but a. serves a PNG.
stsyn
Lunar Supporter - Helped forge New Lunar Republic's freedom in the face of the Solar Empire's oppressive tyrannical regime (April Fools 2023).
Elements of Harmony - Had an OC in the 2022 Community Collab
Non-Fungible Trixie -
Twinkling Balloon - Took part in the 2021 community collab.
Notoriously Divine Tagger - Consistently uploads images above and beyond the minimum tag requirements. And/or additionally, bringing over the original description from the source if the image has one. Does NOT apply to the uploader adding several to a dozen tags after originally uploading with minimum to bare tagging.
Best Artist - Providing quality, Derpibooru-exclusive artwork
Fine Arts - Two hundred uploads with a score of over a hundred (Safe/Suggestive)
Economist -
Cool Crow - "Caw!" An awesome tagger
The Power of Love - Given to a publicly verified artist with an image under their artist’s tag that has reached 1000 upvotes

Moderator
Also problem with a.tumblr.com is that it’s not always accessible (nsfw):  
https://78.media.tumblr.com/407e8b4fa9e87f287b5d7fd27e294248/tumblr_pfn0qblPgs1u8y0bro1_1280.png exists  
https://a.tumblr.com/407e8b4fa9e87f287b5d7fd27e294248/tumblr_pfn0qblPgs1u8y0bro1_1280.png not (but https://a.tumblr.com/407e8b4fa9e87f287b5d7fd27e294248/tumblr_pfn0qblPgs1u8y0bro1_640.png exists too)
 
Maybe bruteforcing server ids will provide png, but not sure. Both links to first image in post provide me jpeg
LostPone
Solar Supporter - Fought against the New Lunar Republic rebellion on the side of the Solar Deity (April Fools 2023).
Notoriously Divine Tagger - Consistently uploads images above and beyond the minimum tag requirements. And/or additionally, bringing over the original description from the source if the image has one. Does NOT apply to the uploader adding several to a dozen tags after originally uploading with minimum to bare tagging.
Fine Arts - Two hundred uploads with a score of over a hundred (Safe/Suggestive)
Perfect Pony Plot Provider - Uploader of 10+ images with 350 upvotes or more (Questionable/Explicit)

Ctrl+S
An update on this to make it even worse: the file you get depends on your location and/or your DNS.
 
I tried to download https://68.media.tumblr.com/3cb69a5025052a5190d611d26640a7a9/tumblr_n8u6mwlw1J1rwimero4_1280.png [nsfw] using two different computers, one in Europe, and one in America, and…
 
Europe:
GET /3cb69a5025052a5190d611d26640a7a9/tumblr_n8u6mwlw1J1rwimero4_1280.png HTTP/1.1
Host: 68.media.tumblr.com
User-Agent: curl/7.57.0
Accept: /
< HTTP/1.1 200 OK
< Date: Thu, 04 Oct 2018 23:48:49 GMT
< Content-Type: image/png
< Content-Length: 726715
(…)@
 
America:
GET /3cb69a5025052a5190d611d26640a7a9/tumblr_n8u6mwlw1J1rwimero4_1280.png HTTP/1.1
Host: 68.media.tumblr.com
User-Agent: curl/7.57.0
Accept: /
< HTTP/1.1 200 OK
< Date: Thu, 04 Oct 2018 23:36:22 GMT
< Content-Type: image/jpeg
< Content-Length: 272440
(…)@
 
Making the exact same request to the same domain will return different files depending on the IP resolved.
 
It’s worth mentioning that making the request to the “right” IP will get the right image. ie, this should get the PNG, no matter where you’re making the request.  
curl -kv https://77.238.180.14/3cb69a5025052a5190d611d26640a7a9/tumblr_n8u6mwlw1J1rwimero4_1280.png -H "Host: 68.media.tumblr.com" -O
HOWEVER, the Host header still determines the file that will be received. For example, this will download the JPEG.  
curl -kv https://77.238.180.14/3cb69a5025052a5190d611d26640a7a9/tumblr_n8u6mwlw1J1rwimero4_1280.png -H "Host: media.tumblr.com" -O
Needless to say, different images require different values in order to get the PNG, assuming it’s even possible to get the PNG (I couldn’t find any PNG for the image linked by StSyaN anywhere, for example).
 
tl;dr: Tumblr is so incredibly broken that, at this moment, it’s nearly impossible to know how to get the PNG versions of the images. I was trying to find a good method now that we know that a.tumblr.com doesn’t always work, but after this I’m giving up, it’s simply not worth it.  
I just hope Tumblr will reenable _raw images eventually anyway.
stsyn
Lunar Supporter - Helped forge New Lunar Republic's freedom in the face of the Solar Empire's oppressive tyrannical regime (April Fools 2023).
Elements of Harmony - Had an OC in the 2022 Community Collab
Non-Fungible Trixie -
Twinkling Balloon - Took part in the 2021 community collab.
Notoriously Divine Tagger - Consistently uploads images above and beyond the minimum tag requirements. And/or additionally, bringing over the original description from the source if the image has one. Does NOT apply to the uploader adding several to a dozen tags after originally uploading with minimum to bare tagging.
Best Artist - Providing quality, Derpibooru-exclusive artwork
Fine Arts - Two hundred uploads with a score of over a hundred (Safe/Suggestive)
Economist -
Cool Crow - "Caw!" An awesome tagger
The Power of Love - Given to a publicly verified artist with an image under their artist’s tag that has reached 1000 upvotes

Moderator
It may be interesting:  
Tumblr started to redirect some image urls (like https://68.media.tumblr.com/3cb69a5025052a5190d611d26640a7a9/tumblr_n8u6mwlw1J1rwimero4_1280.png [nsfw]) to “redirect” page. Almost all ids are affected (except numberless, a, 46 and 66. Also 69 not redirects _1280). Seems to doesn’t work with pretty old URLs without hash. Or it just doesn’t work when post died.  
It’s mostly usefull feature, since it shows original post where image were posted (!!!) and leaks original image size in window\['\_\_\_INITIAL\_STATE\_\_\_'\]\["image-url-page"\].photo.
 
Also seems like it’s cheating a bit: it half-ignores last digit in the image name (this digit shows image position in post) and attempting to change it in normal way leads to 404, while using redirect it works, but showing same image because of its checksum, not the actual in this position. Overflowing number leads to 404.  
Also removing _r1 (“edited” mark) with wrong (lesser?) order id may lead to simply image without wrapper, I don’t have enough samples to research it.
Interested in advertising on Derpibooru? Click here for information!
Champions of Equestria

Help fund the $15 daily operational cost of Derpibooru - support us financially!

Syntax quick reference: **bold** *italic* ||hide text|| `code` __underline__ ~~strike~~ ^sup^ %sub%

Detailed syntax guide