« Back to Image Gallery...

Image Gallery Thumbnails

Thumbnails are reduced-size versions of pictures, used to help in recognizing and organizing them, serving the same role for images as a normal text index does for words (source: http://en.wikipedia.org/wiki/Thumbnail).

Liferay's Image Gallery Portlet automatically creates thumbnails for images when they are upload. This article describes how the creation of this thumbnails can be configured and how thumbnails can be accessed programmatically.

Configuration #

This can be configured through portal.properties.

    # Set the maximum thumbnail height and width in pixels. Set dimension of the
    # custom images to 0 to disable creating a scaled image of that size.
    #
    ig.image.thumbnail.max.dimension=150
    #ig.image.custom1.max.dimension=100
    #ig.image.custom2.max.dimension=0

As seen above, ig.image.thumbnail.max.dimension defines the max dimension of the thumbnail. In addition, another 2 thumbnail with different custom sizes can be created: custom1 and custom2.

Accessing programmatically #

In order to use the thumbnails in jsp files, you should do the following:

IGImage image = ....;

Image largeImage = ImageLocalServiceUtil.getImage(image.getLargeImageId());
Image smallImage = ImageLocalServiceUtil.getImage(image.getSmallImageId());
Image custom1Image = ImageLocalServiceUtil.getImage(image.getCustom1ImageId());
Image custom2Image = ImageLocalServiceUtil.getImage(image.getCustom2ImageId())
0 Attachments
51298 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
Threaded Replies Author Date
Thanks for sharing..this is really greate! Now... Archi Madhu February 6, 2010 9:47 AM
How can i call a custom generated thumbnail... Pablo Liz May 24, 2010 2:07 PM
Can those images be called inside a Web Content... Peter Mesotten August 25, 2010 7:52 AM
Yes, you can use same approach inside journal... wolfgang kubens October 15, 2010 1:56 PM
hi, thanks for this post, it really helped a... Tom I. March 1, 2011 2:30 PM
SOLVED. The custom sized images are created... Tom I. March 1, 2011 3:12 PM
Hi, I am facing one problem regarding... Nilesh Gundecha November 22, 2011 6:43 AM

Thanks for sharing..this is really greate!
Now no need to worry about CSS classes and borwser compatibility issue for small image
also fast image loading if there are many images in same page!
Posted on 2/6/10 9:47 AM.
How can i call a custom generated thumbnail from a .vm or .xsl template?
Posted on 5/24/10 2:07 PM.
Can those images be called inside a Web Content Display as well?
Posted on 8/25/10 7:52 AM.
Yes, you can use same approach inside journal templates also.

Structure:
1<root>
2  <dynamic-element name='headline' type='text' repeatable='false'></dynamic-element>
3  <dynamic-element name='image' type='image_gallery' repeatable='true'></dynamic-element>
4</root>


Journal Template:
 1#set ($ImageLocalService = $serviceLocator.findService("com.liferay.portlet.imagegallery.service.ImageLocal­ServiceUtil"))
 2#set ($IGImageLocalService = $serviceLocator.findService("com.liferay.portlet.imagegallery.service.IGImageLoc­alServiceUtil"))
 3
 4<h1>$headline.getData()</h1>
 5#foreach ($item in $image.getSiblings())
 6<p>
 7    #set ($url = $getterUtil.getString($item.getData()))
 8    #set ($uuid = $getterUtil.getString($httpUtil.getParameter($url, "uuid", false)))
 9    #set ($groupId = $getterUtil.getLong($httpUtil.getParameter($url, "groupId", false)))
10    #set ($imageObj = $IGImageLocalService.getImageByUuidAndGroupId($uuid, $groupId))
11    #set ($smallImageId = $imageObj.getSmallImageId())
12    #set ($thumbObj = $ImageLocalService.getImage($smallImageId))
13
14    <img src="/image/image_gallery?img_id=$smallImageId" width="$thumbObj.getWidth()" height="$thumbObj.getHeight()"/><br>
15</p>
16#end
Posted on 10/15/10 1:56 PM in reply to Peter Mesotten.
hi, thanks for this post, it really helped a lot.

on the other hand, I couldn't get to use a custom sized image in a FreeMarker template in LR 6.0.5.
imageObj.getSmallImageId() works well, but imageObj.getCustom1ImageId() returns 0 (zero number) instead of the object. I have ig.image.custom1.max.dimension=210
in portal-ext.properties
do you have any ideas why it doesn't work?
thanks
Posted on 3/1/11 2:30 PM in reply to wolfgang kubens.
SOLVED.

The custom sized images are created only at adding an image, so if you'd like to use custom size, you have to set it BEFORE you upload images to your gallery.
Posted on 3/1/11 3:12 PM in reply to Tamas Imrei.
Hi,

I am facing one problem regarding Thumbnails in Image Gallery portlet. I am using liferay 6.0.6 version.

I have some jpg file stored in the server machine and want to save this image in Image Gallery portlet. For that I read that jpg file and get the File object and add in Image Gallery portlet using IGImageLocalServiceUtil.addImage(.....) method.

The image is getting stored there but thumbnail is not created. When I click on that ,it shows the image properly.

After analyzing little bit, I found that small Image is not being created. Just wondering why?

If anybody knows the answer ,please help me.

Thanks in advance.
Nilesh
Posted on 11/22/11 6:43 AM in reply to Tamas Imrei.