Skip to content

Commit

Permalink
fix: Image Resize not working for some specific images - EXO-74160
Browse files Browse the repository at this point in the history
Before this fix, in some particular case, images cannot be resized.
This fix add option to correctly write the image for resize

Resolves Meeds-io/meeds#2386
  • Loading branch information
rdenarie committed Sep 13, 2024
1 parent e416374 commit 46bb2c2
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import javax.imageio.IIOImage;
import javax.imageio.ImageIO;
import javax.imageio.ImageReader;
import javax.imageio.ImageWriteParam;
import javax.imageio.ImageWriter;
import javax.imageio.metadata.IIOMetadata;
import javax.imageio.plugins.jpeg.JPEGImageWriteParam;
import javax.imageio.stream.ImageInputStream;

import org.imgscalr.Scalr;
Expand Down Expand Up @@ -119,7 +121,11 @@ private byte[] toByteArray(BufferedImage targetBufferedImage, ImageReader source
writer.setOutput(ImageIO.createImageOutputStream(byteArrayOutputStream));

IIOMetadata metadata = sourceImageReader.getImageMetadata(0);
writer.write(new IIOImage(targetBufferedImage, null, metadata));
ImageWriteParam param = writer.getDefaultWriteParam();
if (param instanceof JPEGImageWriteParam) {
((JPEGImageWriteParam) param).setOptimizeHuffmanTables(true);
}
writer.write(null,new IIOImage(targetBufferedImage, null, metadata), param);
writer.dispose();
return byteArrayOutputStream.toByteArray();
}
Expand Down

0 comments on commit 46bb2c2

Please sign in to comment.