ImgscalrImageManipulator extends AbstractImageManipulator { @Override public Single<String> handleResize(Binary binary, ImageManipulationParameters parameters) { parameters.validate(); parameters.validateLimits(options); BinaryDaoWrapper binaryDao = boot.binaryDao(); Supplier<InputStream> stream = binaryDao.openBlockingStream(binary); return getCacheFilePath(binary.getSHA512Sum(), parameters) .flatMap(cacheFileInfo -> { if (cacheFileInfo.exists) { return Single.just(cacheFileInfo.path); } else { return workerPool.<String>rxExecuteBlocking(bh -> { try ( InputStream is = stream.get(); ImageInputStream ins = ImageIO.createImageInputStream(is)) { BufferedImage image; ImageReader reader = getImageReader(ins); try { image = reader.read(0); } catch (IOException e) { log.error("Could not read input image", e); throw error(BAD_REQUEST, "image_error_reading_failed"); } if (log.isDebugEnabled()) { log.debug("Read image from stream " + ins.hashCode() + " with reader " + reader.getClass().getName()); } image = cropAndResize(image, parameters); String[] extensions = reader.getOriginatingProvider().getFileSuffixes(); String extension = ArrayUtils.isEmpty(extensions) ? "" : extensions[0]; String cacheFilePath = cacheFileInfo.path + "." + extension; File outCacheFile = new File(cacheFilePath); try (ImageOutputStream out = new FileImageOutputStream(outCacheFile)) { ImageWriteParam params = getImageWriteparams(extension); getImageWriter(reader, out).write(null, new IIOImage(image, null, null), params); } catch (Exception e) { throw error(BAD_REQUEST, "image_error_writing_failed"); } bh.complete(cacheFilePath); } catch (Exception e) { bh.fail(e); } }, false).toSingle(); } }); } ImgscalrImageManipulator(Vertx vertx, MeshOptions options, BootstrapInitializer boot);   ImgscalrImageManipulator(Vertx vertx, ImageManipulatorOptions options, BootstrapInitializer boot); @Override Single<String> handleResize(Binary binary, ImageManipulationParameters parameters); @Override int[] calculateDominantColor(BufferedImage image); @Override Single<Map<String, String>> getMetadata(InputStream ins);  }
@Test public void testResize() throws Exception { checkImages((imageName, width, height, color, refImage, path, bs) -> { log.debug("Handling " + imageName); Single<byte[]> obs = manipulator .handleResize(createMockedBinary(path), new ImageManipulationParametersImpl().setWidth(150).setHeight(180)) .map(file -> Files.readAllBytes(Paths.get(file))); CountDownLatch latch = new CountDownLatch(1); obs.subscribe(data -> { try { assertNotNull(data); try (ByteArrayInputStream bis = new ByteArrayInputStream(data)) { BufferedImage resizedImage = ImageIO.read(bis); String referenceFilename = "outputImage-" + imageName.replace(".", "_") + "-resize-reference.png"; assertThat(resizedImage).as(imageName).hasSize(150, 180).matchesReference(referenceFilename); } } catch (Exception e) { e.printStackTrace(); fail("Error occured"); } latch.countDown(); }); try { if (!latch.await(20, TimeUnit.SECONDS)) { fail("Timeout reached"); } } catch (Exception e) { throw new RuntimeException(e); } }); }