0
votes

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.

  • DAM Update Asset Workflow

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.

  • 3rd Party API

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 :

enter image description here

Web enabled rendition process step is as follows :

enter image description here

Problem :

  • Image size does not getting compress and size increased from 206KB to 208KB.

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?

1
Imagemagick is more secure that people think. Its so called vulnerabilities are due to the user not setting their policy.xml file appropriately secure. The policy.xml file is there to be used for that and has been there for a long time. See policy.xml at imagemagick.org/script/resources.php. Also see -define jpeg:extent={size} at imagemagick.org/Usage/formats/#jpg_write for writing jpg file to a given file size. Perhaps that is what you want. - fmw42
Hi, I tried imagemagick. Updating question regarding changes i have done. - Vivek Dhiman
I'm confused. You say you have PNG images, then you try and reduce the size using -define JPEG:... which doesn't apply unless you write a JPEG yet you also say you can't accept any loss of quality - which is inevitable if you use JPEG. Please clarify. Also, it seems odd to be trying to reduce sizes when storage is only getting cheaper. - Mark Setchell
I am uploading jpeg image and output is the png. - Vivek Dhiman
-define jpg:size is fine for reading a jpg. See imagemagick.org/Usage/formats/#jpg_read. When writing jpg, you need to use -define jpg:extent. The issue is that you are lossy decompressing a small jpg, which makes the file size larger and then writing to a losslessly compressed PNG. Therefore the output PNG file size will be larger than the input jpg unless you resize the image (-thumbnail) small enough and remove any meta data. Sorry I know nothing about AEM. - fmw42

1 Answers

0
votes

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);
    }

     }