ImgscalrImageManipulator extends AbstractImageManipulator { protected BufferedImage crop(BufferedImage originalImage, ImageRect cropArea) { if (cropArea != null) { cropArea.validateCropBounds(originalImage.getWidth(), originalImage.getHeight()); try { BufferedImage image = Scalr.crop(originalImage, cropArea.getStartX(), cropArea.getStartY(), cropArea.getWidth(), cropArea.getHeight()); originalImage.flush(); return image; } catch (IllegalArgumentException e) { throw error(BAD_REQUEST, "image_error_cropping_failed", e); } } return originalImage; } 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(expected = GenericRestException.class) public void testCropStartOutOfBounds() throws Exception { BufferedImage bi = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB); manipulator.crop(bi, new ImageManipulationParametersImpl().setRect(500, 500, 20, 25).getRect()); }
@Test(expected = GenericRestException.class) public void testCropAreaOutOfBounds() throws Exception { BufferedImage bi = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB); manipulator.crop(bi, new ImageManipulationParametersImpl().setRect(1, 1, 400, 400).getRect()); }
@Test public void testCropImage() { BufferedImage bi = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB); BufferedImage outputImage = manipulator.crop(bi, null); assertEquals(100, outputImage.getWidth()); assertEquals(200, outputImage.getHeight()); assertEquals("No cropping operation should have occured", bi.hashCode(), outputImage.hashCode()); bi = new BufferedImage(100, 200, BufferedImage.TYPE_INT_ARGB); outputImage = manipulator.crop(bi, new ImageManipulationParametersImpl().setRect(1, 1, 20, 25).getRect()); assertEquals(25, outputImage.getWidth()); assertEquals(20, outputImage.getHeight()); }