if (!destinationFile.exists()) {
try {
FileUtils.copyFileToDirectory(srcImage, this.imageDestinationPath);
LOG.info("copying image: "+ srcImage.getPath());
ImageOutputStream stream = new FileImageOutputStream(destinationFile);
if (Utilities.getImageWidth(srcImage) > PAGE_WIDTH) {
LOG.warn("Image: '" + srcImage.getPath() + "' is too big for the page");
scale = 100.0;
tooBig = true;
}
if (shouldResize || tooBig) {
boolean resized = Utilities.resizeImage(srcImage, stream, Utilities.getFormatName(srcImage), PAGE_WIDTH, (scale)/100.0);
if (!resized) {
LOG.warn("could not resize image " + srcImage + ", copying it entirely");
FileUtils.copyFile(srcImage, destinationFile);
}
}
srcImage = destinationFile;
Utilities.getImageWithLogo(srcImage, stream, Utilities.getFormatName(srcImage), logo);
stream.close();
} catch (IOException e) {
LOG.warn("Error while copying " + srcImage.getPath() + ":\n" +
"\t\t" + e.getMessage());
throw new TubainaException("Couldn't copy image", e);
}