/** * As the image is resized, the request needs to change so that the optimizer can * make sensible image size-related decisions down the pipeline. GIF images are rewritten * as PNGs though, so as not to include the dependency on the GIF decoder. * * @param response the base response that will be modified with the resized image * @param image the resized image that needs to be substituted for the original image from * the response */ private void updateResponse(HttpResponseBuilder response, BufferedImage image) throws IOException { ImageWriter imageWriter = ImageIO.getImageWritersByFormatName(RESIZE_OUTPUT_FORMAT).next(); ImageOutputter outputter = new ImageIOOutputter(imageWriter, null); byte[] imageBytes = outputter.toBytes(image); response .setResponse(imageBytes) .setHeader(CONTENT_TYPE, CONTENT_TYPE_IMAGE_PNG) .setHeader(CONTENT_LENGTH, String.valueOf(imageBytes.length)); }
/** * If the image is resized, the request needs to change so that the optimizer can * make sensible image size-related decisions down the pipeline. GIF images are rewritten * as PNGs though, so as not to include the dependency on the GIF decoder. * * @param response the base response that will be modified with the resized image * @param image the resized image that needs to be substituted for the original image from * the response */ public void updateResponse(HttpResponseBuilder response, BufferedImage image) throws IOException { ImageWriter imageWriter = ImageIO.getImageWritersByFormatName(RESIZE_OUTPUT_FORMAT).next(); ImageOutputter outputter = new ImageIOOutputter(imageWriter, null); byte[] imageBytes = outputter.toBytes(image); response .setResponse(imageBytes) .setHeader(CONTENT_TYPE, CONTENT_TYPE_IMAGE_PNG) .setHeader(CONTENT_LENGTH, String.valueOf(imageBytes.length)); }
/** * As the image is resized, the request needs to change so that the optimizer can * make sensible image size-related decisions down the pipeline. GIF images are rewritten * as PNGs though, so as not to include the dependency on the GIF decoder. * * @param response the base response that will be modified with the resized image * @param image the resized image that needs to be substituted for the original image from * the response */ private void updateResponse(HttpResponseBuilder response, BufferedImage image) throws IOException { ImageWriter imageWriter = ImageIO.getImageWritersByFormatName(RESIZE_OUTPUT_FORMAT).next(); ImageOutputter outputter = new ImageIOOutputter(imageWriter, null); byte[] imageBytes = outputter.toBytes(image); response .setResponse(imageBytes) .setHeader(CONTENT_TYPE, CONTENT_TYPE_IMAGE_PNG) .setHeader(CONTENT_LENGTH, String.valueOf(imageBytes.length)); }
/** * Write the image using a specified write param */ protected void write(BufferedImage image) throws IOException { if (image == null) { return; } byte[] bytes = outputter.toBytes(image); if (minLength > bytes.length) { minBytes = bytes; minLength = minBytes.length; reductionPct = ((response.getContentLength() - minLength) * 100) / response.getContentLength(); } }
/** * Write the image using a specified write param */ protected void write(BufferedImage image) throws IOException { if (image == null) { return; } byte[] bytes = outputter.toBytes(image); if (minLength > bytes.length) { minBytes = bytes; minLength = minBytes.length; reductionPct = ((response.getContentLength() - minLength) * 100) / response.getContentLength(); } }
/** * Write the image using a specified write param */ protected void write(BufferedImage image) throws IOException { if (image == null) { return; } byte[] bytes = outputter.toBytes(image); if (minLength > bytes.length) { minBytes = bytes; minLength = minBytes.length; reductionPct = ((response.getContentLength() - minLength) * 100) / response.getContentLength(); } }