3

I need to create thumbnail starting from a WebP image but ImageIO doesn't support this format. Are there any library that allow me to do something like this ?


String format = getImageFormat(imageFile);
Iterator readers = ImageIO.getImageReadersByFormatName(format);
// rescaling the image 
BufferedImage bi = loadImageRescalingIfNeeded(imageFile, metadata,...);
//resample if needed
bi = resampleImageIfNeeded(bi, thumbWidth, thumbHeight);
// rotate if degree > 0
bi = rotateBufferedImage(bi, degree);
// create jpeg in output
try (ImageOutputStream imageOut = ImageIO.createImageOutputStream(fileOutputStream)){
  try {
    ImageWriter writer = ImageIO.getImageWritersBySuffix("jpeg").next();
                     
    ImageWriteParam iwp = writer.getDefaultWriteParam();
    iwp.setProgressiveMode(ImageWriteParam.MODE_DEFAULT);
    writer.setOutput(imageOut);
    writer.write(null, new IIOImage(bi, null, metadata), iwp);
  } catch (Exception e) {...}
....}
user7469506
  • 33
  • 1
  • 3
  • 1
    ImageIO "supports" any image format through plugins. There are multiple WebP plugins available. [webp-imageio](https://github.com/sejda-pdf/webp-imageio) is probably the plugin with most features (read/write, lossy/lossless etc), but it requires a native library. [TwelveMonkeys ImageIO](https://github.com/haraldk/TwelveMonkeys) (my library) supports only reading, and only lossy format, but is pure Java. – Harald K May 05 '22 at 11:56
  • 1
    Your library was one of the first I tried in these days but unfortunately I need to support also lossless and alpha webp. I'll try with the one you suggested.. thanks – user7469506 May 06 '22 at 11:53

0 Answers0