Skip to content
Extraits de code Groupes Projets
Valider a076520a rédigé par ARNO*'s avatar ARNO*
Parcourir les fichiers

Ajout de la fonction reduire_img, pour forcer la taille des logos (site public)

parent ff36d4ba
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -521,6 +521,131 @@ function exposer ($id, $identique='on', $different='') {
return $different;
}
//
// Reduire la taille d'un logo
//
function reduire_img($img, $taille = 120) {
if (strlen($img) > 0) {
// recuperer le nom du fichier
if (eregi("src=\'([^']+)\'", $img, $regs)) $logo = $regs[1];
if (eregi("align=\'([^']+)\'", $img, $regs)) $align = $regs[1];
if (eregi("name=\'([^']+)\'", $img, $regs)) $name = $regs[1];
if (eregi("hspace=\'([^']+)\'", $img, $regs)) $espace = $regs[1];
if (file_exists($logo)) {
$logo = substr($logo, 4, strlen($logo));
// recuperer nom de l'image et sa terminaison
$nom = substr($logo, 0, strpos($logo, "."));
$format = substr($logo, strlen($logo)-3, strlen($logo));
// test de recalcul en fonction des dates des fichiers
// pour verifier si mise a jour plus recente du logo
if (file_exists("IMG/$taille-$nom.$format")) {
if (filemtime("IMG/$taille-$nom.$format") > filemtime("IMG/$logo")) {
return "<img src='IMG/$taille-$nom.$format' name='$name' border='0' align='$align' alt='' hspace='$espace' vspace='$espace' class='spip_logos' />";
$recalculer = false;
}
else {
$recalculer = true;
}
} else {
$recalculer = true;
}
$gd_formats = lire_meta("gd_formats");
if ($recalculer AND ereg($format, $gd_formats)) {
// Recuperer l'image d'origine
if ($format == "jpg") {
$srcImage = ImageCreateFromJPEG("IMG/$logo");
}
else if ($format == "gif"){
$srcImage = ImageCreateFromGIF("IMG/$logo");
}
else if ($format == "png"){
$srcImage = ImageCreateFromPNG("IMG/$logo");
}
if (!$srcImage) return;
// Calculer le ratio
$srcWidth = ImageSX($srcImage);
$srcHeight = ImageSY($srcImage);
if ($srcWidth > $taille OR $srcHeight > $taille) {
$ratioWidth = $srcWidth/$taille;
$ratioHeight = $srcHeight/$taille;
if ($ratioWidth < $ratioHeight) {
$destWidth = floor($srcWidth/$ratioHeight);
$destHeight = $taille;
}
else {
$destWidth = $taille;
$destHeight = floor($srcHeight/$ratioWidth);
}
} else {
$destWidth = $srcWidth;
$destHeight = $srcHeight;
}
// Initialisation de l'image destination
if ($GLOBALS['flag_ImageCreateTrueColor'] AND $destFormat != "gif")
$destImage = ImageCreateTrueColor($destWidth, $destHeight);
if (!$destImage)
$destImage = ImageCreate($destWidth, $destHeight);
// Recopie de l'image d'origine avec adaptation de la taille
$ok = false;
if ($GLOBALS['flag_ImageCopyResampled'])
$ok = ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
if (!$ok)
$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
// Sauvegarde de l'image destination
$destination = "IMG/$taille-$nom.$format";
if ($format == "jpg") {
ImageJPEG($destImage, $destination, 70);
}
else if ($format == "gif") {
ImageGIF($destImage, $destination);
}
else if ($format == "png") {
ImagePNG($destImage, $destination);
}
ImageDestroy($srcImage);
ImageDestroy($destImage);
return "<img src='$destination' name='$name' border='0' align='$align' alt='' hspace='$espace' vspace='$espace' class='spip_logos' />";
} else {
$taille_origine = @getimagesize("IMG/$logo");
if ($taille_origine) {
// Calculer le ratio
$srcWidth = $taille_origine[0];
$srcHeight = $taille_origine[1];
if ($srcWidth > $taille OR $srcHeight > $taille) {
$ratioWidth = $srcWidth/$taille;
$ratioHeight = $srcHeight/$taille;
if ($ratioWidth < $ratioHeight) {
$destWidth = floor($srcWidth/$ratioHeight);
$destHeight = $taille;
}
else {
$destWidth = $taille;
$destHeight = floor($srcHeight/$ratioWidth);
}
} else {
$destWidth = $srcWidth;
$destHeight = $srcHeight;
}
return "<img src='IMG/$logo' name='$name' width='$destWidth' height='$destHeight' border='0' align='$align' alt='' hspace='$espace' vspace='$espace' class='spip_logos' />";
}
}
}
}
}
//
// Recuperation de donnees dans le champ extra
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter