• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
Locked
0

Dynamically generate thumbnail images

May 10, 2012 May 10, 2012

Copy link to clipboard

Copied

BC is designed with the functionality to automatically scale and display thumbnail images (smaller versions) of existing image files in your site. In this article, you'll learn how to add code to your pages and leverage this capability, so that you don't have to manually create smaller versions of the image files and upload them to the live site.

Adding code to generate a thumbnail image from an existing image

  1. Begin by accessing the source code for the page. Select Site Manager > Pages and select the page from the tree view.
  2.   Click HTML below the content editor to see the source code.
    html_tab.png
  3. Place your cursor at the location on the page where you want to insert a thumbnail image. Type the following code:

<img src="/folder_name/image_file_name.jpg?Action=thumbnail&Width=80&Height=80" />


In the example above, replace this part of the code:

/folder_name/image_file_name.jpg

With the actual path to your full size image file, like this example:

/images/logo.png

Also, update the two numeric values in the following part with the width and height of the thumbnail you want to display (in pixels):

Width=80&Height=80

For example, if you'd like the thumbnail image to be 70 pixels wide by 50 pixels high, update the values like this:

Width=70&Height=50

Note: You do not need to specify both width and height. You can specify one of these dimensions and Business Catalyst will proportionally resize the image based on this dimension.

Setting the aspect ratio of the source image that is resized

If you want to preserve the aspect ratio for the larger image size (to prevent a squashed or squished looking thumbnail image), you can add an additional parameter, thumbnail, to the <img> tag, as shown in the example below:

<img src="/folder_name/image_file_name.jpg?Action=thumbnail&Width=80&Height=80&algorithm=fill_proportional" />


The algorithm parameter accepts the following three values:          

proportional          
fill          
fill_proportional

The default setting for the thumbnail generator is proportional; if you want this setting, you don't need to add the parameter. Here's a description of the results of each value:

proportional: The thumbnail maintains the aspect ratio of the source image and uses the  specified width or height of whichever side of the image file is  proportionately bigger.

fill: The dimensions of the thumbnail are resized to fill the specified Width and Height settings as defined in the parameters; the aspect ratio of the original source image is not maintained.

fill_proportional: The dimensions of the thumbnail are resized to fill the specified Width and Height settings as defined in the parameters; the extra pixels from the top/bottom or left/right are cropped on whichever side of the image is proportionally larger, if needed, to maintain the aspect ratio of the original source image and ensure that the thumbnail does not look squashed or squished. If the desired thumbnail dimensions are larger than the source image dimensions then the image is not resized and transparent pixels are added around the image.

Setting the output format of the generated thumbnail image

You can set the output format of the generated image by appending the &Format= parameter.

For instance, to generate the thumbnail in .png format, this would be the thumbnail URL:

<img src="/folder_name/image_file_name.jpg?Action=thumbnail&Width=80&Height=80&Format=png" />


Accepted output parameters include png, jpg and gif.

Generating thumbnail images for Web Apps

Similar to the process of displaying thumbnail images on web pages and photo galleries, you can also generate thumbnail images programmatically for Web App image content. Simply add parameters to the image source tag as shown in the following example:

<img src="{tag_myimage_value}?Action=thumbnail&Width=80&Height=80" />

In the example above, the part {tag_myimage_value} is replaced with the path to the full sized image when the Web App is dynamically rendered by the browser.

The system uses the data of the full size image to automatically scale it to the height and width values (in pixels) that you specify in the parameters of the <img> tag.

Generating thumbnail images for products in an online store

Programmatically generated thumbnail images are also very useful when displaying product images in a catalog.

Here's an example of an image tag used to generate a thumbnail image of a larger product image:

<img src="{tag_largeimage_path}?Action=thumbnail&Width=50&Height=50" />


In the example above, {tag_largeimage} was originally our dynamic image tag. However, we appended _path to the tag. Doing so will output the path to the full sized image. The same method will work for {tag_smallimage}.

