1

I am using ImageQuick Tool to compress the DAM images. I am using below snippet for conversion.

try {
            System.out.println(" Image is Processing :: " + assetDetails.getName() + "Original Size :: " + assetDetails.getSize());
            ProcessBuilder pb = new ProcessBuilder("C:\\Program Files\\ImageMagick-6.9.9-Q16\\convert.exe", "-quality", "85%", assetDetails.getAssetNode().getPath(), assetDetails.getAssetNode().getPath());
            pb.redirectErrorStream(true);

            Process p = pb.start();
            BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
            System.out.println(p.waitFor());
            session.save();

        } catch (final IOException | RepositoryException | InterruptedException ex) {
            ex.printStackTrace();
        }

Getting an error as below :

 Image is Processing :: A.jpgOriginal Size :: 323.8 KB
convert.exe: unable to open image `/content/dam/A.jpg': No such file or directory @ error/blob.c/OpenBlob/2761.
convert.exe: no images defined `/content/dam/A.jpg' @ error/convert.c/ConvertImageCommand/3258.

Here code is looking for the file from /content/dam from local. How can I do this operation on existing images.

In case, I add the server name before path, I am getting below error :

convert.exe: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.
convert.exe: no data returned `http://localhost:4502/content/dam/A.jpg' @ error/url.c/ReadURLImage/247.
convert.exe: no images defined `http://localhost:4502/content/dam/A.jpg' @ error/convert.c/ConvertImageCommand/3258.

PFA* enter image description here

3
  • Why did you tag it with aem? Seems to be unrelated, look at the tag description Commented Apr 17, 2018 at 10:57
  • Actually, Assets are hosted on AEM server. Commented Apr 17, 2018 at 11:07
  • You seem to be using the wrong path (a linux path, not a windows path), make sure you use the right path. Commented Apr 17, 2018 at 13:32

1 Answer 1

1

The path /content/dam/A.jpg is relative to the JCR repository, not to the actual file system, so an image not found exception is launched. Also the hardcoded value of your ImageMagick installation path, "C:\\Program Files\\ImageMagick-6.9.9-Q16\\convert.exe doesn't seem too flexible IMHO, as it will be probably different in other environments (test, pre-prod, prod, ...).

Actually, if you want to use IM to improve image compression, I would recommend you to add custom Process Steps to the DAM Update Asset workflow.

For example, for creating a fixed 1140x1140 PNG compressed rendition I would use:

<node1
        jcr:primaryType="cq:WorkflowNode"
        description="This process step uses IM PNG compression."
        title="IM PNG Mime Type"
        type="PROCESS">
        <metaData
            jcr:primaryType="nt:unstructured"
            COMMANDS="convert ${directory}/${filename} -resize 1140x1140> -strip -depth 24 -define png:compression-filter=2 -define png:compression-level=9 -define png:compression-strategy=1 cq5dam.web.1140.1140.${extension}"
            MIME_TYPES="image/png"
            PROCESS="com.day.cq.dam.core.process.CommandLineProcess"
            PROCESS_AUTO_ADVANCE="true"/>
</node1>

You can read more about the command in the IM doc and if you are interesting on integrating this in the OOTB AEM workflow, take the node model content from above as an example or take a look at this pretty well described AEM Assets - best practices article.

5
  • 1
    i support the recommendation to use the DAM Update Asset workflow for compression.
    – Jens
    Commented Apr 17, 2018 at 14:36
  • I have checked this earlier. Let say we have already GBs of image files in DAM. In case If I update workflow, how can i achieve the image compression on existing files? Commented Apr 17, 2018 at 18:24
  • Create a java process to query the assets uploaded before a certain date (e.g today) and rerun the DAM Update Asset workflow on them.
    – iusting
    Commented Apr 18, 2018 at 7:56
  • I tried the same, added command to compress the jpeg image. PFA*. I am getting an error : 23.04.2018 17:06:23.951 ERROR [JobHandler: /etc/workflow/instances/server0/2018-04-23_2/update_asset_4:/content/dam/Image-Quality.jpg/jcr:content/renditions/original] com.day.cq.dam.core.process.CommandLineProcess execute: failed to execute command [convert -define jpeg:size=319x319 Image-Quality.jpg -thumbnail 319x319 cq5dam.thumbnail.319.319.png] for asset [/content/dam/Image-Quality.jpg]: org.apache.commons.exec.ExecuteException: Process exited with an error: 4(Exit value: 4) Commented Apr 23, 2018 at 11:43
  • 1
    That's caused by your OS. The convert command may not run with certain Windows versions (for example Windows SE), because it conflicts with the native convert utility that is part of Windows installation. Replace 'convert' with the complete path of the ImageMagick utility: e.g "C:\Program Files\ImageMagick-6.9.9-Q16\convert.exe". Does it work?
    – iusting
    Commented Apr 23, 2018 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.