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); } } } }
/** * @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); }
/** * Output a BufferedImage object into the response outputstream. Once this method has been called, no further action * is possible. Users should set {@code $context.setFinished(true)} to avoid template output. The image is served as * image/jpeg. * * @param image the BufferedImage to output * @throws java.io.IOException if the output fails * @since 1.3 Milestone 2 */ public void outputImage(BufferedImage image) throws IOException { OutputStream ostream = getXWikiContext().getResponse().getOutputStream(); Utils.getComponent(ImageProcessor.class).writeImage(image, "image/jpeg", (float) 0.8, ostream); ostream.flush(); }
public XWikiAttachment downloadAttachment(XWikiAttachment attachment, XWikiContext context) if (!this.imageProcessor.isMimeTypeSupported(attachment.getMimeType(context))) { return attachment;
/** * @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); } }
boolean keepAspectRatio, float requestedQuality, XWikiContext context) throws Exception Image image = this.imageProcessor.readImage(attachment.getContentInputStream(context)); RenderedImage shrunkImage = this.imageProcessor.scaleImage(image, dimensions[0], dimensions[1]); this.imageProcessor.writeImage(shrunkImage, attachment.getMimeType(context), quality, bout);