@Test public void simpleResizeWithEncryption() { Request input = new Request.Builder(IMAGE_URI).resize(50, 50).build(); Request output = secureTransformer.transformRequest(input); assertThat(output).isNotSameAs(input); assertThat(output.hasSize()).isFalse(); String expected = Thumbor.create(HOST, KEY).buildImage(IMAGE).resize(50, 50).toUrl(); assertThat(output.uri.toString()).isEqualTo(expected); }
@NonNull @Override public Request transformRequest(@NonNull Request request) { if (request.resourceId != 0) { return request; } Uri uri = request.uri; if (uri == null) { throw new IllegalArgumentException("Null uri passed to " + getClass().getCanonicalName()); } String scheme = uri.getScheme(); if (!"https".equals(scheme) && !"http".equals(scheme)) { return request; } if (!request.hasSize() && !alwaysTransform) { return request; } Request.Builder newRequest = request.newBuilder(); ThumborUrlBuilder urlBuilder = thumbor.buildImage(uri.toString()); if (request.hasSize()) { urlBuilder.resize(request.targetWidth, request.targetHeight); newRequest.clearResize(); } if (request.centerInside) { urlBuilder.fitIn(); newRequest.clearCenterInside(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { urlBuilder.filter(format(ImageFormat.WEBP)); } newRequest.setUri(Uri.parse(urlBuilder.toUrl())); return newRequest.build(); }
PollexorRequestTransformer implements RequestTransformer { @NonNull @Override public Request transformRequest(@NonNull Request request) { if (request.resourceId != 0) { return request; } Uri uri = request.uri; if (uri == null) { throw new IllegalArgumentException("Null uri passed to " + getClass().getCanonicalName()); } String scheme = uri.getScheme(); if (!"https".equals(scheme) && !"http".equals(scheme)) { return request; } if (!request.hasSize() && !alwaysTransform) { return request; } Request.Builder newRequest = request.newBuilder(); ThumborUrlBuilder urlBuilder = thumbor.buildImage(uri.toString()); if (request.hasSize()) { urlBuilder.resize(request.targetWidth, request.targetHeight); newRequest.clearResize(); } if (request.centerInside) { urlBuilder.fitIn(); newRequest.clearCenterInside(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { urlBuilder.filter(format(ImageFormat.WEBP)); } newRequest.setUri(Uri.parse(urlBuilder.toUrl())); return newRequest.build(); } }
PollexorRequestTransformer implements RequestTransformer { @NonNull @Override public Request transformRequest(@NonNull Request request) { if (request.resourceId != 0) { return request; } Uri uri = request.uri; if (uri == null) { throw new IllegalArgumentException("Null uri passed to " + getClass().getCanonicalName()); } String scheme = uri.getScheme(); if (!"https".equals(scheme) && !"http".equals(scheme)) { return request; } if (!request.hasSize() && !alwaysTransform) { return request; } Request.Builder newRequest = request.newBuilder(); ThumborUrlBuilder urlBuilder = thumbor.buildImage(uri.toString()); if (request.hasSize()) { urlBuilder.resize(request.targetWidth, request.targetHeight); newRequest.clearResize(); } if (request.centerInside) { urlBuilder.fitIn(); newRequest.clearCenterInside(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { urlBuilder.filter(format(ImageFormat.WEBP)); } newRequest.setUri(Uri.parse(urlBuilder.toUrl())); return newRequest.build(); } PollexorRequestTransformer(@NonNull Thumbor thumbor);  PollexorRequestTransformer(@NonNull Thumbor thumbor, boolean alwaysTransform); }
PollexorRequestTransformer implements RequestTransformer { @NonNull @Override public Request transformRequest(@NonNull Request request) { if (request.resourceId != 0) { return request; } Uri uri = request.uri; if (uri == null) { throw new IllegalArgumentException("Null uri passed to " + getClass().getCanonicalName()); } String scheme = uri.getScheme(); if (!"https".equals(scheme) && !"http".equals(scheme)) { return request; } if (!request.hasSize() && !alwaysTransform) { return request; } Request.Builder newRequest = request.newBuilder(); ThumborUrlBuilder urlBuilder = thumbor.buildImage(uri.toString()); if (request.hasSize()) { urlBuilder.resize(request.targetWidth, request.targetHeight); newRequest.clearResize(); } if (request.centerInside) { urlBuilder.fitIn(); newRequest.clearCenterInside(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { urlBuilder.filter(format(ImageFormat.WEBP)); } newRequest.setUri(Uri.parse(urlBuilder.toUrl())); return newRequest.build(); } PollexorRequestTransformer(@NonNull Thumbor thumbor);  PollexorRequestTransformer(@NonNull Thumbor thumbor, boolean alwaysTransform); @NonNull @Override Request transformRequest(@NonNull Request request); }
PollexorRequestTransformer implements RequestTransformer { @NonNull @Override public Request transformRequest(@NonNull Request request) { if (request.resourceId != 0) { return request; } Uri uri = request.uri; if (uri == null) { throw new IllegalArgumentException("Null uri passed to " + getClass().getCanonicalName()); } String scheme = uri.getScheme(); if (!"https".equals(scheme) && !"http".equals(scheme)) { return request; } if (!request.hasSize() && !alwaysTransform) { return request; } Request.Builder newRequest = request.newBuilder(); ThumborUrlBuilder urlBuilder = thumbor.buildImage(uri.toString()); if (request.hasSize()) { urlBuilder.resize(request.targetWidth, request.targetHeight); newRequest.clearResize(); } if (request.centerInside) { urlBuilder.fitIn(); newRequest.clearCenterInside(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { urlBuilder.filter(format(ImageFormat.WEBP)); } newRequest.setUri(Uri.parse(urlBuilder.toUrl())); return newRequest.build(); } PollexorRequestTransformer(@NonNull Thumbor thumbor);  PollexorRequestTransformer(@NonNull Thumbor thumbor, boolean alwaysTransform); @NonNull @Override Request transformRequest(@NonNull Request request);  }