Roch
Roch

Reputation: 22051

Google App Engine & Java : images thumb

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() > 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 !

Upvotes: 1

Views: 1197

Answers (2)

Niklas Rosencrantz
Niklas Rosencrantz

Reputation: 26637

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.

Upvotes: 2

Chris Farmiloe
Chris Farmiloe

Reputation: 14185

Your oldImage is less than 200px wide.

Upvotes: 0

Related Questions