adjaya Posted July 20, 2009 Share Posted July 20, 2009 Bonjour.J'ai vu sur le forum une astuce pour ne pas avoir de bandes blanches sur l'image thickbox, mais celle-ci oblige à redéfinir à chaque foi les dimensions dans préférences>images.Pour ne plus avoir automatiquement de bandes blanches sur cette image j'ai modifié la fonction imagesResize du fichier images.inc.php ainsi : function imageResize($sourceFile, $destFile, $destWidth = NULL, $destHeight = NULL, $fileType = 'jpg') { if (!isset($sourceFile['tmp_name']) OR !file_exists($sourceFile['tmp_name'])) return false; list($sourceWidth, $sourceHeight, $type, $attr) = @getimagesize($sourceFile['tmp_name']); if (!$sourceWidth) return false; if ($destWidth == NULL) $destWidth = $sourceWidth; if ($destHeight == NULL) $destHeight = $sourceHeight; $sourceImage = createSrcImage($type, $sourceFile['tmp_name']); $widthDiff = $destWidth / $sourceWidth; $heightDiff = $destHeight / $sourceHeight; if ($widthDiff > 1 AND $heightDiff > 1) { $nextWidth = $sourceWidth; $nextHeight = $sourceHeight; } else { if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $widthDiff > $heightDiff)) { $nextHeight = $destHeight; $nextWidth = intval(($sourceWidth * $nextHeight) / $sourceHeight); $destWidth = (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 ? $destWidth : $nextWidth); } else { $nextWidth = $destWidth; $nextHeight = intval($sourceHeight * $destWidth / $sourceWidth); $destHeight = (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 ? $destHeight : $nextHeight); } } # ! -thickbox : if (strpos($destFile,'-thickbox') === false) { $borderWidth = intval(($destWidth - $nextWidth) / 2); $borderHeight = intval(($destHeight - $nextHeight) / 2); $destImage = @imagecreatetruecolor($destWidth, $destHeight); $white = imagecolorallocate($destImage, 255, 255, 255); imagefill($destImage, 0, 0, $white); imagecopyresampled($destImage, $sourceImage, $borderWidth, $borderHeight, 0, 0, $nextWidth, $nextHeight, $sourceWidth, $sourceHeight); } else { $borderWidth = intval($destWidth - $nextWidth); $borderHeight = intval($destHeight - $nextHeight); $destImage = @imagecreatetruecolor($destWidth - $borderWidth, $destHeight - $borderHeight); //$white = imagecolorallocate($destImage, 255, 255, 255); //imagefill($destImage, 0, 0, $white); imagecopyresampled($destImage, $sourceImage, 0, 0, 0, 0, $nextWidth, $nextHeight, $sourceWidth, $sourceHeight); } imagecolortransparent($destImage, $white); return (returnDestImage($fileType, $destImage, $destFile)); } Voilà, il ne reste plus qu'a définir une bonne fois pour toute la hauteur et largeur maxi souhaitées de cette image dans les préférences. Link to comment Share on other sites More sharing options...
gbaby Posted September 15, 2009 Share Posted September 15, 2009 thanks! finally something that works! Link to comment Share on other sites More sharing options...
pasc06 Posted September 16, 2009 Share Posted September 16, 2009 Euh... C'est quoi la thickbox ? Link to comment Share on other sites More sharing options...
Dominique Fleury Posted August 19, 2010 Share Posted August 19, 2010 Merci ces quelques lignes de code qui dépannent bien. Pour ma part j'ai radicalement supprimé les bandes blanches sur tous les format d'image... A vrai dire je ne comprends pas très bien l'utilité d'ajouter ces bandes en "hard" dans le .jpg alors qu'on peut très bien s'en sortir en codant correctement son css. C'est d'ailleurs bien dommage qu'il faille aller jusqu'à faire une modif dans le php ce qui posera des problèmes en cas de mise à jour prestashop :-( Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now