use of org.structr.web.entity.Image in project structr by structr.
the class ImageHelper method getOrientation.
public static int getOrientation(final File originalImage) {
try {
final ExifIFD0Directory exifIFD0Directory = getMetadata(originalImage).getFirstDirectoryOfType(ExifIFD0Directory.class);
if (exifIFD0Directory != null && exifIFD0Directory.hasTagName(ExifIFD0Directory.TAG_ORIENTATION)) {
final Integer orientation = exifIFD0Directory.getInt(ExifIFD0Directory.TAG_ORIENTATION);
originalImage.setProperty(StructrApp.key(Image.class, "orientation"), orientation);
return orientation;
}
} catch (MetadataException | JSONException | FrameworkException ex) {
logger.warn("Unable to store orientation information on image {} ({})", new Object[] { originalImage.getName(), originalImage.getId() });
}
return 1;
}
use of org.structr.web.entity.Image in project structr by structr.
the class ImageHelper method createImageNode.
/**
* Create a new image node from the given image data
*
* @param securityContext
* @param imageData
* @param contentType
* @param imageType defaults to Image.class if null
* @param name
* @param markAsThumbnail
* @return image
* @throws FrameworkException
* @throws IOException
*/
public static Image createImageNode(final SecurityContext securityContext, final byte[] imageData, final String contentType, final Class<? extends Image> imageType, final String name, final boolean markAsThumbnail) throws FrameworkException, IOException {
final PropertyMap props = new PropertyMap();
props.put(AbstractNode.type, imageType == null ? Image.class.getSimpleName() : imageType.getSimpleName());
props.put(StructrApp.key(Image.class, "isThumbnail"), markAsThumbnail);
props.put(AbstractNode.name, name);
final Image newImage = StructrApp.getInstance(securityContext).create(imageType, props);
if (imageData != null && imageData.length > 0) {
setFileData(newImage, imageData, contentType);
}
return newImage;
}
use of org.structr.web.entity.Image in project structr by structr.
the class ImageHelper method updateMetadata.
/**
* Update width and height
*
* @param image the image
* @param fis file input stream
* @throws FrameworkException
*/
public static void updateMetadata(final File image, final InputStream fis) throws FrameworkException {
try (final InputStream is = fis) {
final BufferedImage source = ImageIO.read(is);
if (source != null) {
final int sourceWidth = source.getWidth();
final int sourceHeight = source.getHeight();
final PropertyMap map = new PropertyMap();
map.put(StructrApp.key(Image.class, "width"), sourceWidth);
map.put(StructrApp.key(Image.class, "height"), sourceHeight);
map.put(StructrApp.key(Image.class, "orientation"), ImageHelper.getOrientation(image));
image.setProperties(image.getSecurityContext(), map);
}
} catch (IOException ex) {
logger.warn("Unable to read image data", ex);
}
}
use of org.structr.web.entity.Image in project structr by structr.
the class ImageHelper method createImage.
/**
* Create a new image node from the given image data
*
* @param securityContext
* @param imageStream
* @param contentType
* @param imageType defaults to Image.class if null
* @param name
* @param markAsThumbnail
* @return image
* @throws FrameworkException
* @throws IOException
*/
public static Image createImage(final SecurityContext securityContext, final InputStream imageStream, final String contentType, final Class<? extends Image> imageType, final String name, final boolean markAsThumbnail) throws FrameworkException, IOException {
final PropertyMap props = new PropertyMap();
props.put(AbstractNode.type, imageType == null ? Image.class.getSimpleName() : imageType.getSimpleName());
props.put(StructrApp.key(Image.class, "isThumbnail"), markAsThumbnail);
props.put(AbstractNode.name, name);
final Image newImage = StructrApp.getInstance(securityContext).create(imageType, props);
setFileData(newImage, imageStream, contentType);
return newImage;
}
use of org.structr.web.entity.Image in project structr by structr.
the class ImageConverter method convert.
// ~--- methods --------------------------------------------------------
@Override
public Object convert(final Object source) {
if (source == null) {
return false;
}
try {
Image img = null;
try {
if (source instanceof byte[]) {
byte[] data = (byte[]) source;
MagicMatch match = Magic.getMagicMatch(data);
String mimeType = match.getMimeType();
if (keyAndClass != null) {
img = (Image) ImageHelper.createFile(securityContext, data, mimeType, keyAndClass.getCls());
} else {
ImageHelper.setImageData((Image) currentObject, data, mimeType);
}
} else if (source instanceof String) {
String sourceString = (String) source;
if (StringUtils.isNotBlank(sourceString)) {
if (keyAndClass != null) {
// UUID?
if (sourceString.length() == 32) {
img = (Image) ImageHelper.transformFile(securityContext, sourceString, keyAndClass != null ? keyAndClass.getCls() : null);
}
if (img == null) {
img = (Image) ImageHelper.createFileBase64(securityContext, sourceString, keyAndClass != null ? keyAndClass.getCls() : null);
}
} else {
ImageHelper.decodeAndSetFileData((Image) currentObject, sourceString);
ImageHelper.updateMetadata((Image) currentObject);
}
}
}
} catch (Throwable t) {
logger.warn("Cannot create image node from given data", t);
}
if (img != null) {
// manual indexing of UUID needed here to avoid a 404 in the following setProperty call
img.updateInIndex();
currentObject.setProperties(securityContext, new PropertyMap(keyAndClass.getPropertyKey(), img));
}
} catch (Throwable t) {
logger.warn("Cannot create image node from given data", t);
}
return null;
}
Aggregations