Generating preview image thumbnails with liferay default configuration
Posted on
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 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
- First thing is to define your thumbnails in the portal-ext.properties: [cc lang="properties"] dl.file.entry.thumbnail.custom1.max.width=180 dl.file.entry.thumbnail.custom2.max.height=252 dl.file.entry.thumbnail.custom2.max.width=280 dl.file.entry.thumbnail.custom2.max.height=187 [/cc]
- 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 [cc lang="html"] /portal/documents/178201/495116/image.jpg/ac34c05e-5ad5-4704-b006-7cdd182dc1a3?version=1.0&t=1464246512402&imageThumbnail=2 [/cc]
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: [cc lang="java"] public static void deleteFiles() { long[] companyIds = PortalUtil.getCompanyIds(); for (long companyId : companyIds) { try { DLStoreUtil.deleteDirectory( companyId, REPOSITORY_ID, PREVIEW_PATH); } catch (Exception e) { } try { DLStoreUtil.deleteDirectory( companyId, REPOSITORY_ID, THUMBNAIL_PATH); } catch (Exception e) { } } } [/cc] If you want to generate them programmatically, you could use the following method: [cc lang="java"] ImageProcessorUtil.generateImages(null, imageFileEntry.getFileVersion()); [/cc] If you need to check the existence of the thumbnails for a specific image you could call the following method: [cc lang="java"] ImageProcessorUtil.hasImages(imageFileEntry.getFileVersion()) [/cc] Some sources from the forum
This entry was posted in Uncategorized and tagged liferay 6.2, thumbnails by Charalampos Chrysikopoulos