Cherche script utilisant GD
3 messages
• Page 1 sur 1
- zimounet
- WRInaute passionné

- Messages: 1796
- Inscription: 8 Nov 2004
Cherche script utilisant GD
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
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
-

e-kiwi - Modérateur

- Messages: 15544
- Inscription: 23 Déc 2003
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>";
}
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>";
}
- Seb-
- WRInaute discret

- Messages: 188
- Inscription: 6 Mar 2005
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.
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.
3 messages
• Page 1 sur 1
Lectures recommandées sur ce thème :
- Moteur de recherche dans les blogs de Google - 24-01-2007
- Les albums web Picasa passent à 1 Go de stockage - 08-03-2007
- Google Chrome dépasse Safari aux USA - 29-06-2010
- Photos satellite des incendies en Grèce dans Google Earth - 30-08-2007
- Ajouter un Gadget Google sur son site - 04-10-2006
- Google Desktop pour Mac OS X - 05-04-2007
- Google cherche à se développer au Japon - 19-10-2004
- Picasa Web Albums en français - 08-12-2006
Qui est en ligne
Utilisateurs parcourant ce forum: salva et 0 invités
