|
|
@ -20,15 +20,15 @@ class image { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function createimagefromtype($file,$handler) { |
|
|
|
function createimagefromtype($file,$handler) { |
|
|
|
$size = getimagesize($file); |
|
|
|
$size = @getimagesize($file); |
|
|
|
$type=$size[2]; |
|
|
|
$type=$size[2]; |
|
|
|
|
|
|
|
|
|
|
|
switch ($type) { |
|
|
|
switch ($type) { |
|
|
|
case 2 : $imhandler = imagecreatefromjpeg($file); |
|
|
|
case 2 : $imhandler = @imagecreatefromjpeg($file); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 3 : $imhandler = imagecreatefrompng($file); |
|
|
|
case 3 : $imhandler = @imagecreatefrompng($file); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 1 : $imhandler = imagecreatefromgif($file); |
|
|
|
case 1 : $imhandler = @imagecreatefromgif($file); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -53,44 +53,44 @@ class image { |
|
|
|
$height = (int)($size[1]*$scale); |
|
|
|
$height = (int)($size[1]*$scale); |
|
|
|
$deltaw = (int)(($thumbw - $width)/2); |
|
|
|
$deltaw = (int)(($thumbw - $width)/2); |
|
|
|
$deltah = (int)(($thumbh - $height)/2); |
|
|
|
$deltah = (int)(($thumbh - $height)/2); |
|
|
|
$dst_img = ImageCreateTrueColor($thumbw, $thumbh); |
|
|
|
$dst_img = @ImageCreateTrueColor($thumbw, $thumbh); |
|
|
|
if ( !empty($this->color)) |
|
|
|
if ( !empty($this->color)) |
|
|
|
imagefill ( $dst_img, 0, 0, $this->color ); |
|
|
|
@imagefill ( $dst_img, 0, 0, $this->color ); |
|
|
|
$this->bgx=$thumbw; |
|
|
|
$this->bgx=$thumbw; |
|
|
|
$this->bgy=$thumbh; |
|
|
|
$this->bgy=$thumbh; |
|
|
|
} |
|
|
|
} |
|
|
|
elseif ($border==0) { |
|
|
|
elseif ($border==0) { |
|
|
|
$scale = min($thumbw/$size[0], $thumbh/$size[1]); |
|
|
|
$scale = ($size[0] > 0 && $size[1] >0)?min($thumbw/$size[0], $thumbh/$size[1]):0; |
|
|
|
$width = (int)($size[0]*$scale); |
|
|
|
$width = (int)($size[0]*$scale); |
|
|
|
$height = (int)($size[1]*$scale); |
|
|
|
$height = (int)($size[1]*$scale); |
|
|
|
|
|
|
|
|
|
|
|
$deltaw = 0; |
|
|
|
$deltaw = 0; |
|
|
|
$deltah = 0; |
|
|
|
$deltah = 0; |
|
|
|
$dst_img = ImageCreateTrueColor($width, $height); |
|
|
|
$dst_img = @ImageCreateTrueColor($width, $height); |
|
|
|
$this->bgx=$width; |
|
|
|
$this->bgx=$width; |
|
|
|
$this->bgy=$height; |
|
|
|
$this->bgy=$height; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$src_img = $this->bg; |
|
|
|
$src_img = $this->bg; |
|
|
|
|
|
|
|
|
|
|
|
ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img),ImageSY($src_img)); |
|
|
|
@ImageCopyResampled($dst_img, $src_img, $deltaw, $deltah, 0, 0, $width, $height, ImageSX($src_img),ImageSY($src_img)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->bg=$dst_img; |
|
|
|
$this->bg=$dst_img; |
|
|
|
imagedestroy($src_img); |
|
|
|
@imagedestroy($src_img); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function addbackground($bgfile) { |
|
|
|
function addbackground($bgfile) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !empty($bgfile) && file_exists($bgfile) ) { $this->bg = image::createimagefromtype($bgfile,'bg'); |
|
|
|
if ( !empty($bgfile) && file_exists($bgfile) ) { $this->bg = image::createimagefromtype($bgfile,'bg'); |
|
|
|
imagealphablending( $this->bg ,TRUE ); |
|
|
|
@imagealphablending( $this->bg ,TRUE ); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function addlogo($file) { |
|
|
|
function addlogo($file) { |
|
|
|
$this->logo = image::createimagefromtype($file,'logo'); |
|
|
|
$this->logo = image::createimagefromtype($file,'logo'); |
|
|
|
imagealphablending( $this->logo ,TRUE ); |
|
|
|
@imagealphablending( $this->logo ,TRUE ); |
|
|
|
$size = getimagesize($file); |
|
|
|
$size = getimagesize($file); |
|
|
|
$this->logox=$size[0]; |
|
|
|
$this->logox=$size[0]; |
|
|
|
$this->logoy=$size[1]; |
|
|
|
$this->logoy=$size[1]; |
|
|
@ -100,11 +100,11 @@ class image { |
|
|
|
function mergelogo($x,$y,$alpha=100) { |
|
|
|
function mergelogo($x,$y,$alpha=100) { |
|
|
|
if ($x<0) $x=$this->bgx-$this->logox+$x; |
|
|
|
if ($x<0) $x=$this->bgx-$this->logox+$x; |
|
|
|
if ($y<0) $y=$this->bgy-$this->logoy+$y; |
|
|
|
if ($y<0) $y=$this->bgy-$this->logoy+$y; |
|
|
|
return imagecopymerge ( $this->bg, $this->logo, $x, $y, 0, 0, $this->logox, $this->logoy, $alpha ); |
|
|
|
return @imagecopymerge ( $this->bg, $this->logo, $x, $y, 0, 0, $this->logox, $this->logoy, $alpha ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function makecolor($red, $green, $blue) { |
|
|
|
function makecolor($red, $green, $blue) { |
|
|
|
$this->color = imagecolorallocate( $this->bg, $red, $green, $blue ); |
|
|
|
$this->color = @imagecolorallocate( $this->bg, $red, $green, $blue ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function setfont($fontfile) { |
|
|
|
function setfont($fontfile) { |
|
|
@ -116,7 +116,7 @@ class image { |
|
|
|
$this->fontfile='verdana'; |
|
|
|
$this->fontfile='verdana'; |
|
|
|
$text= preg_replace('`(?<!\r)\n`',"\r\n",$text); |
|
|
|
$text= preg_replace('`(?<!\r)\n`',"\r\n",$text); |
|
|
|
|
|
|
|
|
|
|
|
$box=imagettfbbox ( $size, $angle, $this->fontfile, $text ); |
|
|
|
$box=@imagettfbbox ( $size, $angle, $this->fontfile, $text ); |
|
|
|
if ($x<0) { |
|
|
|
if ($x<0) { |
|
|
|
$x=$this->bgx - max($box[2],$box[4]) + $x; |
|
|
|
$x=$this->bgx - max($box[2],$box[4]) + $x; |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -128,7 +128,7 @@ class image { |
|
|
|
$y=max(-$box[7],-$box[5]) + $y; |
|
|
|
$y=max(-$box[7],-$box[5]) + $y; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
imagettftext($this->bg, $size, $angle, $x, $y, $this->color, $this->fontfile , $text ); |
|
|
|
@imagettftext($this->bg, $size, $angle, $x, $y, $this->color, $this->fontfile , $text ); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -143,20 +143,20 @@ class image { |
|
|
|
case 'PNG' : |
|
|
|
case 'PNG' : |
|
|
|
if (!$file) header("Content-type: image/png"); |
|
|
|
if (!$file) header("Content-type: image/png"); |
|
|
|
if ($compress!=-1) |
|
|
|
if ($compress!=-1) |
|
|
|
imagetruecolortopalette ( $this->bg, true, $compress); |
|
|
|
@imagetruecolortopalette ( $this->bg, true, $compress); |
|
|
|
return imagepng($this->bg,$file,$compress); |
|
|
|
return imagepng($this->bg,$file,$compress); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'GIF' : |
|
|
|
case 'GIF' : |
|
|
|
if (!$file) header("Content-type: image/gif"); |
|
|
|
if (!$file) header("Content-type: image/gif"); |
|
|
|
if ($compress!=-1) |
|
|
|
if ($compress!=-1) |
|
|
|
imagetruecolortopalette ( $this->bg, true, $compress); |
|
|
|
@imagetruecolortopalette ( $this->bg, true, $compress); |
|
|
|
return imagegif($this->bg,$file,$compress); |
|
|
|
return imagegif($this->bg,$file,$compress); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: return 0; |
|
|
|
default: return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
imagedestroy($this->bg); |
|
|
|
@imagedestroy($this->bg); |
|
|
|
imagedestroy($this->logo); |
|
|
|
@imagedestroy($this->logo); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|