コード例 #1
0
 @Test
 public void testChop() throws IOException {
   ChkType chkType = ChkType.CROP;
   String cropLeftX = "0.0";
   String cropTopY = "0.0";
   String cropRightX = "0.5";
   String cropBottomY = "0.5";
   Transform transform =
       ImagesServiceFactory.makeCrop(
           new Float(cropLeftX),
           new Float(cropTopY),
           new Float(cropRightX),
           new Float(cropBottomY));
   for (OutputEncoding encoding : ENCODES) {
     applyAndVerify("pngAttach.png", transform, chkType, encoding);
   }
 }
コード例 #2
0
 public byte[] process(byte[] data, ImageFormat format, ContentType type, float balance) {
   Image image = ImagesServiceFactory.makeImage(data);
   CompositeTransform tx = ImagesServiceFactory.makeCompositeTransform();
   if (format.isCrop()) {
     float w1 = image.getWidth();
     float h1 = image.getHeight();
     float w2 = format.getWidth();
     float h2 = format.getHeight();
     Crop c = new Crop(w1, h1, w2, h2, balance);
     tx.concatenate(ImagesServiceFactory.makeCrop(c.x, c.y, c.x + c.width, c.y + c.height));
   }
   tx.concatenate(ImagesServiceFactory.makeResize(format.getWidth(), format.getHeight()));
   try {
     ImagesService imagesService = ImagesServiceFactory.getImagesService();
     OutputEncoding outputEncoding = OutputEncoding.valueOf(type.name());
     return imagesService.applyTransform(tx, image, outputEncoding).getImageData();
   } catch (OverQuotaException e) {
     throw new ImageServiceException(e);
   }
 }