Google App Engine& Java:图像拇指

时间:2011-05-13 19:59:35

标签: java google-app-engine resize thumbnails

我正在尝试调整大小并将图片裁剪到Google App引擎中以创建缩略图

我希望能够创建任意大小的200x150拇指。

这是我目前使用的代码,现在我需要裁剪它,因此它不会超过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();

谢谢!

2 个答案:

答案 0 :(得分:2)

我使用getServingUrl

动态提供谷歌应用引擎的缩略图

这可以调整大小并裁剪只存储一张图像进行调整大小并动态裁剪。因为我对这个解决方案非常满意,所以我希望它也适合你。

答案 1 :(得分:0)

您的oldImage宽度小于200px。