Photo Links as /photo/

ScottInAustinScottInAustin Registered Users Posts: 12 Big grins
I am using API 1.3.0 in a PHP program to embed photo urls in a blog. The API images.getURLs function, returns the photo URLs such as: http://example.smugmug.com/Motorhome-Galleries/Travels-2004/My-Tradewinds-Cabo/i-J38Rhn7/0/Th/65064762_1-Th.jpg.

I dislike the URL containing the folder structure in case I move the photos.

The API docs for images.getURLs show the URL examples with just the folder structure as /photos/. Example: http://example.smugmug.com/photos/i-J38Rhn7/0/Th/65064762_1-Th.jpg.

I discovered this works! I can replace the folder structure with a simple /photos/ for a much simpler URL.

Is there a way to force the API to return a URL with /photos/?


Thanks

Comments

  • thenickdudethenickdude Registered Users Posts: 1,302 Major grins
    edited May 6, 2014
    The URL that contains your folder names will continue to work even after the image is moved. For example, imagine if you had moved your example image from a folder called Motorhome-picks into its new home, the old URL would have been:

    http://gallery.iltsbd.com/Motorhome-picks/i-J38Rhn7/0/Th/65064762_1-Th.jpg

    And you can see that the "old" link continues to work, even though your photo has now moved.

    I think /photos/ URLs are returned when the image is sourced from an Unlisted gallery (since including the gallery name in the URL would reveal the existence of the Unlisted gallery). You can probably just transform your URLs to /photo/ URLs with a regex like this:
    <?php
    
    $url = "http://example.smugmug.com/Motorhome-Galleries/Travels-2004/My-Tradewinds-Cabo/i-J38Rhn7/0/Th/65064762_1-Th.jpg";
    
    $url = preg_replace('#(^http://[^/]+)(/[^/]+)+/(i-[a-zA-Z0-9]+/)#', '$1/photos/$3', $url);
    
    echo $url;
    
  • ScottInAustinScottInAustin Registered Users Posts: 12 Big grins
    edited May 6, 2014
    Awesome. The regex code was exactly what I was trying to create.

    This is the last step in converting an old blog to blogger, an old gallery to Smugmug. I had to maintain the directory (folder) structure and refererences to photos from the blog.

    This step parses the photo references from the old blog, matches the old reference to the new smugmug id/keyword and reconstructs the image html for the new blog.

    Now I have shorter, consistent photo URL's which are MUCH easier to proof!! And less confusing when we moving things around.

    Thank you!!!
  • AllenAllen Registered Users Posts: 10,008 Major grins
    edited May 6, 2014
    All the old photo links still work everywhere including in blogger.
    ..../photos/XXXXXXX_xxxxxx-M.jpg

    In newSmug the /XXXXXXX_xxxxxx can be found in the page source in the feed url's.
    At least for the old gallery links.

    <link rel="alternate" type="application/rss+xml"......&Data=38993374_NWjRjH&format=rss200" />
    <link rel="alternate" type="application/atom+xml" ......&Data=38993374_NWjRjH&format=atom10" />
    Al - Just a volunteer here having fun
    My Website index | My Blog
Sign In or Register to comment.