Search code examples
htmlcsstumblr

Tumblr: Best way to display photos with proper dimensions


I would like my template to have different dimensions for a photo, based on it being a portrait or landscape image.

For example:

if (dimensions == landscape)
{LinkOpenTag}
    <img src="{PhotoURL-500}" width="800" height="600" class="photo" alt="{PhotoAlt}" />   
{LinkCloseTag}
else
{LinkOpenTag}
    <img src="{PhotoURL-500}" width="600" height="800" class="photo" alt="{PhotoAlt}" />
{LinkCloseTag}

Solution

  • Sadly you can't work out if an image is landscape / portrait from Tumblr theme operators alone. You would need to use javascript to work this out.

    However, I question why you would need to know this as both the following would display an image, in its natural size / orientation:

    {LinkOpenTag}
        <img src="{PhotoURL-500}" class="photo" alt="{PhotoAlt}" />
    {LinkCloseTag}
    

    Or:

    {LinkOpenTag}
        <img src="{PhotoURL-500}" width="{PhotoWidth-500}" height="{PhotoHeight-500}" class="photo" alt="{PhotoAlt}" />
    {LinkCloseTag}
    

    Reference: http://www.tumblr.com/docs/en/custom_themes#photo-posts