File: /home/panama/public_html_old/image_class.php
<?
class image
{
var $image_property = "";
var $required = "";
function getImageInfo($imagename)
{
if(!file_exists($imagename))
{
trigger_error("Image Library version 2.0 : The image path provided is not a valid path",E_USER_ERROR);
return false;
} // end of the if condition
$this->image_property = getimagesize($imagename); //getting the image size
return true;
}
function __getRatio()
{
if($this->required["height"] > $this->required["width"])
{
if($this->image_property[0] > $this->image_property[1])
{
$ratio = $this->image_property[1] / $this->image_property[0];
$this->image_property[5] = $this->required["width"];
$this->image_property[6] = $this->image_property[5] * $ratio;
}
else
{
$ratio = $this->image_property[0] / $this->image_property[1];
$this->image_property[6] = $this->required["width"];
$this->image_property[5] = $this->image_property[6] * $ratio;
}
}
else
{
if($this->image_property[0] > $this->image_property[1])
{
$ratio = $this->image_property[1] / $this->image_property[0];
$this->image_property[5] = $this->required["width"];
$this->image_property[6] = $this->image_property[5] * $ratio;
}
else
{
$ratio = $this->image_property[0] / $this->image_property[1];
$this->image_property[6] = $this->required["height"];
$this->image_property[5] = $this->image_property[6] * $ratio;
}
}
$this->required["width"] = $this->image_property[5];
$this->required["height"] = $this->image_property[6];
}
function createthumb($img, $new_width, $new_height)
{
//First, check for a valid file.
if (is_file($img))
{
//Now, get the current file size.
if ($this->getImageInfo($img))
{
$this->required['width'] = $new_width;
$this->required['height'] = $new_height;
$this->__getRatio();
//Now that we have the size constraints, let's find the file type.
$thepath = pathinfo ($img);
//Set up our thumbnail.
$dst = imagecreatetruecolor($this->required["width"], $this->required["height"]);
//Make a file name.
$filename = str_replace (".".$thepath['extension'], "", $thepath["basename"]);
$filename = $thepath["dirname"]."/thumb_".$filename . "" . $size . "." . $thepath['extension'];
$types = array('jpg' => array('imagecreatefromjpeg', 'imagejpeg'),
'jpeg' => array('imagecreatefromjpeg', 'imagejpeg'),
'gif' => array('imagecreatefromgif', 'imagegif'),
'png' => array('imagecreatefrompng', 'imagepng'));
$x_type = strtolower($thepath['extension']);
$func = $types[$x_type][0];
$src = $func($img);
//Create the copy.
imagecopyresampled($dst, $src, 0, 0, 0, 0,$this->required["width"], $this->required["height"],$this->image_property[0], $this->image_property[1]);
//Create the thumbnail.
$func = $types[$x_type][1];
$func($dst, $filename);
return $dest;
}
}
//echo "No image found.";
}
function display_image($imagename , $new_width , $new_height)
{
$this->required['width'] = $new_width;
$this->required['height'] = $new_height;
//echo $imagename;
$this->image_property = getimagesize($imagename);
$this->__getRatio();
}
function getBackground($img,$color,$bgArray)
{
if(!$color) return false;
$c = $this->getColor($color,$img);
if(!$c) return false;
//@ imagefill($img, 0, 0, $c);
//x,y,w,h
imagefilledrectangle ($img,$bgArray["x"],$bgArray["y"],$bgArray["w"],$bgArray["h"],$c);
}
//imagecolorat
function getColor($color,$img)
{
if(!$color) return false;
$c = $this->rgb2hex2rgb($color);
if(!is_array($c)) return false;
return @ imagecolorallocate($img, $c['r'], $c['g'], $c['b']);
}
function rgb2hex2rgb($c)
{
if(!$c) return false;
$c = trim($c);
$out = false;
if(eregi("^[0-9ABCDEFabcdef\#]+$", $c)){
$c = str_replace('#','', $c);
$l = strlen($c);
if($l == 3){
unset($out);
$out[0] = $out['r'] = $out['red'] = hexdec(substr($c, 0,1));
$out[1] = $out['g'] = $out['green'] = hexdec(substr($c, 1,1));
$out[2] = $out['b'] = $out['blue'] = hexdec(substr($c, 2,1));
}elseif($l == 6){
unset($out);
$out[0] = $out['r'] = $out['red'] = hexdec(substr($c, 0,2));
$out[1] = $out['g'] = $out['green'] = hexdec(substr($c, 2,2));
$out[2] = $out['b'] = $out['blue'] = hexdec(substr($c, 4,2));
}else $out = false;
}elseif (eregi("^[0-9]+(,| |.)+[0-9]+(,| |.)+[0-9]+$", $c)){
if(eregi(",", $c))
$e = explode(",",$c);
else if(eregi(" ", $c))
$e = explode(" ",$c);
else if(eregi(".", $c))
$e = explode(".",$c);
else return false;
if(count($e) != 3) return false;
$out = '#';
for($i = 0; $i<3; $i++)
$e[$i] = dechex(($e[$i] <= 0)?0:(($e[$i] >= 255)?255:$e[$i]));
for($i = 0; $i<3; $i++)
$out .= ((strlen($e[$i]) < 2)?'0':'').$e[$i];
$out = strtoupper($out);
}else $out = false;
return $out;
}
//new fill image function start here
function imageFillColorXY($imgHeight,$imgObj)
{
$array = array();
for($i=0;$i<$imgHeight;$i++)
{
$color_index = imagecolorat($imgObj, $i, $i);
$color[$i] = imagecolorsforindex($imgObj, $color_index);
if($color[$i]['red'] == 255 && $color[$i]['green'] == 255 && $color[$i]['blue'] == 255)
{
$array["x"] = $i;
$array["y"] = $i;
break;
}
}
return $array;
}
function imageFillColorHeight($imageFillColorX,$imgHeight,$imgObj)
{
$ih=0;
for($i=$imageFillColorX;$i<$imgHeight;$i++)
{
$color_index = imagecolorat($imgObj, $imageFillColorX, $i);
$color[$i] = imagecolorsforindex($imgObj, $color_index);
if($color[$i]['red'] == 255 && $color[$i]['green'] == 255 && $color[$i]['blue'] == 255)
{
$ih++;
}
}
return $ih;
}
function imageFillColorWidth($imageFillColorY,$imgWidth,$imgObj)
{
$iw=0;
for($i=$imageFillColorY;$i<$imgWidth;$i++)
{
$color_index = imagecolorat($imgObj,$i,$imageFillColorY);
$color[$i] = imagecolorsforindex($imgObj, $color_index);
if($color[$i]['red'] == 255 && $color[$i]['green'] == 255 && $color[$i]['blue'] == 255)
{
$iw++;
}
}
return $iw;
}
}
?>