thumbnailator icon indicating copy to clipboard operation
thumbnailator copied to clipboard

Support progressive encoding for output (i.e. allow writing progressive JPEGs)

Open jlerbsc opened this issue 8 years ago • 6 comments

Hi, Is there a way to generate progressive jpeg with thumbnailator? Thanks,

jlerbsc avatar May 07 '17 07:05 jlerbsc

No, Thumbnailator does not expose the functionality of the Java Image I/O API to specify whether to use progressive encoding. As that functionality is not exposed, is it not possible at this time to create progressive JPEGs.

That said, I'd be interested to hear how much interest there is. If there's a lot of interest, then I think it's worth incorporating this as a new feature.

coobird avatar May 10 '17 14:05 coobird

Note to self:

API Design memo for a potential way to specify the output parameters of the compression format used for the output.

JPEG:

Thumbnails.of(images)
    .withOptions(OutputFormat.JPEG.usingProgressive().withQuality(0.9))
    .toFiles(Rename.PREFIX_DOT_THUMBNAIL);

PNG:

Thumbnails.of(images)
    .withOptions(OutputFormat.PNG.usingDefaults())
    .toFiles(Rename.PREFIX_DOT_THUMBNAIL);

coobird avatar Apr 15 '18 17:04 coobird

This would be quite useful for a project I'm working on, as it's pretty content-heavy, and the UX for slow connections would be better with progressive images I think. https://www.adoptanimals.io/

Thanks for all your hard work so far, I did quite a bit of searching for good JVM thumbnail making and this one was by far the easiest to use and produced really nice results (all the animal images on that site are produced using it) 👍

lopcode avatar May 06 '18 10:05 lopcode

@CarrotCodes I'm glad to hear that Thumbnailator is being put to good use, and thank you for your comment. :)

I can't make any promises when Thumbnailator will add support for setting progressive JPEGs, but I'll keep it in mind for features to work on. (I might end up creating a temporary workaround if I can't cleanly integrate it into the API yet.)

coobird avatar May 08 '18 15:05 coobird

hi :) Is there any way we can assist you in implementing this? IMHO as a workaround we could get a bufferedImage and do the writing ourselves, so not a blocker for me

reisi007 avatar Jun 14 '19 12:06 reisi007

In case this helps, here is the code I use for this (the example is in Kotlin, but it should be easy to translate it to Java):

ImageIO.createImageOutputStream(stream).use { imageOutputStream ->
    val writer = ImageIO.getImageWritersBySuffix("jpeg").next()
    try {
        writer.output = imageOutputStream
        writer.write(
            null,
            IIOImage(builder.asBufferedImage(), null, null),
            writer.defaultWriteParam.apply {
                progressiveMode = ImageWriteParam.MODE_DEFAULT
            }
        )
    } finally {
        writer?.dispose()
    }
}

axelfontaine avatar Dec 28 '20 19:12 axelfontaine