Fixed: Product Image PNG - Black Background
When uploading a png image to a product via product/content, transparent
background becomes black.
Uploading the same image via content component or image management works.
Thanks: Ingo
@@ -21,6 +21,7 @@ package org.apache.ofbiz.security;
import java.awt.Graphics;
import java.awt.Image;
+import java.awt.Transparency;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
@@ -360,8 +361,8 @@ public class SecuredUpload {
Image initialSizedImage = resizedImage.getScaledInstance(originalWidth, originalHeight, Image.SCALE_SMOOTH);
// Save image by overwriting the provided source file content
- BufferedImage sanitizedImage = new BufferedImage(initialSizedImage.getWidth(null), initialSizedImage.getHeight(null),
- BufferedImage.TYPE_INT_RGB);
+ int type = originalImage.getTransparency() == Transparency.OPAQUE ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
+ BufferedImage sanitizedImage = new BufferedImage(initialSizedImage.getWidth(null), initialSizedImage.getHeight(null), type);
Graphics bg = sanitizedImage.getGraphics();
bg.drawImage(initialSizedImage, 0, 0, null);
bg.dispose();
