glide icon indicating copy to clipboard operation
glide copied to clipboard

Any way to get centercrop or centerfit type?

Open rayboot opened this issue 11 years ago • 3 comments

Cause of I will post the centercrop or centerfit params to server. And the server will make transform. For example The Nginx have crop service,you could post the image url like http://the/image/path/someimage.jpg!t400x400.jpg and will return a 400X400 and centerCrop image.

How could I get the centerCrop or centerFit type?

rayboot avatar Aug 10 '15 08:08 rayboot

You have to roll your own because you can't know what transformations are applied to the request. What if it's CircleCrop and a WaterMark one after the other?

But don't worry it's kind of easy: https://github.com/bumptech/glide/wiki/Downloading-custom-sizes-with-Glide

You will need something like:

class MyDataModel {
    String url;
    ImageView.ScaleType scaleType;
    String buildUrl(int width, int height) {
        return this.url + transform(width, height);
    }
    String transform(int width, int height) {
        return scaleType == ScaleType.CENTER_CROP?
            String.format(Locale.ROOT, "!t%dx%d.%s", width, height, getExtension(url))
            : // TODO modify to switch-case if there are more options
            ""
        ;
    }
}

Here's how Glide maps ScaleType to default Transformations: https://github.com/bumptech/glide/blob/3.0/library/src/main/java/com/bumptech/glide/GenericRequestBuilder.java#L675

TWiStErRob avatar Aug 10 '15 09:08 TWiStErRob

When you say "post", do you mean "send/request" or "HTTP POST"?

TWiStErRob avatar Aug 10 '15 09:08 TWiStErRob

Thanks.

rayboot avatar Aug 11 '15 03:08 rayboot