/** * @param attachment an image attachment * @param context the XWiki context * @return the width of the specified image * @throws IOException if reading the image from the attachment content fails * @throws XWikiException if reading the attachment content fails */ public int getWidth(XWikiAttachment attachment, XWikiContext context) throws IOException, XWikiException { return this.imageProcessor.readImage(attachment.getContentInputStream(context)).getWidth(null); }
/** * @param attachment an image attachment * @param context the XWiki context * @return the height of the specified image * @throws IOException if reading the image from the attachment content fails * @throws XWikiException if reading the attachment content fails */ public int getHeight(XWikiAttachment attachment, XWikiContext context) throws IOException, XWikiException { return this.imageProcessor.readImage(attachment.getContentInputStream(context)).getHeight(null); } }
private void resizeImageToAttachment(InputStream imageFileInputStream, int width, int height, XWikiAttachment outputAttachment) throws IOException { OutputStream attachmentOutputStream = null; try { Image originalImage = imageProcessor.readImage(imageFileInputStream); RenderedImage resizedImage = imageProcessor.scaleImage(originalImage, width, height); attachmentOutputStream = outputAttachment.getAttachment_content().getContentOutputStream(); imageProcessor.writeImage(resizedImage, "image/png", 1.0f, attachmentOutputStream); } finally { // Close the attachment output stream since we are done writing to it. if (attachmentOutputStream != null) { IOUtils.closeQuietly(attachmentOutputStream); } } } }
boolean keepAspectRatio, float requestedQuality, XWikiContext context) throws Exception Image image = this.imageProcessor.readImage(attachment.getContentInputStream(context));