开发者

Google App Engine & Java : images thumb

开发者 https://www.devze.com 2023-03-05 14:30 出处:网络
I\'m trying to resize and crop images into Google App engine in order to create thumbnails I would like to be able to create 200x150 thumbs from any size.

I'm trying to resize and crop images into Google App engine in order to create thumbnails

I would like to be able to create 200x150 thumbs from any size.

This is the code I'm using so far now I need to crop it so it doesn't go bigger than 200x150:

    Image oldImage = ImagesServiceFactory.makeImage(picture);
    //Create the Image Service Factory and the Resize Transform
    ImagesService imagesService = ImagesServiceFactory.getImagesService();
    int w = 0;
    int h = 0;
    if (oldImage.getWidth() &g开发者_JS百科t; oldImage.getHeight()) {
        w = 1000;
        h = height;
    } else {
        h = 1000;
        w = width;
    }
    Transform resize = ImagesServiceFactory.makeResize(w, h);
    //Resize The Image using the transform created above
    Image resizedImage = imagesService.applyTransform(resize, oldImage);

    Transform crop = ImagesServiceFactory.makeCrop(0.0, 0.0, width / resizedImage.getHeight(), height / resizedImage.getHeight());

    Image cropedImage = imagesService.applyTransform(crop, resizedImage);

    //Serve the newly transformed image
    return cropedImage.getImageData();

Thanks !


I serve thumbnails with google app engine dynamically using getServingUrl

That can resize and crop storing only one image doing the resize and crop dynamically. Since I'm very satisfied with that solution I hope it can work for you too.


Your oldImage is less than 200px wide.

0

精彩评论

暂无评论...
验证码 换一张
取 消