use of com.squareup.pollexor.ThumborUrlBuilder in project picasso by square.
the class PollexorRequestTransformer method transformRequest.
@Override
public Request transformRequest(Request request) {
if (request.resourceId != 0) {
// Don't transform resource requests.
return request;
}
Uri uri = request.uri;
String scheme = uri.getScheme();
if (!"https".equals(scheme) && !"http".equals(scheme)) {
// Thumbor only supports remote images.
return request;
}
if (!request.hasSize()) {
// Thumbor only works with resizing images.
return request;
}
// Start building a new request for us to mutate.
Request.Builder newRequest = request.buildUpon();
// Create the url builder to use.
ThumborUrlBuilder urlBuilder = thumbor.buildImage(uri.toString());
// Resize the image to the target size.
urlBuilder.resize(request.targetWidth, request.targetHeight);
newRequest.clearResize();
// If the center inside flag is set, perform that with Thumbor as well.
if (request.centerInside) {
urlBuilder.fitIn();
newRequest.clearCenterInside();
}
// If the Android version is modern enough use WebP for downloading.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
urlBuilder.filter(format(ImageFormat.WEBP));
}
// Update the request with the completed Thumbor URL.
newRequest.setUri(Uri.parse(urlBuilder.toUrl()));
return newRequest.build();
}
Aggregations