Page 1 of 1

AssetServer change quality of image while resizing

Posted: Wed Sep 11, 2013 7:36 am
by staleks
Hi all,

I have one strange request from client. I receive big images, and using AssetServer I was able to Resize image using folowing parameters:
width-amount=140, height-amount=140, high-quality=false and reduce-only=true

As a result I have a image constraint by width and height to 140px, highQuality is not applicable and in case that the image is less than 140px X 140px (which is not the case), image transformation won't be applied.

After image is transformed, actual physical size of an image is still big. It varies from 15 KB to 35 KB.
Client has the request that there can't be paging. As a result I have some subcategories with 160 products.
You can imagine that loading of images on those page takes 160 products * 20 KB > 3 MB. Now 100 users ... Yes a lot of network load :)

I came on idea that, if I can lower quality on transformed images (e.g. having 70% - 80% of original quality), size of a images will also reduce to 70% - 80% of current network load.

I've entered BLC framwork in "debug mode", found Resize.class
(org.broadleafcommerce.openadmin.server.service.artifact.image.effects.chain.filter.Resize.java)

There are couple of points, that I am willing to try to change, but I can't find a way to do that:

1. line 197

Code: Select all

g2.drawImage(ret.getScaledInstance(w, h, Image.SCALE_SMOOTH), 0, 0, w, h, null);


As you can see, Image.SCALE_SMOOTH is hardcoded, and I can't find a way to apply different `hint`

If I take a look at Image.java (java.awt.Image.java), there are different algorithms
like:
Image.SCALE_DEFAULT, Image.SCALE_FAST, ...

Is this possible to change?

2. Also, please note the following lines:
in default constructor,

Code: Select all

line 30: private RenderingHints hints;
line 34: private Object hint;


also full constrcutor

Code: Select all

line 43: this.hints = hints;
line 47: this.hint = RenderingHints.VALUE_INTERPOLATION_BICUBIC;


How I can try some different RenderingHints?

Please note that I've be using `blStaticMapNamedOperationComponent`.
Definition of thumb140 is given as follows:

Code: Select all

     <entry key="thumb140">
          <map>
               <entry key="resize-width-amount" value="140" />
               <entry key="resize-height-amount" value="140" />
               <entry key="resize-high-quality" value="false" />
               <entry key="resize-maintain-aspect-ratio" value="true" />
               <entry key="resize-reduce-only" value="true" />
          </map>
    </entry>


Thank you for Your help