UPDATE 13/07/2017 [ THE ISSUE IS FIXED ]
Magento team has released SUPEE-9767 V2 in this version of the patch the problem with transparent gif's and png's is fixed.
You should revert all changes to the file that was discussed in this thread. Then revert the applied V1 patch and finally apply the new version V2.
PRE - SUPEE-9767 V2
Please don't use the code discussed bellow instead apply V2 of the patch the problem discussed bellow is already fixed in this version
If somebody experience problem with transparent png's that when uploaded from the admin panel the background becomes black. (On the products) is in relation to the Image Upload callback introduced in:
app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php
In the moment I am not sure what exactly is causing this behaviour but I am trying to figure it out I can confirm that when the callback is removed the strange behaviour is going away.
UPDATE
Ok, I found the function that is also updated from SUPEE-9767 this is actually breaking the transparency in the png's a copy of the original image is created without transparency.
+++ app/code/core/Mage/Core/Model/File/Validator/Image.php
@@ -87,10 +87,33 @@ public function setAllowedImageTypes(array $imageFileExtensions = array())
*/
public function validate($filePath)
{
- $fileInfo = getimagesize($filePath);
- if (is_array($fileInfo) and isset($fileInfo[2])) {
- if ($this->isImageType($fileInfo[2])) {
- return null;
+ list($imageWidth, $imageHeight, $fileType) = getimagesize($filePath);
+ if ($fileType) {
+ if ($this->isImageType($fileType)) {
+ //replace tmp image with re-sampled copy to exclude images with malicious data
+ $image = imagecreatefromstring(file_get_contents($filePath));
+ if ($image !== false) {
+ $img = imagecreatetruecolor($imageWidth, $imageHeight);
+ imagecopyresampled($img, $image, 0, 0, 0, 0, $imageWidth, $imageHeight, $imageWidth, $imageHeight);
+ switch ($fileType) {
+ case IMAGETYPE_GIF:
+ imagegif($img, $filePath);
+ break;
+ case IMAGETYPE_JPEG:
+ imagejpeg($img, $filePath, 100);
+ break;
+ case IMAGETYPE_PNG:
+ imagepng($img, $filePath);
+ break;
+ default:
+ return;
+ }
+ imagedestroy($img);
+ imagedestroy($image);
+ return null;
+ } else {
+ throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid image.'));
+ }
}
}
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid MIME type.'));
UPDATE
Here is updated version of the function to preserve the png transparency
imagealphablending($img, false);
imagesavealpha($img, true);
these two lines need to be added to the patch.
Update the function in app/code/core/Mage/Core/Model/File/Validator/Image.php
/**
* Validation callback for checking is file is image
*
* @param string $filePath Path to temporary uploaded file
* @return null
* @throws Mage_Core_Exception
*/
public function validate($filePath)
{
list($imageWidth, $imageHeight, $fileType) = getimagesize($filePath);
if ($fileType) {
if ($this->isImageType($fileType)) {
//replace tmp image with re-sampled copy to exclude images with malicious data
$image = imagecreatefromstring(file_get_contents($filePath));
if ($image !== false) {
$img = imagecreatetruecolor($imageWidth, $imageHeight);
imagealphablending($img, false);
imagesavealpha($img, true);
imagecopyresampled($img, $image, 0, 0, 0, 0, $imageWidth, $imageHeight, $imageWidth, $imageHeight);
switch ($fileType) {
case IMAGETYPE_GIF:
imagegif($img, $filePath);
break;
case IMAGETYPE_JPEG:
imagejpeg($img, $filePath, 100);
break;
case IMAGETYPE_PNG:
imagepng($img, $filePath);
break;
default:
return;
}
imagedestroy($img);
imagedestroy($image);
return null;
} else {
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid image.'));
}
}
}
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid MIME type.'));
}
UPDATE 23/06/17
This updated version of the function fixes the PNG and the GIF transparency.
/**
* Validation callback for checking is file is image
*
* @param string $filePath Path to temporary uploaded file
* @return null
* @throws Mage_Core_Exception
*/
public function validate($filePath)
{
list($imageWidth, $imageHeight, $fileType) = getimagesize($filePath);
if ($fileType) {
if ($this->isImageType($fileType)) {
//replace tmp image with re-sampled copy to exclude images with malicious data
$image = imagecreatefromstring(file_get_contents($filePath));
if ($image !== false) {
$img = imagecreatetruecolor($imageWidth, $imageHeight);
switch ($fileType) {
case IMAGETYPE_GIF:
imagecolortransparent($img, imagecolorallocatealpha($img, 0, 0, 0, 127));
imagealphablending($img, false);
imagesavealpha($img, true);
imagecopyresampled($img, $image, 0, 0, 0, 0, $imageWidth, $imageHeight, $imageWidth, $imageHeight);
imagegif($img, $filePath);
break;
case IMAGETYPE_JPEG:
imagecopyresampled($img, $image, 0, 0, 0, 0, $imageWidth, $imageHeight, $imageWidth, $imageHeight);
imagejpeg($img, $filePath, 100);
break;
case IMAGETYPE_PNG:
imagealphablending($img, false);
imagesavealpha($img, true);
imagecopyresampled($img, $image, 0, 0, 0, 0, $imageWidth, $imageHeight, $imageWidth, $imageHeight);
imagepng($img, $filePath);
break;
default:
return;
}
imagedestroy($img);
imagedestroy($image);
return null;
} else {
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid image.'));
}
}
}
throw Mage::exception('Mage_Core', Mage::helper('core')->__('Invalid MIME type.'));
}
RewriteRule ^/?(index.phprss|index.php/rss/catalog|index.php/rss/order|rss/catalog|rss/order).*$ /no-route [R=301,L,NC]