Skip navigation
Currently Being Moderated

Re-size an image in using the Image class?

Jul 23, 2012 6:16 PM

Is there a way to resize an image using the class?  I wanted to extend the foundation image componet and have it resize to a specific height and width.  Is there a way to change the size of the image before you call image.draw(out) ?

  • Currently Being Moderated
    Jul 23, 2012 6:34 PM   in reply to stewa52

    Try using ImageHelper to get a resized layer & then apply


    Mark as:
  • Currently Being Moderated
    Jul 25, 2012 12:30 AM   in reply to stewa52

    You also don't want to insert you resizing efforts prior to calling the image.draw method. The draw method doesn't actually render the image,  it draws the HTML img tag that your components print out. If you were to use the ImageHelper to get the layer and resize it that would not actually change the size of the image.


    Now that img tag will contain a URL to the image, and that URL will generally look something like this (unless you have customized your image components):


    /path/to/your/page/_jcr_content/par/textimage/image.img.jpg/1323947520 848.jpg


    This URL is going to trigger a script or servlet that will be responsible for rendering the image. In the example above because the textimage component extends the parbase component and because URL includes the img selector it will end up triggering the servlet at /libs/foundation/components/parbase/ If you go into CRXDE Lite you can go to this file and look at the source code of this servlet and see an example of how it uses the layer to resize the image if that author edited the image in the smart image widget.


    You can also see example of servlets that resize and image ot specific preset sizes (as you want to do) you can look at /apps/geometrixx-outdoors/components/product/image/ and /apps/geometrixx-outdoors/components/product/image/


    So what you would want to do is something like this:

    1. Create your own component at /apps/mysite/components/foo
    2. Create a servlet at /apps/mysite/components/foo/ - put your logic to resize the image here based on some of the examples
    3. Create your component JSP at /apps/mysite/components/foo/foo.jsp
    4. Create your component's dialog and in this dialog include a smart image widget - make sure you store your image on component node, not a sub-node. If you store your image on a sub-node you need to make sure the sub-node includes the same resource type as your main node).
    5. In your component JSP when you create your foundation Image object make sure to image.setSelector("bar") before you call image.draw()


    That should result in an image URL that looks like /path/to/your/page/_jcr_content/par/textimage/ 0848.jpg


    Those steps aren't tested - so I may have missed something or mistyped something, but it should point you in the right direction.

    Mark as:
  • Currently Being Moderated
    Jul 29, 2012 7:01 PM   in reply to orotas

    Good info. Thanks for right direction.

    Mark as:
  • Currently Being Moderated
    May 20, 2013 6:44 AM   in reply to Sham HC

    There is a default servlet available which does resizing, you can find this here

    /libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/prof ile/impl/

    This works fine if you use default version and call image like this

    <img  src="/content/dam/geometrixx/portraits/ ail.jpg">

    I have created another thread for extension of this servlet, please view the following thread

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points