xpoitau Posted December 22, 2009 Share Posted December 22, 2009 Voici ma petite bidouille pour remplacer GD par imagemagick dans images.inc.phpremplacer la fonction---- function imageResize($sourceFile, $destFile, $destWidth = NULL, $destHeight = NULL, $fileType = 'jpg') { list($sourceWidth, $sourceHeight, $type, $attr) = getimagesize($sourceFile); if (!$sourceWidth) return false; if ($destWidth == NULL) $destWidth = $sourceWidth; if ($destHeight == NULL) $destHeight = $sourceHeight; $sourceImage = createSrcImage($type, $sourceFile); $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); } } $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); imagecolortransparent($destImage, $white); */ // ajout pour imagemagick $bordure = $borderWidth+$borderHeight; $cmd = "convert -size ".$sourceWidth."x".$sourceHeight." ".$sourceFile." -resize ".$nextWidth."x".$nextHeight." -bordercolor white -border ".$bordure."x".$bordure." -gravity center -crop ".$destWidth."x".$destHeight."+0+0 ".$destFile; exec($cmd); return (returnDestImage($fileType, $destImage, $destFile)); } et aussi la fonction : function returnDestImage($type, $ressource, $filename) { /* $flag = false; switch ($type) { case 'gif': $flag = imagegif($ressource, $filename); break; case 'png': $flag = imagepng($ressource, $filename, 7); break; case 'jpeg': default: $flag = imagejpeg($ressource, $filename, 90); break; } imagedestroy($ressource); return $flag; */ if (file_exists("$filename")) { return true; } else { return false; } } bien sûr, il faut avoir imagemagick installé et la possibilité d'exécuter des commandes en php.Xavieraxome.com images.inc.php Link to comment Share on other sites More sharing options...
Yoya Posted December 23, 2009 Share Posted December 23, 2009 Pas testé mais excellente initiative, merci à toi.Cdlt,Pierre. Link to comment Share on other sites More sharing options...
Julien Breux Posted December 23, 2009 Share Posted December 23, 2009 Très bon sachant que GD est un peu...[NOTE]Sorry Thomas :S[/NOTE] Link to comment Share on other sites More sharing options...
jamesie Posted April 20, 2010 Share Posted April 20, 2010 fantastic this worked first time thanks!! Link to comment Share on other sites More sharing options...
jamesie Posted April 20, 2010 Share Posted April 20, 2010 I did generate thumbnails and lost them all! I get permission problem, maybe its not related but can you suggest what I should check please? Link to comment Share on other sites More sharing options...
yvesbj Posted April 20, 2010 Share Posted April 20, 2010 Bonjour, je connais pas imagemagick, pourriez vous me dire quelles sont les différences svp ? Link to comment Share on other sites More sharing options...
jamesie Posted April 21, 2010 Share Posted April 21, 2010 http://www.imagemagick.org/script/index.php Je ne sais pas le functionalite en detail mais le function Regenerate Thumbnails ne marche pas. J'ai PHP 5.2.9 et peut etre ca cause le probleme. Est ce que tu a un bon solution?Cheers James 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