[Hippo-cms7-user] Improving image resizing quality (CMS image gallery)

Jasha Joachimsthal j.joachimsthal at onehippo.com
Mon Jun 14 09:53:58 CEST 2010


Cool :-)

Another thing for the committers: most of the methods in the ImageUtils are
private which makes it nearly impossible to extend the class without
copy-pasting a lot of them. Can they change from private to protected?

Jasha Joachimsthal

j.joachimsthal at onehippo.com - jasha at apache.org

www.onehippo.com
Amsterdam - Hippo B.V. Oosteinde 11 1017 WT Amsterdam +31(0)20-5224466
San Francisco - Hippo USA Inc. 185 H Street, suite B, Petaluma CA 94952 +1
(707) 7734646






On 11 June 2010 16:18, Arje Cahn <a.cahn at onehippo.com> wrote:

> Nice improvement, Kenan :)
>
> Could you try to turn that into a patch and send that to the
> mailinglist? Then one of our committers can apply your patch to the
> core codebase.
>
> Tx,
>
> Arjé Cahn
>
>
>
> On Fri, Jun 11, 2010 at 4:05 PM, Kenan Salic <k.salic at onehippo.com> wrote:
> > Hi,
> >
> > Mostly pictures that are uploaded and are re-sized to a smaller thumbnail
> > don't have nice quality. This offers a possible solution to improve the
> > quality a bit.
> >
> > ------------------
> > EXAMPLES:
> >
> > THUMBNAIL BEFORE
> >
> > THUMBNAIL AFTER
> >
> > CLICK HERE TO SEE MORE EXAMPLES (You have to click on some images to see
> the
> > actual picture)
> > -------------------
> >
> > The org.hippoecm.frontend.plugins.gallery.ImageUtils class resizes the
> image
> > with method createThumbnail()
> >
> > What I have done, is made an extension of the ImageUtils and overriden
> the
> > createThumbnail method by adding:
> >
> > if(resizeRatio < 0.6d){
> >       originalImage = resizeTrick(originalImage);
> >  }
> >
> > Before the scaling of the picture. This method is called upon if the
> resize
> > ratio is smaller than 0.6 (works the best with smaller pictures).
> >
> > the resizeTrick method:
> >
> > private BufferedImage resizeTrick(BufferedImage image){
> >        image = createCompatibleImage(image);
> >        image = blurImage(image);
> >        return image;
> >    }
> >
> >    private BufferedImage createCompatibleImage(BufferedImage image){
> >        GraphicsConfiguration gc =
> > BufferedImageGraphicsConfig.getConfig(image);
> >         int w = image.getWidth();
> >         int h = image.getHeight();
> >         BufferedImage result = gc.createCompatibleImage(w, h,
> > Transparency.TRANSLUCENT);
> >         Graphics2D g2 = result.createGraphics();
> >         g2.drawRenderedImage(image, null);
> >         g2.dispose();
> >         return result;
> >    }
> >
> >    private BufferedImage blurImage(BufferedImage image){
> >        float ninth = 1.0f/9.0f;
> >         float[] blurKernel = {
> >                 ninth, ninth, ninth,
> >                 ninth, ninth, ninth,
> >                 ninth, ninth, ninth
> >         };
> >
> >         Map<RenderingHints.Key, Object> map = new
> > HashMap<RenderingHints.Key, Object>();
> >
> >
> map.put(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
> >
> >
> map.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
> >
> >
> map.put(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
> >         RenderingHints hints = new RenderingHints(map);
> >         BufferedImageOp op = new ConvolveOp(new Kernel(3, 3, blurKernel),
> > ConvolveOp.EDGE_NO_OP, hints);
> >         return op.filter(image, null);
> >    }
> >
> >
> > What the snippet does, is blur the image by a ninth before scaling. This
> > will make the re-sized image look a bit better.
> >
> > Also what I have done in the createScaledImage method, added some
> > RenderHints before drawing the image:
> >
> >  Map<RenderingHints.Key, Object> map = new HashMap<RenderingHints.Key,
> > Object>();
> >
>  map.put(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
> >
>  map.put(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
> >
>  map.put(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
> >
> > g2d.setRenderingHints(map);
> >
> > -------------------
> > EXAMPLES:
> >
> > THUMBNAIL BEFORE
> >
> > THUMBNAIL IMPROVED
> >
> > CLICK HERE TO SEE MORE EXAMPLES (You have to click on some images to see
> the
> > actual picture)
> >
> > -----------------
> > Based upon this: blog
> >
> > Regards
> >
> > _______________________________________________
> > Hippo-cms7-user mailing list and forums
> > http://www.onehippo.org/cms7/support/forums.html
> >
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onehippo.org/pipermail/hippo-cms7-user/attachments/20100614/90ac6e95/attachment.htm>


More information about the Hippo-cms7-user mailing list