Vous êtes ici : Accueil > Ressources > Codes Sources PHP / mySQL > Image perspective avec librairie GD

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($resultat255255255);

    if (
$type == "d")
    {
        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$sy1$hauteur1$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$sy1$hauteur1$height);
        }
    }
    
    
$col imagecolorallocatealpha($resultat000127);
    
imagecolortransparent($resultat$col);

        
imagePNG($resultat$destination100);
}

// 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 ]

Suivre editeurscripts sur Twitter

On vous rappelle


Jplayer : Un player MP3 Javascript et CSS personnalisable

Calculer votre pagerank

Url de votre site :


  • PageRank www.editeurscripts.com
  • PageRank www.turfomania.fr
  • PageRank www.banques-en-ligne.fr
  • PageRank www.esfacturesdevis.com

Restez en contact

Facebook Facebook

RSS RSS

Version Mobile Version Mobile


Météo du jour

Temps clair

Température actuelle : 12°C

Condition actuelle : Temps clair

Humidité : 62 %

Vent : E à 23 km/h

» Plus d'informations