Cherche script utilisant GD

WRInaute passionné
Hello,

Quelqu'un pourrais il m'indiquer le code pour redimensionner une image, avec par exemple une hauteur a respecter, et que le script redimenssionne l'image en largeur proportionnellement a la hauteur indiqué, ou l'inverse, ou mieux, je sais pas avec des %tages etc
 
WRInaute accro
j ai un vieux bout de code à mettre à jour avec les nouvells fonctions php4 (ex : move_upload_files(), etc...)

function copier_image($photo,$nom_photo,$destination,$longueur_max,$hauteur_max)
{
// ----extention --------
$ext = explode(".", $nom_photo);
if(count($ext) > 1) $ext = strtolower(end($ext));
if (($ext=='jpg') or ($ext=='jpeg') or ($ext=='jpe'))
{
$type='jpg';
$est_image='oui';
}
else if ($ext=='gif')
{
$type='gif';
$est_image='oui';
}
else if ($ext=='png')
{
$type='png';
$est_image='oui';
}
else $est_image='non';

if ($est_image=='oui')
{
// ----info de l'image
$size = GetImageSize($photo);
if ($type=='jpg') $src_im = ImageCreateFromJpeg($photo);
else if ($type=='gif') $src_im = ImageCreateFromGif($photo);
else if ($type=='png') $src_im = ImageCreateFromPng($photo);
$longueur_photo = $size[0];
$hauteur_photo = $size[1];
//----- si dimensions ok, la copier
if (($longueur_photo<$longueur_max) and ($hauteur_photo<$hauteur_max))
{
if (copy($photo, $destination)) return true;
else return false;
}
else
{
// ----modifier longueur
if ($longueur_photo > $longueur_max)
{
$hauteur_photo=round(($longueur_max / $longueur_photo) * $hauteur_photo);
$longueur_photo=$longueur_max;
}
// ----modifier hauteur
if ($hauteur_photo > $hauteur_max)
{
$longueur_photo=round(($hauteur_max / $hauteur_photo) * $longueur_photo);
$hauteur_photo=$hauteur_max;
}
$dst_im = ImageCreateTrueColor($longueur_photo,$hauteur_photo);
ImageCopyResampled($dst_im,$src_im,0,0,0,0,$longueur_photo,$hauteur_photo,$size[0],$size[1]);

if (ImageJpeg($dst_im,$destination)) echo "";
else echo "<script>alert('ERREUR : Photo $nom_photo non copiée')</script>";
}
}
else echo "<script>alert('Attention : La photo n\'est pas au format valide (jpg, gif, png). elle ne sera donc pas copiée')</script>";

}
 
WRInaute discret
Spip le fait automatiquement. Tu peux toujours télécharger les fichiers et voir quel code ils utilisent. Le filtre s'appelle reduire_image mais il renvoie je crois vers creer_vignette ou un truc comme ça.

Les fichiers intéressants s'appellent inc_filtres.php3 et inc_logos.php3.

Y'a un peu d'adaptation à faire, mais au moins tu devrais avoir du code propre.
 

➡️ Offre MyRankingMetrics ⬅️

pré-audit SEO gratuit avec RM Tech (+ avis d'expert)
coaching offert aux clients (avec Olivier Duffez ou Fabien Faceries)

Voir les détails ici

coaching SEO
Discussions similaires
Haut