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

(cherry picked from commit eca91ab)
  • Loading branch information
rdenarie authored and Jihed525 committed Sep 16, 2024
1 parent b2520bf commit 34fb364
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 @@ -111,7 +113,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 34fb364

Please sign in to comment.