Skip to content
Snippets Groups Projects
Commit 9754c5f4 authored by Vincent Massol's avatar Vincent Massol
Browse files

XWIKI-21546: "Unsupported Image Type" warning in the logs when scaling some JPEG images

* Improve warning messages too
parent 10d079d4
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,14 @@
<artifactId>xwiki-platform-component-multi</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Use a better image parser than what is in the JDK with ImageIO (which doesn't support CMYK-encoded
jpeg images for example. Just adding this dependency is enough for calls to ImageIO.read() to use
twelvemonkeys's implementation. -->
<dependency>
<groupId>com.twelvemonkeys.imageio</groupId>
<artifactId>imageio-jpeg</artifactId>
<version>3.12.0</version>
</dependency>
<!-- Used by the image plugin to resize the images (i.e. create thumbnails) on the server side. -->
<dependency>
<groupId>net.coobird</groupId>
......
......@@ -26,6 +26,7 @@
import java.util.Arrays;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -63,6 +64,8 @@ public class ImagePlugin extends XWikiDefaultPlugin
*/
private static final String PLUGIN_NAME = "image";
private static final String DEFAULT_QUALITY_PARAM = "xwiki.plugin.image.defaultQuality";
/**
* Cache for already served images.
*/
......@@ -120,13 +123,13 @@ public void init(XWikiContext context)
String imageProcessorHint = context.getWiki().Param("xwiki.plugin.image.processorHint", "thumbnailator");
this.imageProcessor = Utils.getComponent(ImageProcessor.class, imageProcessorHint);
String defaultQualityParam = context.getWiki().Param("xwiki.plugin.image.defaultQuality");
String defaultQualityParam = context.getWiki().Param(DEFAULT_QUALITY_PARAM);
if (!StringUtils.isBlank(defaultQualityParam)) {
try {
this.defaultQuality = Math.max(0, Math.min(1, Float.parseFloat(defaultQualityParam.trim())));
} catch (NumberFormatException e) {
LOG.warn("Failed to parse xwiki.plugin.image.defaultQuality configuration parameter. "
+ "Using {} as the default image quality.", this.defaultQuality);
LOG.warn("Failed to parse [{}] configuration parameter. Using [{}] as the default image quality.",
DEFAULT_QUALITY_PARAM, this.defaultQuality);
}
}
}
......@@ -219,9 +222,9 @@ public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiConte
// Transform the image attachment before is it downloaded.
result = downloadImage(attachment, width, height, quality, context);
} catch (Exception e) {
LOG.warn(
"Failed to transform image attachment {} for scaling, falling back to original attachment.",
attachment.getFilename());
LOG.warn("Failed to transform image attachment [{}] for scaling, falling back to original "
+ "attachment. Root error: [{}]", attachment.getFilename(),
ExceptionUtils.getRootCauseMessage(e));
LOG.debug("Full stack trace for image attachment scaling error: ", e);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment