Feel free to use/modify it as you wish =]
Code: Select all
<?
class Image
{
var $ext;
var $img;
function Image($url)
{
$this->ext = substr($url, -3);
$this->LoadImage($url);
}
function LoadImage($url)
{
switch($this->ext)
{
case "png":
case "PNG":
$this->img = imagecreatefrompng($url);
break;
case "jpg":
case "JPG":
$this->img = imagecreatefromjpeg($url);
break;
case "gif":
case "GIF":
$this->img = imagecreatefromgif($url);
break;
}
}
function Output($dest = '')
{
header("Content-type: image");
if($dest == '')
{
switch($this->ext)
{
case "png":
case "PNG":
imagepng($this->img);
break;
case "jpg":
case "JPG":
imagejpeg($this->img);
break;
case "gif":
case "GIF":
imagegif($this->img);
break;
}
}
else
{
switch($this->ext)
{
case "png":
case "PNG":
imagepng($this->img, $dest);
break;
case "jpg":
case "JPG":
imagejpeg($this->img, $dest);
break;
case "gif":
case "GIF":
imagegif($this->img, $dest);
break;
}
}
}
function Destroy()
{
imagedestroy($this->img);
}
function Transparent($r, $g, $b)
{
$color = imagecolorallocate($this->img, $r, $g, $b);
imagecolortransparent($this->img, $color);
}
function Resize($percent)
{
$img = $this->img;
$imw = imagesx($this->img);
$imh = imagesy($this->img);
$dw = round($imw*($percent/100));
$dh = round($imh*($percent/100));
$this->img = imagecreatetruecolor($dw, $dh);
imagecopyresampled($this->img, $img, 0, 0, 0, 0, $dw, $dh, $imw, $imh);
imagedestroy($img);
}
function Colorize($r, $g, $b, $factor)
{
$temp = imagecreatetruecolor(imagesx($this->img), imagesy($this->img));
$color = imagecolorallocate($r,$g,$b);
imagefill($temp, 0, 0, $color);
imagecopymerge($this->img, $temp, 0, 0, 0, 0, imagesx($temp), imagesy($temp), $factor);
imagedestroy($temp);
}
}
?>