OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
863 stars 438 forks source link

Black background of PNG images with transparent background in the Wysiwyg editor #3998

Open boesbo opened 1 month ago

boesbo commented 1 month ago

Preconditions (*)

  1. OpenMage 20.7.0

Steps to reproduce (*)

  1. Open the Static Block creation page
  2. Go to the editor and load an image. A PNG with a transparent background

Expected result (*)

  1. The thumbnail created is with black background instead of transparent
  2. Thumbnail viewable on edit is with black background instead of transparent

Actual result (*)

  1. The problem only affects thumbnail creation and preview display in the editor.
  2. Regarding Thumb creation I am testing a fix that involves adding $image->keepTransparency(true); to line 386 of the file app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php
  3. As for displaying the preview in the editor, go to Controller: app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php Action: directiveAction(). I still haven't found a way to solve it.

I attach images of my GD version.

Thumb app/code/core/Mage/Cms/Model/Wysiwyg/Images/Storage.php::resizeFile

Screen Shot 2024-05-16 at 16 17 21 PM

Preview in editor app/code/core/Mage/Adminhtml/controllers/Cms/WysiwygController.php::directiveAction

Screen Shot 2024-05-16 at 16 17 31 PM

Screen Shot 2024-05-16 at 15 33 36 PM

fballiano commented 1 month ago

I'm testing this but I don't think it's the editor's fault because I see the black background already right after uploading it

Screenshot 2024-05-17 alle 10 07 53

at that moment I don't think the new wyswyg has nothing to do with it

boesbo commented 1 month ago

I'm testing this but I don't think it's the editor's fault because I see the black background already right after uploading it

Screenshot 2024-05-17 alle 10 07 53

at that moment I don't think the new wyswyg has nothing to do with it

Yes, the problem is in the two files I mentioned above

fballiano commented 1 month ago

same thing happening with the old editor on latest v19

Screenshot 2024-05-17 alle 10 12 12
boesbo commented 1 month ago

same thing happening with the old editor on latest v19

Screenshot 2024-05-17 alle 10 12 12

Yes, by selling the history I noticed that it is something that we have been carrying with me I imagine since Magento 1.9. Do you think this is intentional behavior? It seems strange.

fballiano commented 1 month ago

mmmm I really don't know :-\

all images are always re-saved in order to remove any possible form of "virus" within the image, but to remove transparency I've no idea why

pquerner commented 1 month ago

Its imagemagick. Where it gets its settings tho, that I don't know. I remember something from the TYPO3 days: https://stackoverflow.com/questions/18809692/why-do-imagemagick-based-thumbnail-images-of-pdf-files-in-typo3-have-black-backg https://forge.typo3.org/issues/37060

I dont know if that setting is available to customize from within magento, or if its only sitting in some php.ini file. I know too little about this.

boesbo commented 1 month ago

Its imagemagick. Where it gets its settings tho, that I don't know. I remember something from the TYPO3 days: https://stackoverflow.com/questions/18809692/why-do-imagemagick-based-thumbnail-images-of-pdf-files-in-typo3-have-black-backg https://forge.typo3.org/issues/37060

I dont know if that setting is available to customize from within magento, or if its only sitting in some php.ini file. I know too little about this.

That part of the script uses the GD library not ImageMagick: $image = Varien_Image_Adapter::factory('GD2');

pquerner commented 1 month ago

Well this perhaps then https://stackoverflow.com/questions/5913284/php-gd-transparent-areas-goes-black

(im checking out here, im just googleing stuff anyway)

boesbo commented 1 month ago

Yes, this is it. In the two files I wrote at the beginning, transparency management is missing. But it's so obvious that it makes me doubt. It doesn't seem like an oversight.

I can also act by creating a PR, but first I want to better understand if this behavior has a purpose, since it is only visible in the editor.

pquerner commented 1 month ago

Well, all this system comes from a time where it wasnt the norm and browsers had troubles with transparent files? I think up to IE11 no IE browser learned to do it or something? So it could be very well just that. :D

boesbo commented 1 month ago

In the next few days I will propose a patch. I am very clear on the problem. Transparency is simply not managed in the two phases: 1. thumb creation, 2. editor preview url