Google App engine: Image Scaling


You can use following app engine classes to resize images using Java.
-------------------------------------------------------------------------


import com.google.appengine.api.images.Image;
import com.google.appengine.api.images.ImagesService;
import com.google.appengine.api.images.ImagesServiceFactory;
import com.google.appengine.api.images.Transform;
----------------------------------------------------------------------




public  byte[]  resizedImage(byte[] oldImageData,int width,int height) throws IOException{

ImagesService imagesService = ImagesServiceFactory.getImagesService();
        Image oldImage = ImagesServiceFactory.makeImage(oldImageData);
        log.info(this.getClass()+":oldImage height:"+oldImage.getHeight()+" and width:"+oldImage.getWidth());
       Transform resize = ImagesServiceFactory.makeResize(width,height);
        Image newImage = imagesService.applyTransform(resize, oldImage);
        byte[] newImageData = newImage.getImageData();
       
        log.info(this.getClass()+"After resize newImage height:"+newImage.getHeight()+" and width:"+newImage.getWidth());

      

        return  newImageData ;
}

Comments

Popular posts from this blog

Read Images from a xlsx file using Apache POI

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

How to create mail message in FRC822 format