TOPICS
Documentation

Views

14.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
May 10, 2012 May 10, 2012

Copy link to clipboard

Copied

Great stuff, Daniel! One thing to note is that this code will not work for catalog images or if you choose to add the product image to the online cart. In either case, you can use some CSS to control the width of the image and place the image in a container with a width and height setting that is also set to overflow hidden. Also, concerning the cart image, if you use the large product image for both the list and details view (using the re-sizing method above for the list), you can then use the small image solely for use in the cart layout.

Carol | BCGurus.com | http://bcgurus.com/Business-Catalyst-Templates for only $7

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 15, 2012 Sep 15, 2012

Copy link to clipboard

Copied

Hi Daniel,

Thanks for the info.. but is there any way of applying "fill_proportional" to the thumbnails which are generated for the photo gallery module in BC?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 16, 2012 Sep 16, 2012

Copy link to clipboard

Copied

Take a look at http://kb.worldsecuresystems.com/134/bc_1345.html#main_Photo_Gallery_Modules

The format for the photo gallery is:

{module_photogallery,ID,rowLength,targetFrame,resultsPerPage,Width,Height,UseStandardMethod,ThumbnailAlgorithm}

ThumbnailAlgorithm can be set to fill_proportional

-mario

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

Hi:

I am trying to get this to work in IE8, on the cart page, but the image is not being  scaled down - unfortunately with setting the container to a height/width of 100px and overflow to hidden - I just see a little bit of the image in the cart.  Looking at the piece I can see, I can tell the image is the usual 600px size - so it is still large.  Any thoughts?

I also saw where it was mentioned I could use the {tag_smallimage} for the cart layout, but I can not get that tag to populate images.  It just shows the text, when you go to the front end of the site.

http://childtocherish01.businesscatalyst.com (this is the site, not yet launched, although we are shooting for this week)

Thanks so much for any assistance that can be offered.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

Inside the shopping cart you need to use {tag_productimage} which should render the small product image. 600px would not be a small product image. Please find that image inside the file manager and make sure that the size is correct.

-m

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 12, 2012 Nov 12, 2012

Copy link to clipboard

Copied

Thanks.  The one issue is that I was trying to create the site so the client did not have to scale their images manually - I wanted them to be able to  load up an image (even a large one) into the product edit screen and then in the different places where the image is going to be used I would have code scale it down automatically.  I actually found a solution by noticing it was working on the OXO Template in BC.  I matched its CSS settings, and now the images are showing correctly in IE.

Thanks again for the help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

I followed your code and I got the results I needed. But, I have a problem. I am using this code for a Small Product Display photo. Now I cannot click on the photo to take me to the Large Product Display. Did I miss something in the code? I placed the code in the module template in place of the {tag_smallimage}, as shown below...

<div class="shop-product-small clear">

<h5>{tag_name}</h5>

<br />

<div class="image"><img alt="" src="{tag_largeimage_path}?Action=thumbnail&Width=253&Height=253&algorithm=fill_proportional" /></div>

</div>

Any thoughts?

Chuck

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

Hey Chuck,

Just wrap the image in an anchor tag with the href="{tag_itemurl_nolink}"

so:

<a href="{tag_itemurl_nolink}"><img alt="" src="{tag_largeimage_path}?Action=thumbnail&Width=253&Height= 253&algorithm=fill_proportional" /></a>

Carol | BCGurus.com | http://bcgurus.com/Business-Catalyst-Templates for only $7

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 01, 2012 Jun 01, 2012

Copy link to clipboard

Copied

Perfect! Thanks Carol!

Chuck

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 28, 2012 Jun 28, 2012

Copy link to clipboard

Copied

Does anyone know if this will work in an email campaign and then display properly in major email clients?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jun 28, 2012 Jun 28, 2012

Copy link to clipboard

Copied

Hi Pat,

This will not work inside the email campaigns. You can only use the tag which are present inside the Tag Dropdown in email campaigns.

Cheers,

