Topic: Serve images from CDN

I'm exporting galleries from Lightroom and it works correctly.  I'd like the images to be loaded from my cdn.  I would have to replace the relative url with //cdn.ryansmithphotography.com for each image in the xml.  I could do a find and replace in the xml file, but that would be a pain each time I change the gallery.  Would you have any suggestions for a better way?

Re: Serve images from CDN

If you wanted to start each imageURL with a certain string (to denote the start of an absolute path), then you could modify the template file that the Lightroom plugin uses to generate the gallery's 'config.xml' file.
Open the 'juicebox.lrwebengine/config.xml' file in a plain text editor and change the imageURL entry line 114 from:

imageURL="images/<%= getImage(index).exportFilename %>.jpg"

... to something like:

imageURL="http://cdn.ryansmithphotography.com/images/<%= getImage(index).exportFilename %>.jpg"

Re: Serve images from CDN

Thanks, I actually thought of that and tried it.  The problem is each gallery has a relative path.  In the config.xml it's always just images/...  But I actually have each gallery in a different directory on the site, so the actual path would be like //cdn.ryansmithphotography.com/juicebox/weddings/images/....  So if I just change the template file it would just end up with the links to //cdn.ryansmithphotography.com/images/...   I really couldn't think of a way to do it except for a find and replace in the xml unless you have any other suggestions.  Thanks for the help.

Re: Serve images from CDN

The ideal solution would be to have a custom field within the interface where you could enter a directory name to be prepended to the image names in the imageURL entries.
What you could perhaps do is enter a value in the Pro Options text area that Juicebox itself does not use such as:

directory="http://cdn.ryansmithphotography.com/juicebox/weddings"

You could then modify the Lightroom plugin's 'config.xml' template file to use this value as the start of each imageURL.
You could also instruct the plugin to not write this value to the configuration options in the opening <juiceboxgallery> tag (although this would not actually make any difference to the gallery as Juicebox would just ignore the custom attribute).

Try the following, which will accept a key named 'directory' in the Pro Options text area.
If you entered:

directory="http://cdn.ryansmithphotography.com/juicebox/weddings"

... into the Pro Options text area, then it would result in an imageURL such as:

imageURL="http://cdn.ryansmithphotography.com/juicebox/weddings/images/image.jpg"

Open the 'juicebox.lrwebengine/config.xml' file in a plain text editor and change lines 89-120 to the following:

local dir = ""

for index, value in ipairs(pro_options) do
    if value ~= "" then
        local attrs = explode("=", trim(value), 2)
        if table_length(attrs) == 2 then
            local key = escape(attrs[1]:gsub("%s+", ""))
            local value = escape(trim(attrs[2]):gsub("^([`'\"])(.-)%1$", "%2"))
            if key:lower() == "directory" then
                dir = value
            elseif not lite_options[key:lower()] then
                write("\n" .. key .. "=\"" .. value .. "\"")
            end
        end
    end
end %>
>

<% for index = 1, numImages do %>
    <image imageURL="<%= dir %>/images/<%= getImage(index).exportFilename %>.jpg" thumbURL="thumbs/<%= getImage(index).exportFilename %>.jpg" linkURL="<%= getImage(index).metadata.linkURL %>" linkTarget="_blank">
        <title><![CDATA[<%= strip_control_characters(getImage(index).metadata.title) %>]]></title>
        <caption><![CDATA[<%= strip_control_characters(getImage(index).metadata.caption) %>]]></caption>
    </image>
<% end %>

</juiceboxgallery>

Re: Serve images from CDN

Awesome, that seems to have worked perfectly.  It makes it so the gallery can't be previewed in Lightroom but that really makes no difference at all.  Now if I make changes to a gallery I can directly ftp them to my website through Lightroom with no extra steps.  If you added some more options to the Lightroom plugin I think that would be a much better alternative to Juicebox builder for most photographers.  Thanks for the help.

Re: Serve images from CDN

It makes it so the gallery can't be previewed in Lightroom but that really makes no difference at all.

Use the following code for the gallery to be displayed in the live preview window. The 'directory' value will be written to the gallery's 'config.xml' file only when the gallery is exported (and not in preview mode).

local dir = ""

