[ 989 087 ]
[ 38.107.191.83 ]
Insérer un copyright sur une image avec la librairie GDVoici comment insérer un copyright sur une image, avec la librairie GD2.
Image du copyright (copyright.png) :
Mise en application- Le code pour insérer un copyright sur une image, enregistrez le sous "copyright_image.php" :
<?php
// on ouvre l'image
$file_image = $_SERVER['DOCUMENT_ROOT'].$_GET['image'];
if(exif_imagetype($file_image) == IMAGETYPE_PNG)
{$image = imagecreatefrompng($file_image);}
elseif(exif_imagetype($file_image) == IMAGETYPE_GIF)
{$image = imagecreatefromgif($file_image);}
elseif(exif_imagetype($file_image) == IMAGETYPE_JPEG)
{$image = imagecreatefromjpeg($file_image);}
// on ouvre le copyright
// /copyright/ est le répertoire ou vous stockerez l'image du copyright.
// $_SERVER["DOCUMENT_ROOT"] indique le chemin absolu ou votre base de site se situe.
$file_copyright = $_SERVER['DOCUMENT_ROOT'].'/copyright/copyright.png';
$copyright = imagecreatefrompng($file_copyright);
// on récupère les dimensions du copyright
list($w_copy, $h_copy) = getimagesize($file_copyright);
// on applique une transparence
$transparence = imagecolorallocate($copyright, 0, 0, 0);
imagefill($copyright, 0, 0, $transparence);
imagecolortransparent($copyright, $transparence);
// positionnement du copyright
$pos_x = 4; $pos_y = 4;
if($_GET['position'] == '2'){
$pos_x = imagesx($image) - ($w_copy + 4);}
elseif($_GET['position'] == '3'){
$pos_x = imagesx($image) - ($w_copy + 4);
$pos_y = imagesy($image) - ($h_copy + 4);}
elseif($_GET['position'] == '4'){
$pos_y = imagesy($image) - ($h_copy + 4);}
// on fusionne les images
imagecopymerge($image, $copyright, $pos_x, $pos_y, 0, 0, $w_copy, $h_copy, $_GET['opacity']);
// on affiche l'image finale
header("Content-type: image/png");
imagepng($image);
imagedestroy($image);
imagedestroy($copyright);
?>
Remarque : Les images de types JPG, GIF et PNG sont acceptées par le code. - Le code pour afficher notre image avec le copyright : <img src="copyright_image.php?image=/images/image.jpg&position=2&opacity=90" alt="" /> Variables utilisées pour l'affichage :
[0] commentaire - Voir/Editer |