Purpose:
Document and Media Portlet provides the feature to upload images in the Liferay portal. Which can be used for multiple purposes. This document is used to generate more than 2 thumbnail images automatically on upload image to document and media portlet.
Requirement:
Document and Media portlet generated a single thumbnail image for any uploaded image. I need to generate multiple thumbnails with different sizes as well.Existing Feature:
Liferay provided properties to automatically generate two thumbnail images for any uploaded images. As we need to generate 2 thumbnail image 320 x 240 and 480 x 600 respectively. Add the following properties in the portal-ext.properties: dl.file.entry.thumbnail.enabled=true dl.file.entry.thumbnail.custom1.max.width=320 dl.file.entry.thumbnail.custom1.max.height=240 dl.file.entry.thumbnail.custom2.max.width=480 dl.file.entry.thumbnail.custom2.max.height=600 To check generated images. First, go to document and media portlet then click on uploaded image. You will see the below-given page. Right click on the small image preview and click on ‘Inspect’ or ‘Inspect element’. It will opens developer tool and highlight <img> tag and in src attribute you will see url something like: <img> Tag: <img alt="Thumbnail" border="no" class="thumbnail" src="http://localhost:8080/documents/30503/0/Ruby+Hood/97fc65f8-b8ea-444c-b553-771694086beb?version=1.1&t=1497270260000&imageThumbnail=1" style="max-height: 135px; max-width: 135px;"> URL: http://localhost:8080/documents/30503/0/Ruby+Hood/97fc65f8-b8ea-444c-b553-771694086beb?version=1.1&t=1497270259984&imageThumbnail=1 In the above-listed URL, you can see that there is one parameter &imageThumbnail=1 appended at the end of the URL. To check thumbnail just copy paste that URL to new tab and change the &imageThumbnail=1 value to &imageThumbnail=2. You can see the same image with different size. This is the existing feature provided by Liferay document and media portlet.Extended Existing Feature using ext-plugin:
Liferay provides only two properties for generating the thumbnail. To generate more than 2 thumbnail image we need to extend existing functionality. com.liferay.portlet.documentlibrary.util.DLPreviewableProcessor class has following methods to change in.- storeThumbnailImages(FileVersion fileVersion, RenderedImage renderedImage)
- storeThumbnailImage(FileVersion fileVersion, RenderedImage renderedImage, int index)
Steps to Extend Existing Functionality using ext-plugin:
- Create ext-plugin.
- Create any custom class lets say MyImageProcessorImpl which extends ‘DLPreviewableProcessor’ abstract class and implements ‘ImageProcessor’ interface.
- Override all the methods and change in below given two methods(find in blue) as shown in methods. they are list at the end of the document.
- storeThumbnailImages(FileVersion fileVersion, RenderedImage renderedImage)
- storeThumbnailImage(FileVersion fileVersion, RenderedImage renderedImage, int index)
- Create ‘portal-ext.properties’ in WEB-INF/ext-impl/src path and add below given properties
- dl.file.entry.processors=com.liferay.portlet.documentlibrary.util.AudioProcessorImpl,com.liferay.portlet.documentlibrary.util.PDFProcessorImpl,com.liferay.portlet.documentlibrary.util.RawMetadataProcessorImpl,com.liferay.portlet.documentlibrary.util.VideoProcessorImpl,com.liferay.portlet.documentlibrary.util.VideoProcessorImpl,com.custom.portlet.documentlibrary.util.MyImageProcessorImpl
- Note: Replaced com.custom.portlet.documentlibrary.util.MyImageProcessorImpl with com.portlet.documentlibrary.util.ImageProcessorImpl
- dl.file.entry.thumbnail.custom3.max.width=640
- dl.file.entry.thumbnail.custom3.max.height=960
- dl.file.entry.thumbnail.custom4.max.width=1280
- dl.file.entry.thumbnail.custom4.max.height=720
- dl.file.entry.thumbnail.custom5.max.width=1600
- dl.file.entry.thumbnail.custom5.max.height=900
- dl.file.entry.thumbnail.custom6.max.width=1900
- dl.file.entry.thumbnail.custom6.max.height=1280
- Deploy ext-plugin.
No comments:
Post a Comment