IT Certificaions

Google Cloud Platform

Thursday, September 6, 2012

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 ;
}