use of com.enonic.xp.image.Cropping in project xp by enonic.
the class ImageContentProcessor method updateImageMetadata.
private ExtraDatas updateImageMetadata(final EditableContent editable) {
final Media media = (Media) editable.source;
final Attachment mediaAttachment = media.getMediaAttachment();
if (mediaAttachment == null) {
return editable.extraDatas;
}
final ByteSource binary = contentService.getBinary(editable.source.getId(), mediaAttachment.getBinaryReference());
if (binary == null) {
return editable.extraDatas;
}
final BufferedImage image = toBufferedImage(binary);
final Cropping cropping = media.getCropping();
final long byteSize = mediaAttachment.getSize();
final long imageWidth;
final long imageHeight;
final long imageSize;
if (cropping == null || cropping.isUnmodified()) {
imageWidth = image.getWidth();
imageHeight = image.getHeight();
imageSize = imageWidth * imageHeight;
} else {
final BufferedImage croppedImage = cropImage(image, cropping);
imageWidth = croppedImage.getWidth();
imageHeight = croppedImage.getHeight();
imageSize = imageWidth * imageHeight;
}
ExtraData extraData = editable.extraDatas.getMetadata(MediaInfo.IMAGE_INFO_METADATA_NAME);
if (extraData != null) {
final PropertyTree xData = extraData.getData();
setLongProperty(xData, IMAGE_INFO_PIXEL_SIZE, imageSize);
setLongProperty(xData, IMAGE_INFO_IMAGE_HEIGHT, imageHeight);
setLongProperty(xData, IMAGE_INFO_IMAGE_WIDTH, imageWidth);
setLongProperty(xData, MEDIA_INFO_BYTE_SIZE, byteSize);
}
return editable.extraDatas;
}
use of com.enonic.xp.image.Cropping in project xp by enonic.
the class ImageServiceImplTest method testReadImageWithCache.
@Test
public void testReadImageWithCache() throws IOException {
Cropping cropping = Cropping.create().top(0.25).bottom(0.75).left(0.25).right(0.75).zoom(2).build();
final ReadImageParams readImageParams = ReadImageParams.newImageParams().contentId(contentId).binaryReference(binaryReference).cropping(cropping).scaleSize(128).filterParam("blur(10)").mimeType("image/jpeg").backgroundColor(0xFF0000).quality(5).orientation(ImageOrientation.BottomLeft).build();
ByteSource imageData = imageService.readImage(readImageParams);
assertArrayEquals(ByteStreams.toByteArray(getClass().getResourceAsStream("processed.jpg")), imageData.read());
Mockito.verify(imageFilter).apply(any());
imageData = imageService.readImage(readImageParams);
assertArrayEquals(ByteStreams.toByteArray(getClass().getResourceAsStream("processed.jpg")), imageData.read());
Mockito.verify(imageFilter).apply(any());
}
Aggregations