-mario

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2012 Aug 13, 2012

Copy link to clipboard

Copied

I am trying to do this with a webapp item but it is not working for me -

   <a href="{tag_image-1_nolink}"><img alt="" src="{tag_image-1}?Action=thumbnail?Width=400?Height=400" /></a>

          

Produces no image and shows everything after the last } on the webpage - here is my example - im building this using a webapp and the user upload 2 images for each "item" - trying to display these small but clickable to larger size -

http://romanfarm.businesscatalyst.com/for-sale/26-acres-for-sale

Not sure what i am doing wrong - thanks in advance!

Tom Cuneo

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2012 Aug 13, 2012

Copy link to clipboard

Copied

Hi Tom, use _value instead of _nolink. Also make sure the field type is image.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2012 Aug 13, 2012

Copy link to clipboard

Copied

Thanks SO much Carol for the quick reply -

That seemed to work partially lol 🙂

<a href="{tag_image-1_value}"><img alt="" src="{tag_image-1_value}?Action=thumbnail?Width=400?Height=400" /></a>

<a href="{tag_image-2_value}"><img alt="" src="{tag_image-2_value}" /></a>

Ive updated the link above - ive got two images, the second is now showing but full screen the first is not with the Action tied to it..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2012 Aug 13, 2012

Copy link to clipboard

Copied

Just to add when i view the element in source it is showing the right path to the image itself -

<img alt="" src="/images/propS1-1.jpg?Action=thumbnail?Width=400?Height=400?algorithm=fill_proportional">

Thanks again - this is my first real webapp and it is going to be cool when i get it going 🙂 Love learning new stuff!


Tom

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 13, 2012 Aug 13, 2012

Copy link to clipboard

Copied

I got it figured out 🙂

Thanks again Carol - much thanks for taking the time to help! It is very much appreciated


Tom

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 20, 2012 Aug 20, 2012

Copy link to clipboard

Copied

Hi Tom,

I was on vacation so sorry to miss your two replies! Happy to hear you got it working!

Carol

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 20, 2012 Aug 20, 2012

Copy link to clipboard

Copied

No worries Carol 🙂 Again thanks for your time -

Im enjoying the web apps the more i dig into it. Got some great ideas for our customers i can now build for them using web apps. Once i get past the learning curves of the system could be dangerous LOL

In fact we got one client just because of being able to meet their desires using webapps 😉  I'll be a guru yet 😉

Tom

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Dec 06, 2012 Dec 06, 2012

Copy link to clipboard

Copied

Hey guys,

just an update, the thumbnail API has been updated.

You can now specify just a single dimension (width or height) and the system will proportionally resize the other dimension.

Cheers,

Dan

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

Can this technique be used for resizing Catalog images as well?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Dec 18, 2012 Dec 18, 2012

Copy link to clipboard

Copied

Hi Natenoob,

Looks like this method can't be used for catalog images. The reason is that you can't output the raw path of the catalog image using a tag (e.g. /image/catalog-image.png).

The {tag_image} tag in the catalog layout outputs the full <img src....> HTML so adding the thumbnail parameter would end up being <img src="/image/catalog-image.png">?Action=thumbnail&Width=80&Height=80.

Cheers,

Daniel

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 18, 2012 Dec 18, 2012

Copy link to clipboard

Copied

Thanks! Do you recommend png format over jpg? I've noticed some graphical errors when resizing gif images, but so far jpg is working for me

Sent from my iPhone

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Dec 18, 2012 Dec 18, 2012

Copy link to clipboard

Copied

I find jpg works quite well

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 10, 2013 Apr 10, 2013

Copy link to clipboard

Copied

Hi,

I am struggling to get my cataloge image to resize automatically in cataloge view.

This is the current code that is there:

<div class="shop-catalogue clear">

<h4>{tag_name}</h4>

<div class="image">{tag_image}</div>

</div>

Is it even possible to adjust the code to resize thhe image?

Thanks

Steve

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines