September 2010
8 posts
I parsed a file_get_contents(api/read URL) return value directly, using domxml_open_mem(). The script walks the many-to-one photo-url children of each photo post. Each photo-url contains the URL for a copy of the original image sized up to, but not larger than, the attributed max-width. For high-resolution images, each URL will be distinct. For small original images, you will see the URL to its largest size repeated, for example:
…
<photo-url max-width=”1280”>
http://25.media.tumblr.com/SJZFJaHDo5vco3muV3EgxVjo_250.jpg
</photo-url>
−
<photo-url max-width=”500”>
http://25.media.tumblr.com/SJZFJaHDo5vco3muV3EgxVjo_250.jpg
</photo-url>
−
<photo-url max-width=”400”>
http://25.media.tumblr.com/SJZFJaHDo5vco3muV3EgxVjo_250.jpg
</photo-url>
…
Knowing an element for each of the standard max-widths will be present even for smaller images allows you to simplify by checking directly for a given max-width. You can also iterate through doing a getimagesize() on each to find actual dimensions.