1 Reply Latest reply on May 23, 2013 11:38 PM by Veena_07

    How can to resize an image uploaded in to the smart image

    Veena_07 Level 3

      Hi

       

          I have an image uploaded into the smartimage from the local file system. How can i resize this file or create a rendition for this image?

       

       

      Thanks

      Veena

        • 1. Re: How can to resize an image uploaded in to the smart image
          Veena_07 Level 3

          Hi

           

             I got a reference for the same question from Stack Overflow http://stackoverflow.com/questions/14726485/resize-an-image-resource-in-cq5/16728970#16728 970

           

           

          I tried the same method

           

           

          Resource resourceNew = resource.getResourceResolver().getResource(img.getFileReference());

              Asset asset = resourceNew.adaptTo(Asset.class);

              log.error("asset ****" + asset);

              Layer layer = new Layer(asset.getOriginal().getStream());

              layer.resize(200, 200);

              log.error("layer ****" + layer);

             

             

                                  Image image = new Image(resource);

              String mimeType = image.getMimeType();

           

              ByteArrayOutputStream bout = null;

              ByteArrayInputStream bin = null;

           

           

              try {

                  bout = new ByteArrayOutputStream(2048);

                  layer.write(mimeType, 1, bout);

           

           

                  bin = new ByteArrayInputStream(bout.toByteArray());

           

           

                  asset.addRendition("resizedImage", bin, mimeType);

          log.error("asset Bin" + asset);

              } finally {

                  // close streams ...              

              }

           

           

           

          Where img is my Image object and I was able to create a rendition in the dam.

           

          But the rendition I am getting is in File format. Is there a way by which i can change it to png format??? any Help will be appreciable..

           

          Thanks

           

          Veena