use of java.awt.color.CMMException in project openolat by klemens.
the class ImageHelperImpl method scaleImage.
/**
* @param image The image to scale
* @param imageExt The extension if not given by the image file (optional)
* @param scaledImaged the new scaled image
* @param maxWidth the maximum width of the new scaled image
* @param maxheight the maximum height of the new scaled image
* @return
*/
@Override
public Size scaleImage(File image, String imageExt, File scaledImage, int maxWidth, int maxHeight, boolean fill) {
ImageInputStream imageSrc = null;
try {
imageSrc = new FileImageInputStream(image);
SizeAndBufferedImage scaledSize = calcScaledSize(imageSrc, imageExt, maxWidth, maxHeight, fill);
if (scaledSize == null || scaledSize.image == null) {
return null;
}
if (!scaledSize.getScaledSize().isChanged() && isSameFormat(image, imageExt, scaledImage)) {
if (FileUtils.copyFileToFile(image, scaledImage, false)) {
return scaledSize.getSize();
}
}
BufferedImage bufferedImage = scaledSize.image;
BufferedImage scaledBufferedImage = scaleTo(bufferedImage, scaledSize.getScaledSize());
if (writeTo(scaledBufferedImage, scaledImage, scaledSize.getScaledSize(), getImageFormat(scaledImage))) {
return scaledSize.getScaledSize();
}
return null;
} catch (IOException e) {
return null;
// fxdiff FXOLAT-109: prevent red screen if the image has wrong EXIF data
} catch (CMMException e) {
return null;
} finally {
closeQuietly(imageSrc);
}
}
use of java.awt.color.CMMException in project openolat by klemens.
the class ImageHelperImpl method scaleImage.
/**
* @param image the image to scale
* @param scaledImaged the new scaled image
* @param maxSize the maximum size (height or width) of the new scaled image
* @return
*/
@Override
public Size scaleImage(VFSLeaf image, VFSLeaf scaledImage, int maxWidth, int maxHeight, boolean fill) {
OutputStream bos = null;
ImageInputStream ins = null;
try {
ins = getInputStream(image);
if (ins == null) {
return null;
}
String extension = FileUtils.getFileSuffix(image.getName());
SizeAndBufferedImage scaledSize = calcScaledSize(ins, extension, maxWidth, maxHeight, fill);
if (scaledSize == null || scaledSize.getImage() == null) {
return null;
}
ins = getInputStream(image);
if (ins == null) {
return null;
}
bos = new BufferedOutputStream(scaledImage.getOutputStream(false));
if (!scaledSize.getScaledSize().isChanged() && isSameFormat(image, scaledImage)) {
InputStream cloneIns = image.getInputStream();
IOUtils.copy(cloneIns, bos);
IOUtils.closeQuietly(cloneIns);
return scaledSize.getScaledSize();
} else {
BufferedImage imageSrc = scaledSize.getImage();
BufferedImage scaledSrc = scaleTo(imageSrc, scaledSize.getScaledSize());
boolean scaled = writeTo(scaledSrc, bos, scaledSize.getScaledSize(), getImageFormat(scaledImage));
if (scaled) {
return scaledSize.getScaledSize();
}
return null;
}
} catch (IOException e) {
return null;
// fxdiff FXOLAT-109: prevent red screen if the image has wrong EXIF data
} catch (CMMException e) {
return null;
} finally {
closeQuietly(ins);
FileUtils.closeSafely(bos);
}
}
Aggregations