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 67 68 69 70
| # Redimmentionne et applique un philigramme.
function SaveResizedJPG($srcfile, $dstfile, $ext, $maxw=450, $maxh=325, $quality=75)
{
if($ext==".jpg" || $ext==".jpeg" || $ext==".jfif")
$imgsrc = imagecreatefromjpeg($srcfile);
elseif(strtolower($ext) == ".png")
$imgsrc = imagecreatefrompng($srcfile);
elseif(strtolower($ext) == ".gif")
$imgsrc = imagecreatefromgif($srcfile);
$w = $actw = imagesx($imgsrc);
$h = $acth = imagesy($imgsrc);
if (!$maxw) $maxw = 450;
if (!$maxh) $maxh = 325;
if (!$quality) $quality = 75;
if ($w > $maxw)
{
$w = $maxw;
$h = round($acth/$actw*$maxw);
}
if ($h > $maxh)
{
$h = $maxh;
$w = round($actw/$acth*$maxh);
}
$imgdest = imagecreatetruecolor($w,$h) or die ("Impossible de crée un flux d'image GD");
$size=getimagesize($srcfile);
$font="applegaramond-bold.ttf"; // Police utilisée pour écrire le filigrane
$filigrane="Copyright";
$t=20; // Taille de la police
$couleur_text = imagecolorallocatealpha($imgsrc, 255, 255, 255, 75);
$h=0;
$l=0;
$i=0;
//Cette double boucle permet de répeter le filigrane en croisé sur toute l'image (suivant sa taille)
while($h<$size[1])
{
while($l<$size[0])
{
imagettftext($imgsrc, $t, 0, $l, $h+$t, $couleur_text, $font, $filigrane);
$l=$l+400;
}
$i++;
if($i % 2){$l=200;}else{$l=0;}
$h=$h+100;
}
imagecopyresampled($imgdest, $imgsrc, 0, 0, 0, 0, $w, $h, $actw, $acth);
if (imagejpeg($imgdest, $dstfile, $quality))
{
echo "yes";
$ret = true;
}
else
{
echo "no";
$ret = false;
}
return $ret;
} |
Partager