This is an automated email from the ASF dual-hosted git repository.

jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git


The following commit(s) were added to refs/heads/trunk by this push:
     new cba0e4b77a Fixed: Product Image PNG - Black Background (OFBIZ-12750)
cba0e4b77a is described below

commit cba0e4b77ad3168674227007ae42d04f3a14daee
Author: Jacques Le Roux <jacques.le.r...@les7arts.com>
AuthorDate: Sat Feb 4 12:14:48 2023 +0100

    Fixed: Product Image PNG - Black Background (OFBIZ-12750)
    
    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
---
 .../src/main/java/org/apache/ofbiz/security/SecuredUpload.java       | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git 
a/framework/security/src/main/java/org/apache/ofbiz/security/SecuredUpload.java 
b/framework/security/src/main/java/org/apache/ofbiz/security/SecuredUpload.java
index ca1bd09e5e..fb9fd68ed3 100644
--- 
a/framework/security/src/main/java/org/apache/ofbiz/security/SecuredUpload.java
+++ 
b/framework/security/src/main/java/org/apache/ofbiz/security/SecuredUpload.java
@@ -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();

Reply via email to