1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
<?php
header ("Content-type: image/jpeg"); // C'est une image (nan sérrieux ?)
$a = date("Y"); // l'année (pour le copyright)
if(!isset($_GET['img'])){ // s'il n'y a pas d'image en GEt, on lui en donne une par défaut
$img = "/img/inconnu.jpg";
}
else{ // Sinon, on prend l'image concernée
$img = "/img/".$_GET['img'].".jpg";
}
/****************************************************
1 : Récupération de la photo à partir du get *
*****************************************************/
$photo = imagecreatefromjpeg($img);
/********************************************************
2 : Création d'une image vierge pour notre texte *
*********************************************************/
$copyright = imagecreate(200,50);
// Définition des couleurs
//$bleuclair = imagecolorallocate($copyright, 156, 227, 254);
$noir = imagecolorallocate($copyright, 0, 0, 0);
//$blanc = imagecolorallocate($copyright, 255, 255, 255);
// Ecriture de texte de copyright
imagestring($copyright, 4, 35, 15, "CC $a, http://Mayart.tk", $blanc);
imagecolortransparent($copyright, $noir); // On rend le fond noir transparent
// Tadam, le copyright est la !
imagepng($copyright);
/************************************
3 : Fusion des deux images *
*************************************/
// On charge d'abord les images
$source = imagecreatefrompng($copyright); // Le copyright est la source
$destination = imagecreatefromjpeg($photo); // La photo est la destination
// Les fonctions imagesx et imagesy renvoient la largeur et la hauteur d'une image
$largeur_source = imagesx($source);
$hauteur_source = imagesy($source);
$largeur_destination = imagesx($destination);
$hauteur_destination = imagesy($destination);
// On veut placer le logo en bas à* droite, on calcule les coordonnées où on doit placer le logo sur la photo
$destination_x = $largeur_destination - $largeur_source;
$destination_y = $hauteur_destination - $hauteur_source;
// On met le copyright (source) dans l'image de destination (la photo)
imagecopymerge($destination, $source, $destination_x, $destination_y, 0, 0, $largeur_source, $hauteur_source, 60);
/****************************************
4 : Affichage de l'image finale *
*****************************************/
imagejpeg($destination);
?> |
Partager