<?php
/***** arguments pour charger la page: image.php?file=imagefileURL&type=format&w=largeur&h=hauteur&title=titre&align=alignementX&valign=alignementY ******/
$f = $_GET['file'];
$dst = $_GET['dst'];
$GLOBALS['titlefont'] = 5;
/** retourne les nouvelles dimensions de l'image ajuste aux dimensions originales (pas de distortions)*/
function getSize($im) {
if(isset($_GET['w'])) $w = $_GET['w'];
if(isset($_GET['h'])) $h = $_GET['h'];
if(!isset($w) || $w == 0) $w = imagesx($im)/imagesy($im) * $h;
if(!isset($h) || $h == 0) $h = imagesy($im)/imagesx($im) * $w;
if($w == 0 && $h == 0) { $w = imagesx($im); $h = imagesy($im); }
return array($w,$h);
}
/** applique le copyright */
function copyright(&$im) {
$str = "(c) b23:production ".date('Y');
$font = 2; $inset = 1; $color = imagecolorallocatealpha($im, 255,50,0,50);
$s = getSize($im); $x = $s[0] - imagefontwidth($font) * ($inset + strlen($str)); $y = $s[1] - imagefontheight($font) * $inset;
imagestring($im, $font, $x, $y, $str, $color);
}
/** applique un titre */
function title(&$im, $title, $align = "left", $valign = "center") {
$font = $GLOBALS['titlefont']; $inset = 2; $color = imagecolorallocatealpha($im, 255,50,0,20);
$s = getSize($im);
switch($align) {
case "left":
$x = imagefontwidth($font) * ($inset);
break;
case "right":
$x = $s[0] - imagefontwidth($font) * ($inset + strlen($title));
break;
case "center":
$x = intval($s[0]/2) - imagefontwidth($font) * intval(strlen($title)/2);
break;
default: $x = imagefontwidth($font) * ($inset);
}
switch($valign) {
case "top":
$y = imagefontheight($font) * $inset;
break;
case "bottom":
$y = $s[1] - imagefontheight($font) * $inset;
break;
case "center":
$y = intval($s[1]/2) - intval(imagefontheight($font)/2);
break;
default: $y = $s[1] - imagefontheight($font) * $inset;
}
imagestring($im, $font, $x, $y, $title, $color);
}
// les formats supports par php 4 et 5
if (function_exists("imagegif") && $_GET['type'] == 'gif') {
$im = imagecreatefromgif($f);
$s = getSize($im); $im_r = imagecreatetruecolor($s[0], $s[1]);
$trans = imagecolortransparent($im); //imagecolorallocatealpha($im_r,0,0,0,127);
imagecolortransparent($im_r, $trans);
imagecopyresampled($im_r, $im, 0, 0, 0, 0, $s[0], $s[1], imagesx($im), imagesy($im)); // imagesavealpha($im_r, true);
if(isset($_GET['title'])) title($im_r, $_GET['title'], $_GET['align'], $_GET['valign']);
copyright($im_r);
header("Content-type: image/gif");
imagegif($im_r,$dst);
}
elseif (function_exists("imagejpeg") && $_GET['type'] == 'jpeg') {
$im = imagecreatefromjpeg($f);
$s = getSize($im); $im_r = imagecreatetruecolor($s[0], $s[1]);
$trans = imagecolortransparent($im); //imagecolorallocatealpha($im_r,0,0,0,127);
imagecolortransparent($im_r, $trans);
imagecopyresampled($im_r, $im, 0, 0, 0, 0, $s[0], $s[1], imagesx($im), imagesy($im));
if(isset($_GET['title'])) title($im_r, $_GET['title'], $_GET['align'], $_GET['valign']);
copyright($im_r);
header("Content-type: image/jpeg");
imagejpeg($im_r, $dst, 80);
}
elseif (function_exists("imagepng") && $_GET['type'] == 'png') {
$im = imagecreatefrompng($f);
$s = getSize($im); $im_r = imagecreatetruecolor($s[0], $s[1]);
$trans = imagecolortransparent($im); //imagecolorallocatealpha($im_r,0,0,0,127);
imagecolortransparent($im_r, $trans);
imagecopyresampled($im_r, $im, 0, 0, 0, 0, $s[0], $s[1], imagesx($im), imagesy($im));
if(isset($_GET['title'])) title($im_r, $_GET['title'], $_GET['align'], $_GET['valign']);
copyright($im_r);
header("Content-type: image/png");
imagepng($im_r,$dst);
} elseif (function_exists("imagewbmp") && $_GET['type'] == 'wbmp') {
$im = imagecreatefrowbmp($f);
$s = getSize($im); $im_r = imagecreatetruecolor($s[0], $s[1]);
$trans = imagecolortransparent($im); //imagecolorallocatealpha($im_r,0,0,0,127);
imagecolortransparent($im_r, $trans);
imagecopyresampled($im_r, $im, 0, 0, 0, 0, $s[0], $s[1], imagesx($im), imagesy($im));
if(isset($_GET['title'])) title($im_r, $_GET['title'], $_GET['align'], $_GET['valign']);
copyright($im_r);
header("Content-type: image/vnd.wap.wbmp");
imagewbmp($im_r,$dst);
} else {
die("Pas de support graphique avec PHP sur ce serveur");
} imagedestroy($im_r);
?>