Reputation: 1997
We have plenty of png images in DAM. We want to compress these images in such a way that their quality/resolution should not compromise. I have gone through several options and want to know the best one.
We are on AEM 6.0 and wondering whether this features will work well in 6.0 version. Moreover, This tool have some vulnerabilities as well.
We can update the workflow to add our custom code block and by using JAVA7 IO api we can perform the compression. Also can we add a new process step at first stage so that can compress the images as first operation when this workflow initiate. Any other thoughts are welcome.
Are there any third party API where using CURL we can compress the images apart from TinyPNG.
Have started using ImageMagick on 6.0:
EPS thumbnails (powered by ImageMagick) Step is as follows :
Web enabled rendition process step is as follows :
Problem :
AEM Logs says :
13.04.2018 15:05:43.111 *INFO* [JobHandler: /etc/workflow/instances/server0/2018-04-13_1/update_asset_439:/content/dam/A.jpg/jcr:content/renditions/original] com.day.cq.dam.core.process.CommandLineProcess execute: executing command line ["C:\Program Files\ImageMagick-6.9.9-Q16\convert.exe" -depth 8 -define jpeg:size=319x319 A.jpg -thumbnail 319x319 cq5dam.thumbnail.319.319.png] for asset [/content/dam/A.jpg]. (Size is 208KB of thumbnail generated)
If I run Locally, I can see the file size reduced to 130KB.
"C:\Program Files\ImageMagick-6.9.9-Q16\convert.exe" -depth 8 -define jpeg:size=319x319 A.jpg -thumbnail 319x319 cq5dam.thumbnail.319.319.png
Any Idea why image in not compressing on AEM?
Upvotes: 0
Views: 2247
Reputation: 2021
You need to write a servlet which will dynamically compress the size of the image such a way that the quality and resolution is maintained.
public class YourServlet extends AbstractImageServlet {
protected Layer createLayer(AbstractImageServlet.ImageContext imageContext)
throws RepositoryException, IOException {
Layer resized = ImageHelper.resize(layer, new Dimension(), new Dimension(0, 0),
new Dimension(768, 768));
}
protected void writeLayer(SlingHttpServletRequest request, SlingHttpServletResponse response,
AbstractImageServlet.ImageContext context, Layer layer, double quality)
throws IOException, RepositoryException {
super.writeLayer(request, response, context, layer, QUALITY);
}
}
Upvotes: 0