Watermark sur image en PHP (à la volée)
Salutations,
J'ai besoin de copyrighter des images sur un site.
Ces images sont en JPG.
Il y a des thumbnails et des versions HD.
Pour les thumbnails, aucun pb.
Le pb qu'il me reste est sur un tag href...
J'explique...
Mon fichier watermark.php :
Code:
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
| <?php
// this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
// where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script
// where this script is named watermark.php
// call this script with an image tag
// <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
$imagesource = $_GET['path'];
$watermarkPath = $_GET['wm'];
$filetype = substr($imagesource,strlen($imagesource)-4,4);
$filetype = strtolower($filetype);
$watermarkType = substr($watermarkPath,strlen($watermarkPath)-4,4);
$watermarkType = strtolower($watermarkType);
if($filetype == ".gif")
$image = @imagecreatefromgif($imagesource);
else
if($filetype == ".jpg" || $filetype == "jpeg" || $filetype == "JPG")
$image = @imagecreatefromjpeg($imagesource);
else
if($filetype == ".png")
$image = @imagecreatefrompng($imagesource);
else
die();
if(!$image)
die();
if($watermarkType == ".gif")
$watermark = @imagecreatefromgif($watermarkPath);
else
if($watermarkType == ".png")
$watermark = @imagecreatefrompng($watermarkPath);
else
die();
if(!$watermark)
die();
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth) );
$startheight = (($imageheight - $watermarkheight) );
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?> |
Je l'appelle via une ligne du genre :
Code:
echo '<a href="watermark.php?path='.$tab1.'&wm=pict/wm.png" target ="_blank"><img height ="480" border="0" src="watermark.php?path='.$tab2.'&wm=pict/wm.png" alt="'.$tab1.'"></a>';
Le pb n'est pas sur le <img src, car cela marche, mais sur le href...
En effet, la page ouverte me sort un garbage monumental...
Any idea ?
Un pop-up javascript ?