<?php
// Globals
define("pathim", '../images/');
define("w_wat", 42); // Largeur watermark
define("h_wat", 28); // Hauteur watermark
// ----------------------------------------------------- Fonctions
// ----------------------------------------------------- ---------
function im_croix(){
// Création de l'image
$n_im = @imagecreate (189, 39);
// Fond + Contour
$background_color = imagecolorallocate ($n_im, 51, 51, 51);
imagefilledrectangle ($n_im, 2, 2, 186, 36, imagecolorallocate ($n_im, 0, 0, 0));
// Image croix
imagefilledrectangle ($n_im, 6, 6, 19, 20, imagecolorallocate ($n_im, 128, 128, 128));
imagefilledrectangle ($n_im, 7, 7, 19, 21, imagecolorallocate ($n_im, 51, 51, 51));
imagefilledrectangle ($n_im, 7, 7, 18, 20, imagecolorallocate ($n_im, 192, 192, 192));
imagefilledrectangle ($n_im, 7, 7, 17, 19, imagecolorallocate ($n_im, 255, 255, 255));
imagefilledrectangle ($n_im, 10, 11, 15, 15, imagecolorallocate ($n_im, 255, 0, 0));
imageline ($n_im, 12, 11, 13, 11, imagecolorallocate ($n_im, 255, 255, 255));
imageline ($n_im, 12, 15, 13, 15, imagecolorallocate ($n_im, 255, 255, 255));
imageline ($n_im, 10, 13, 11, 13, imagecolorallocate ($n_im, 255, 255, 255));
imageline ($n_im, 14, 13, 15, 13, imagecolorallocate ($n_im, 255, 255, 255));
imagesetpixel ($n_im, 10, 12, imagecolorallocate ($n_im, 255, 255, 255));
imagesetpixel ($n_im, 15, 12, imagecolorallocate ($n_im, 255, 255, 255));
imagesetpixel ($n_im, 10, 14, imagecolorallocate ($n_im, 255, 255, 255));
imagesetpixel ($n_im, 15, 14, imagecolorallocate ($n_im, 255, 255, 255));
imagesetpixel ($n_im, 6, 21, imagecolorallocate ($n_im, 51, 51, 51));
// Texte
$text_color = imagecolorallocate ($n_im, 46, 186, 141);
$font = imageloadfont(pathim . 'hootie.gdf');
imagestring ($n_im, $font, 26, 10, "Pas d'image", $text_color);
// Création de l'image
header ("Content-type: image/gif");
imagegif ($n_im);
// Destruction des ressources images
imagedestroy($n_im);
return True;
}
function GetSource() {
// Récupère le fichier source
$src = $_GET['src'];
if (strtolower((substr($src, 0, 4))) != "http") { $src = '../' . $src; }
$src = str_replace(' ','%20',$src); //REPLACE THE SPACES
return $src;
}
function ReSizes ($s_width, $s_height, $s_src){
if ($s_width > 220){
$mul = 220 / $s_width;
$n_width = 220;
$n_height = $s_height * $mul;
if ($n_height > 220){
$mul = 220 / $n_height;
$n_height = 220;
$n_width = $n_width * $mul;
}
$n_im = @imagecreatetruecolor ($n_width, $n_height);
imagecopyresized ($n_im, $s_src, 0, 0, 0, 0, $n_width, $n_height, $s_width, $s_height);
}else{
$n_width = $s_width;
$n_height = $s_height;
$n_im = @imagecreatetruecolor ($n_width, $n_height);
imagecopy ($n_im, $s_src, 0, 0, 0, 0, $n_width, $n_height);
}
$RetVal = array (
'n_width' => $n_width,
'n_height' => $n_height,
'n_im' => $n_im);
imagedestroy($s_src);
return $RetVal;
}
function doWaterM ($width, $height, $n_im){
$l_logo = imagecreatefrompng (pathim . "logo.png");
$l_x = $width - w_wat - 5;
$l_y = $height - h_wat - 5;
imagecopy ($n_im, $l_logo, $l_x, $l_y, 0, 0, w_wat, h_wat);
imagedestroy($l_logo);
}
// ----------------------------------------------------- Page
// ----------------------------------------------------- ----
if (!isset ($_GET['src'])){
im_croix();
exit;
}
$src = GetSource();
list($s_width, $s_height, $s_type, $s_attr) = getimagesize($src);
switch ($s_type){
case 1 : // GIF
// Création des ressrouces
$s_src = imagecreatefromgif ($src);
imagealphablending($s_src,true);
// Changements de tailles
$ret = ReSizes ($s_width, $s_height, $s_src);
// Water mark
doWaterM ($ret['n_width'], $ret['n_height'], $ret['n_im']);
// Création de l'image
header ("Content-type: image/gif");
imagegif ($ret['n_im']);
// Destruction des images
imagedestroy($ret['n_im']);
break;
case 2 : // JPEG
// Création des ressrouces
$s_src = imagecreatefromjpeg ($src);
imagealphablending($s_src,true);
// Changements de tailles
$ret = ReSizes ($s_width, $s_height, $s_src);
// Water mark
doWaterM ($ret['n_width'], $ret['n_height'], $ret['n_im']);
// Création de l'image
header ("Content-type: image/jpeg");
imagejpeg ($ret['n_im']);
// Destruction des images
imagedestroy($ret['n_im']);
break;
case 3: // PNG
// Création des ressrouces
$s_src = imagecreatefrompng ($src);
imagealphablending($s_src,true);
// Changements de tailles
$ret = ReSizes ($s_width, $s_height, $s_src);
// Water mark
doWaterM ($ret['n_width'], $ret['n_height'], $ret['n_im']);
// Création de l'image
header ("Content-type: image/png");
imagepng ($ret['n_im']);
// Destruction des images
imagedestroy($ret['n_im']);
break;
case 6 : // BMP
$n_im = @imagecreate (189, 39);
// Fond + Contour
$background_color = imagecolorallocate ($n_im, 51, 51, 51);
imagefilledrectangle ($n_im, 2, 2, 186, 36, imagecolorallocate ($n_im, 0, 0, 0));
$text_color = imagecolorallocate ($n_im, 46, 186, 141);
imagestring ($n_im, 1, 10, 10, "Pas de .BMP svp", $text_color);
imagestring ($n_im, 1, 10, 25, "(Cliquez ici)", $text_color);
// Création de l'image
header ("Content-type: image/gif");
imagegif ($n_im);
// Destruction des images
imagedestroy($n_im);
break;
default :
$n_im = @imagecreate (189, 39);
// Fond + Contour
$background_color = imagecolorallocate ($n_im, 51, 51, 51);
imagefilledrectangle ($n_im, 2, 2, 186, 36, imagecolorallocate ($n_im, 0, 0, 0));
$text_color = imagecolorallocate ($n_im, 46, 186, 141);
imagestring ($n_im, 1, 10, 10, "Format d'image incorrect", $text_color);
imagestring ($n_im, 1, 10, 25, "(Cliquez ici)", $text_color);
// Création de l'image
header ("Content-type: image/gif");
imagegif ($n_im);
// Destruction des images
imagedestroy($n_im);
break;
}
?>