1 Reply Latest reply on Jul 2, 2013 3:49 PM by orotas

    Image optimization before original gets uploaded


      Hello guys! I wrote a script that does several image optimizations (like taking out exif information, palette reductions, etc), something similar at what smush-it does. I want to integrate it to DAM, but the only way I found out so far was to generate a new image with a different name (like thumbnails are created). Do you know if there's a way to intercept the original image before it gets uploaded? I want to do my optimizations even before thumbnail generation.


      Thanks and regards

        • 1. Re: Image optimization before original gets uploaded
          orotas Experience Cloud MVP

          One thing to consider is not to intercept it but to add you code as one of the first steps in the update asset workflow. You would create a workflow process step and insert after probably the first step before the meta-data extraction step.


          In your workflow process step you need to do a little JCR manipulation to update the original rendition node.


          Once you have made your changes to the image you will want to convert it to an Input Stream.


          Then you will need to get JCR Value Factory from the JCR Session






          If you are doing this in a workflow process step you should be able to the get the session through either the resource of the DAM asset or the workflow session.


          Once you have value factory you use it to create a new Binary object (http://www.day.com/maven/javax.jcr/javadocs/jcr-2.0/javax/jcr/Binary.html). Then get a new Value object from the value factory based on the binary object.


          Once you have the value object you need to get the JCR Node for the original rendition (which you should already have if you were manipulating the file). You then get the child node named jcr:content and you set the jcr:data property to be the new Value object and save the session. That should replace the original binary and from that point on all the other DAM functionality should work. As intended.


          You might want to consider copying the update asset workflow, making your changes and then changing the launcher configs to point to your workflow instead of the out of the box one just for clarity.