for index, value in ipairs(pro_options) do
    if value ~= "" then
        local attrs = explode("=", trim(value), 2)
        if table_length(attrs) == 2 then
            local key = escape(attrs[1]:gsub("%s+", ""))
            local value = escape(trim(attrs[2]):gsub("^([`'\"])(.-)%1$", "%2"))
            if key:lower() == "directory" then
                if mode ~= "preview" then
                    dir = value:gsub("/*$", "") .. "/"
                end
            elseif not lite_options[key:lower()] then
                write("\n" .. key .. "=\"" .. value .. "\"")
            end
        end
    end
end %>
>

<% for index = 1, numImages do %>
    <image imageURL="<%= dir %>images/<%= getImage(index).exportFilename %>.jpg" thumbURL="thumbs/<%= getImage(index).exportFilename %>.jpg" linkURL="<%= getImage(index).metadata.linkURL %>" linkTarget="_blank">
        <title><![CDATA[<%= strip_control_characters(getImage(index).metadata.title) %>]]></title>
        <caption><![CDATA[<%= strip_control_characters(getImage(index).metadata.caption) %>]]></caption>
    </image>
<% end %>

</juiceboxgallery>

If you added some more options to the Lightroom plugin I think that would be a much better alternative to Juicebox builder for most photographers.

You might like to know that we are currently working on a new Lightroom plugin which will feature all Pro configuration options in the interface (removing the need to type them into the 'Pro Options' text area).

Re: Serve images from CDN

Even better, maybe this can be an option in the new plugin.  Thanks.

Re: Serve images from CDN

Would you have a recommendation of a way to do the same type of thing this post was about but with the new plugin?

Re: Serve images from CDN

As the new Lightoom plugin no longer has a Pro Option text area, you would need to use one of the available configuration options to enter your custom data.
I would recommend using an input field which accepts text and will not actually be used in your own gallery. For example, if you are not using audio in your gallery, you could use the audioUrlMp3 field.

Add the following to the plugin's 'config.xml' file (on line 48 which is currently blank):

<% local dir = ""
if mode ~= "preview" then
    dir = model.juicebox.audioUrlMp3
end %>

... and change line 54 from:

<image imageURL="images/<%= getImage(index).exportFilename %>.jpg" thumbURL="thumbs/<%= getImage(index).exportFilename %>.jpg" linkURL="<%= getImage(index).metadata.linkURL %>" linkTarget="_blank">

... to:

<image imageURL="<%= dir %>images/<%= getImage(index).exportFilename %>.jpg" thumbURL="thumbs/<%= getImage(index).exportFilename %>.jpg" linkURL="<%= getImage(index).metadata.linkURL %>" linkTarget="_blank">

You can then enter something like the following into the audioUrlMp3 field:

http://www.example.com/juicebox/gallery/

... and the imageURL entries will look like this:

imageURL="http://www.example.com/juicebox/gallery/images/image.jpg"

Please note that the line numbers refer to the current version of the plugin (v1.4.4.0).

Re: Serve images from CDN

Great, that worked perfectly, thanks.  I don't guess it makes any difference that the audiourlmp3= url is added into the config.xml config options?  I assume it just ignores it since there isn't an actual mp3 file available.

Re: Serve images from CDN

If you do not set playAudioOnLoad="TRUE" or showAudioButton="TRUE" (to allow audio functionality), then audioUrlMp3 will not actually be used and its entry in the gallery's 'config.xml' file will just be redundant.
If you wanted to prevent audioUrlMp3 from being written to the gallery's 'config.xml' file, then you could change line 42 of the plugin's 'config.xml' file from:

if (value ~= tostring(model.default[key])) then

... to:

if (value ~= tostring(model.default[key]) and key ~= "audioUrlMp3") then

Re: Serve images from CDN

Thanks for the great support.

Re: Serve images from CDN

You're welcome.

14 (edited by rsmith4321 2015-10-27 00:20:32)

Re: Serve images from CDN

I'm hoping you guys can eventually add cdn config option to the plugin.  This works but everytime the plugin is updated I have to re-edit the config.xml.

Re: Serve images from CDN

I recommend that you post suggestions for new versions (of the core Juicebox or any of the associated plugins) in the Feature Requests forum thread.
I do not know the likelihood of your suggestion being included in a future version of the Lightroom plugin but posting it in the Feature Requests thread gives it the best chance of being seen and considered by the developers.

I know you have already mentioned it in passing (and I realise that it would need to be done with a unique path for each gallery) but you could use a single global search and replace action in a text editor to change:

imageURL="

... to something like:

imageURL="http://www.example.com/gallery/

It should take less than a minute per gallery and might be an alternative workaround.