@Override protected void rewriteImpl(BufferedImage image) throws IOException { if (!ImageUtils.isOpaque(image)) { // We can rewrite transparent GIFs to PNG but for IE6 it requires the use of // the AlphaImageReader and some pain. Deferring this until that is proven to work // Write to strip any metadata and re-compute the palette. We allow arbitrary large palettes // here as if the image is already in a direct color model it will already have been // constrained by the max in-mem constraint. write(ImageUtils.palettize(image, Integer.MAX_VALUE)); } else { usePng = true; outputter = new ImageIOOutputter(ImageIO.getImageWritersByFormatName("png").next(), null); super.rewriteImpl(image); } }
@Override protected void rewriteImpl(BufferedImage image) throws IOException { if (!ImageUtils.isOpaque(image)) { // We can rewrite transparent GIFs to PNG but for IE6 it requires the use of // the AlphaImageReader and some pain. Deferring this until that is proven to work // Write to strip any metadata and re-compute the palette. We allow arbitrary large palettes // here as if the image is already in a direct color model it will already have been // constrained by the max in-mem constraint. write(ImageUtils.palettize(image, Integer.MAX_VALUE)); } else { usePng = true; outputter = new ImageIOOutputter(ImageIO.getImageWritersByFormatName("png").next(), null); super.rewriteImpl(image); } }
@Override protected void rewriteImpl(BufferedImage image) throws IOException { if (!ImageUtils.isOpaque(image)) { // We can rewrite transparent GIFs to PNG but for IE6 it requires the use of // the AlphaImageReader and some pain. Deferring this until that is proven to work // Write to strip any metadata and re-compute the palette. We allow arbitrary large palettes // here as if the image is already in a direct color model it will already have been // constrained by the max in-mem constraint. write(ImageUtils.palettize(image, Integer.MAX_VALUE)); } else { usePng = true; outputter = new ImageIOOutputter(ImageIO.getImageWritersByFormatName("png").next(), null); super.rewriteImpl(image); } }
@Override protected void rewriteImpl(BufferedImage image) throws IOException { // Create a new optimizer config and disable JPEG conversion OptimizerConfig pngConfig = new OptimizerConfig(config.getMaxInMemoryBytes(), config.getMaxPaletteSize(), false, config.getJpegCompression(), config.getMinThresholdBytes()); // Output the image as PNG PNGOptimizer pngOptimizer = new PNGOptimizer(pngConfig, response); pngOptimizer.rewriteImpl(image); int pngLength = Integer.MAX_VALUE; if (pngOptimizer.getRewrittenImage() != null) { // PNG was better than original so use it minBytes = pngOptimizer.getRewrittenImage(); minLength = minBytes.length; pngLength = minLength; } // Write as standard JPEG using the configured default compression level write(image); // JPEG did not beat PNG if (pngLength == minLength) { usePng = true; } }
@Override protected void rewriteImpl(BufferedImage image) throws IOException { // Create a new optimizer config and disable JPEG conversion OptimizerConfig pngConfig = new OptimizerConfig(config.getMaxInMemoryBytes(), config.getMaxPaletteSize(), false, config.getJpegCompression(), config.getMinThresholdBytes()); // Output the image as PNG PNGOptimizer pngOptimizer = new PNGOptimizer(pngConfig, response); pngOptimizer.rewriteImpl(image); int pngLength = Integer.MAX_VALUE; if (pngOptimizer.getRewrittenImage() != null) { // PNG was better than original so use it minBytes = pngOptimizer.getRewrittenImage(); minLength = minBytes.length; pngLength = minLength; } // Write as standard JPEG using the configured default compression level write(image); // JPEG did not beat PNG if (pngLength == minLength) { usePng = true; } }
@Override protected void rewriteImpl(BufferedImage image) throws IOException { int pngLength = Integer.MAX_VALUE; if (config.isJpegConversionAllowed()) { // Create a new optimizer config and disable JPEG conversion OptimizerConfig pngConfig = new OptimizerConfig(config.getMaxInMemoryBytes(), config.getMaxPaletteSize(), false, config.getJpegCompression(), config.getMinThresholdBytes(), config.getJpegHuffmanOptimization(), config.getJpegRetainSubsampling()); // Output the image as PNG PNGOptimizer pngOptimizer = new PNGOptimizer(pngConfig, response); pngOptimizer.rewriteImpl(image); if (pngOptimizer.getRewrittenImage() != null) { // PNG was better than original so use it minBytes = pngOptimizer.getRewrittenImage(); minLength = minBytes.length; pngLength = minLength; } } // Write as standard JPEG using the configured default compression level write(image); // JPEG did not beat PNG if (pngLength == minLength) { usePng = true; } }