Generating preview image thumbnails with liferay default configuration

Posted on 26/05/2016 by Charalampos Chrysikopoulos

This seems to be, even now, a subject without a specific documentation. The need of thumbnails is very common especially if you are showing content with images in a public url with a lot of traffic.

Liferay comes with PDFBox build in, that can create images for certain image types. Of course, you can use a lot of extra tools like ImageMagick, or Xuggler to create more sophisticated thumbnails, not only for images, but also for pdfs, documents etc. Have a look <a href=""_blank">here.

In our case, the needs are small. We have jpg images, and we need to have two custom thumbnails for them:

  • 180 x 252
  • 280 x 187

Also, we have already a URL in some of our portlets, that has the form:


This url is generated by the class
String com.liferay.portlet.documentlibrary.util.DLUtil.getPreviewURL(FileEntry fileEntry, FileVersion fileVersion, ThemeDisplay themeDisplay, String queryString, boolean appendVersion, boolean absoluteURL)

After a lot of reading in the forum, and after a lot of trying, I came to this conclusion (without being very confident about it):

  • First thing is to define your thumbnails in the
  • We add the parameter imageThumbnail in out url with the value 2 for the custom1 thumbnail and with the value 3 for the custom2 thumbnail. So our url now, looks like

It is so simple.


Ok, but in all articles I 've read, everybody is defining only 2 custom thumbnails. What if I want to defined 6 of them?
Hm, I don't know the answer. Everything I tried, didn't worked out. Defining another custom3 thumbnails in the properties, didn't work with adding the value 4 in the imageThumbnail parameter.

Havig a better look at the class com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor, it seems that you can use only those two properties, and no more than this. So, the number of the optionally custom thumbnails are exact 2.

I found this article in the web, which is describing a way (with an et plugin) to have more than 2 thumbnails.

There are two properties dl.file.entry.thumbnail.max.width and dl.file.entry.thumbnail.max.height. What if I change them?
Changing them, would affect the thumbnails in the document & media portlet in the control panel. It would eventually break the layout.

How can I recreate the thumbnails of my images?
There is a button in the control panel / Configuration / Server Administration / Resources with the name "Reset preview and thumbnail files for Documents and Media portlet."
The description for that is:

Reset preview and thumbnail files for the Documents and Media portlet: You can send in a request to reset the preview and thumbnail files for each item in your portal’s Documents and Media libraries.

The code that is running in the background. deletes two directories in the file system:

public static void deleteFiles() {
long[] companyIds = PortalUtil.getCompanyIds();
for (long companyId : companyIds) {
try {
catch (Exception e) {
try {
catch (Exception e) {

If you want to generate them programmatically, you could use the following method:
ImageProcessorUtil.generateImages(null, imageFileEntry.getFileVersion());

If you need to check the existence of the thumbnails for a specific image you could call the following method:

Some sources from the forum

This entry was posted in Uncategorized and tagged liferay 6.2, thumbnails by Charalampos Chrysikopoulos

Add new comment