Image perspective avec librairie GD
Avec cette fonction, vous pourrez créer une image en perspective. Celle-ci gardera la même taille, avec un effet de droite à gauche ou de gauche à droite.
<?php
function imagePerspective($fichier, $hauteur_finale, $destination, $type = "g") {
list($width, $height) = getimagesize($fichier);
$hauteur_finale = $height - ($height * $hauteur_finale / 100);
$source = imagecreatefromjpeg($fichier);
$resultat = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($resultat, 255, 255, 255);
if ($type == "d")
{
for($i=0;$i<$width;$i++)
{
$sx = $i;
$sy = 0;
$hauteur = round($height - $hauteur_finale * round(1 - 100 * $i / $width / 100,2));
$dx = $i;
$dy = ($height - $hauteur) / 2;
imagecopyresized($resultat, $source, $dx, $dy, $sx, $sy, 1, $hauteur, 1, $height);
}
}
else
{
for($i=0;$i<$width;$i++)
{
$sx = $i;
$sy = 0;
$hauteur = round($height - $hauteur_finale * round(100 * $i / $width / 100,2));
$dx = $i;
$dy = ($height - $hauteur) / 2;
imagecopyresized($resultat, $source, $dx, $dy, $sx, $sy, 1, $hauteur, 1, $height);
}
}
$col = imagecolorallocatealpha($resultat, 0, 0, 0, 127);
imagecolortransparent($resultat, $col);
imagePNG($resultat, $destination, 100);
}
// exemple d'utilisation :
// imagePerspective("image_source.jpg", "80", "image_destination.jpg", "g");
// 80 signifie le pourcentage de diminution
// g signifie le coté de perspective (d = droit)
?>
| Date d'ajout : | 23/11/2009 |
| Catégorie : | Graphique |
| Vues : | 701 |
| Auteur : | Lejeune Cédric |
| [ Site Web ] [ Email ] | |
Dernières actualités
- 15 Mars 2012
- 14 Mars 2012
- 14 Mars 2012
- 19 Janvier 2012
- 09 Janvier 2012
www.editeurscripts.com
www.turfomania.fr
www.banques-en-ligne.fr
www.esfacturesdevis.com
![]() |
Température actuelle : 12°C Condition actuelle : Temps clair |
Humidité : 62 %
Vent : E à 23 km/h





