<?php
/**
* Rounded PHP, Rounded corners made easy.
*
* rounded.php
*
* PHP version 5, GD version 2
*
* Copyright (C) 2008 Tree Fort LLC
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category Rounded PHP
* @package <none>
* @author Nevada Kent <hide@address.com>
* @version 1.1
* @link http://dev.kingthief.com
* @link http://dev.kingthief.com/demos/roundedphp
* @link http://www.sourceforge.net/projects/roundedphp
*/
define('ROUNDED_DEBUG', false);
# Required classes
require_once 'Rounded/Color.php';
require_once 'Rounded/Corner.php';
require_once 'Rounded/Rectangle.php';
require_once 'Rounded/Side.php';
if (isset($_GET['params'])) {
$params = preg_replace(array('/^[\/]+/', '/[\/]+$/'), '', $_GET['params']);
$vars = array();
$params = explode('/', $params);
foreach ($params as $param) {
$a = explode('_', $param);
$vars[$a[0]] = $a[1];
}
extract($vars);
} else
extract($_GET);
# Options =
# - Shape: 'c' (or 'corner'), 'r' (or 'rectangle'), 's' (or 'side')
# - Radius: (integer >= 0)
# - Width: (integer >= 2)
# - Height: (integer >= 2)
# - Border Width: (integer >= 0)
# - Foreground Color: (hex code - 3 or 6 char)
# - Background Color: (hex code - 3 or 6 char)
# - Border Color: (hex code - 3 or 6 char)
# - Orientation: 'tl' (or 'lt'), 'tr' (or 'rt'), 'bl' (or 'lb'), 'br' (or 'rb')
# - Side: 't', 'top', 'l', 'left', 'b', 'bottom', 'r', 'right'
# - Antialias: 1, 0
# - Format: 'png', 'gif', 'jpg' (or 'jpeg')
# - Background Opacity: (0 <= integer <= 100)
# - Border Opacity: (0 <= integer <= 100)
# - Foreground Opacity: (0 <= integer <= 100)
# - Transparent Color: (hex code - 3 or 6 char)
$shape = isset($shape) ? strval($shape) : (isset($sh) ? strval($sh) : 'c');
$radius = isset($radius) ? intval($radius) : (isset($r) ? intval($r) : 10);
$width = isset($width) ? intval($width) : (isset($w) ? intval($w) : 100);
$height = isset($height) ? intval($height) : (isset($h) ? intval($h) : 100);
$foregroundcolor = isset($foregroundcolor) ? strval($foregroundcolor) : (isset($fgc) ? strval($fgc) : 'CCCCCC');
$backgroundcolor = isset($backgroundcolor) ? strval($backgroundcolor) : (isset($bgc) ? strval($bgc) : 'FFFFFF');
$bordercolor = isset($bordercolor) ? strval($bordercolor) : (isset($bc) ? strval($bc) : '000000');
$borderwidth = isset($borderwidth) ? intval($borderwidth) : (isset($bw) ? intval($bw) : 0);
$orientation = isset($orientation) ? strval($orientation) : (isset($o) ? strval($o) : 'tl');
$side = isset($side) ? strval($side) : (isset($si) ? strval($si) : 'top');
$antialias = isset($antialias) ? (bool) intval($antialias) : (isset($aa) ? (bool) intval($aa) : true);
$format = isset($format) ? strval($format) : (isset($f) ? strval($f) : 'png');
$backgroundopacity = isset($backgroundopacity) ? intval($backgroundopacity) : (isset($bgo) ? intval($bgo) : 100);
$borderopacity = isset($borderopacity) ? intval($borderopacity) : (isset($bo) ? intval($bo) : 100);
$foregroundopacity = isset($foregroundopacity) ? intval($foregroundopacity) : (isset($fgo) ? intval($fgo) : 100);
$transparentcolor = isset($transparentcolor) ? strval($transparentcolor) : (isset($tc) ? strval($tc) : NULL);
switch (strtolower($format)) {
case 'jpg' :
case 'jpeg' :
$transparentcolor = NULL;
case 'gif' :
$backgroundopacity = 100;
$borderopacity = 100;
$foregroundopacity = 100;
break;
case 'png' :
$transparentcolor = NULL;
break;
}
$params = array(
'radius' => $radius,
'width' => $width,
'height' => $height,
'borderwidth' => $borderwidth,
'orientation' => $orientation,
'side' => $side,
'antialias' => $antialias,
'colors' => array(
'foreground' => new Color($foregroundcolor, $foregroundopacity / 100),
'border' => new Color($bordercolor, $borderopacity / 100),
'background' => new Color($backgroundcolor, $backgroundopacity / 100)
)
);
switch (strtolower($shape)) {
case 'r' :
case 'rect' :
case 'rectangle' :
$img = Rectangle::create($params);
break;
case 's' :
case 'side' :
$img = Side::create($params);
break;
case 'c' :
case 'corner' :
default :
$img = Corner::create($params);
break;
}
imagesavealpha($img, true);
if (!is_null($transparentcolor) && $transparentcolor) {
$color = new Color($transparentcolor);
imagecolortransparent($img, $color->getColorResource($img));
}
if (!ROUNDED_DEBUG) {
header('Cache-Control: max-age=3600, must-revalidate');
header('Pragma: cache');
switch (strtolower($format)) {
case 'jpg' :
case 'jpeg' :
header('Content-Type: image/jpeg');
imagejpeg($img, '', 100);
break;
case 'gif' :
header('Content-Type: image/gif');
imagegif($img);
break;
case 'png' :
default :
header('Content-Type: image/png');
imagepng($img);
break;
}
}
?>