AGGIORNAMENTO 13/07/2017 [IL PROBLEMA È RISOLTO]
Il team di Magento ha rilasciato SUPEE-9767 V2 in questa versione della patch il problema con gif e png trasparenti è stato risolto.
È necessario ripristinare tutte le modifiche al file discusso in questo thread. Quindi ripristina la patch V1 applicata e infine applica la nuova versione V2.
PRE - SUPEE-9767 V2
Si prega di non usare il codice discusso qui sotto invece applicare V2 della patch, il problema discusso qui sotto è già risolto in questa versione
Se qualcuno ha problemi con i PNG trasparenti che quando vengono caricati dal pannello di amministrazione lo sfondo diventa nero. (Sui prodotti) è in relazione al callback di Image Upload introdotto in:
app/code/core/Mage/Adminhtml/controllers/Catalog/Product/GalleryController.php
Al momento non sono sicuro di cosa stia causando esattamente questo comportamento, ma sto cercando di capirlo, posso confermare che quando il callback viene rimosso lo strano comportamento scompare.
![inserisci qui la descrizione dell'immagine](https://i.stack.imgur.com/caYJz.jpg)
AGGIORNARE
Ok, ho trovato la funzione che è anche aggiornata da SUPEE-9767 questo sta effettivamente rompendo la trasparenza nei png è una copia dell'immagine originale creata senza trasparenza.
+++ 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.'));
AGGIORNARE
Ecco la versione aggiornata della funzione per preservare la trasparenza del png
imagealphablending($img, false);
imagesavealpha($img, true);
queste due righe devono essere aggiunte alla patch. Aggiorna la funzione inapp/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.'));
}
AGGIORNAMENTO 23/06/17
Questa versione aggiornata della funzione corregge il PNG e la trasparenza GIF.
/**
* 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.'));
}