class ThumbMaker
{
private $options = array('file' => null, 'name' => null, 'type' => null, 'orig_w' => 0, 'orig_h' => 0, 'width' => 0, 'height' => 0,
'pos_X' => 0, 'pos_Y' => 0, 'resize' => true,
'savepath' => false, 'savename' => null);
function __construct($arg, $path = false)
{
$this->options['file'] = (string)$arg['f'];
if( $this->CheckFile($this->options['file']) )
{
$this->SetOptions($arg, $path);
if( !$this->CheckThumb() )
$this->Make();
else
$this->Show( '', $this->options['savepath']. '/' .$this->options['savename'] );
}
else
$this->Error($arg['w'], $arg['h']);
}
function CheckFile($file)
{
{
$info = pathinfo($this->options['file']); $this->options['type'] = $info['extension'];
$this->options['name'] = $info['filename'];
return true;
}
elseif(@fopen($file, "r")) {
$info = explode("/", $this->options['file']); $this->options['type'] = end($ext); $this->options['name'] = $ext[0];
return true;
}
else
return false;
}
function SetOptions($arg, $path)
{
$this->options['width'] = (int)$arg['w'];
$this->options['height'] = (int)$arg['h'];
{
$this->options['pos_X'] = $pos[0];
$this->options['pos_Y'] = $pos[0];
}
$this->options['resize'] = false;
$this->options['savepath'] = $path;
$this->options['savename'] = md5( implode($this->options) ). '.' .$this->options['type']; }
function CheckThumb()
{
if(file_exists($this->options['savepath']. '/' .$this->options['savename'])) return true;
else
return false;
}
function Make()
{
$img = $this->CreateImg($this->options['file']);
$percent = $this->options['width'] / $this->options['orig_w'];
$new['width'] = $this->options['orig_w'] * $percent;
$new['height'] = $this->options['orig_h'] * $percent;
$topX = 0; $topY = 0;
if( $this->options['pos_X']!=0 )
{
$topX = $this->options['pos_X'];
$topY = $this->options['pos_Y'];
}
elseif( $this->options['orig_w'] <= $this->options['orig_h'] )
$topY = $new['height'] * 0.3;
if($this->options['resize'])
{
$new['width'], $new['height'],
$this->options['orig_w'], $this->options['orig_h']);
}
else
{
$this->options['orig_w'], $this->options['orig_h'],
$this->options['orig_w'], $this->options['orig_h']);
}
$this->Show($new_img, false, $this->options['savepath'].'/'.$this->options['savename']);
}
function CreateImg($file)
{
switch($this->options['type'])
{
case 'jpg' :
}
}
function Show($img, $file = false, $save = null)
{
if($file)
$img = $this->CreateImg($file);
switch($this->options['type'])
{
case 'jpg' :
case 'jpeg':header('Content-type: image/jpeg'); break;
case 'gif' :header('Content-type: image/gif'); break;
case 'png' :header('Content-type: image/png'); break;
}
}
function Error($width, $height)
{
$height = $width / 2;
$textSize = 5;
if($width<=50)
{
$textSize = 2;
imagestring($img, $textSize, 15, 5, "Nem", $text_color); imagestring($img, $textSize, 1, 20, "elérhető!", $text_color); }
else
imagestring($img, $textSize, 5, 5, "Nem elérhető!", $text_color);
header('Content-type: image/jpeg'); }
}
new ThumbMaker($_GET, 'thumb');