ACC SHELL
<?php
class image
{
private $srcWidth;
private $srcHeight;
private $srcType;
private $srcImage=NULL;
private $raito;
private $srcRaito;
private $bgColor='ffffff';
private $bgImage=NULL;
function __construct()
{
if( !defined('IMAGE_TRIM') ) define('IMAGE_TRIM', 1);
if( !defined('IMAGE_RAITO') ) define('IMAGE_RAITO', 2);
if( !defined('IMAGE_FULL') ) define('IMAGE_FULL', 3);
}
function setBgColor($color)
{
$this->bgColor=$color;
}
function setBgImage($url)
{
@$s=getimagesize($url);
if( $s[2]!=IMAGETYPE_JPEG )
die('Background image is not JPEG!');
$this->bgImage=$url;
}
function load($srcUrl)
{
list($this->srcWidth, $this->srcHeight, $this->srcType) = getImageSize($srcUrl);
switch($this->srcType)
{
case IMAGETYPE_JPEG: $this->srcImage=imageCreateFromJpeg($srcUrl); break;
case IMAGETYPE_PNG: $this->srcImage=imageCreateFromPng($srcUrl); break;
case IMAGETYPE_GIF: $this->srcImage=imageCreateFromGif($srcUrl); break;
}
if( is_null($this->srcImage) )
die('Can\'t load image');
}
function resize($width, $height, $dest, $mode=IMAGE_TRIM, $saveAs=IMAGETYPE_JPEG)
{
$image=NULL;
$raito=$width/$height;
$srcRaito=$this->srcWidth/$this->srcHeight;
switch($mode)
{
case IMAGE_TRIM:
if( $srcRaito>$raito )
{
$newWidth=$srcRaito*$height;
$newHeight=$height;
$x=-($newWidth-$width)/2;
$y=0;
}
else
{
$newWidth=$width;
$newHeight=$width/$srcRaito;
$x=0;
$y=-($newHeight-$height)/2;
}
$image=imageCreateTrueColor($width, $height);
imageCopyResampled($image, $this->srcImage, $x, $y, 0, 0, $newWidth, $newHeight, $this->srcWidth, $this->srcHeight);
break;
case IMAGE_RAITO:
if( ($width>$this->srcWidth ) && ($height>$this->srcHeight) )
{
$newWidth=$this->srcWidth;
$newHeight=$this->srcHeight;
}
elseif( $srcRaito>$raito )
{
$newWidth=$width;
$newHeight=$width/$srcRaito;
}
else
{
$newWidth=$height*$srcRaito;
$newHeight=$height;
}
$image=imageCreateTrueColor($newWidth, $newHeight);
imageCopyResampled($image, $this->srcImage, 0, 0, 0, 0, $newWidth, $newHeight, $this->srcWidth, $this->srcHeight);
break;
case IMAGE_FULL:
if( $srcRaito<$raito )
{
$newWidth=$srcRaito*$height;
$newHeight=$height;
$x=-($newWidth-$width)/2;
$y=0;
}
else
{
$newWidth=$width;
$newHeight=$width/$srcRaito;
$x=0;
$y=-($newHeight-$height)/2;
}
if( !is_null($this->bgImage) )
$image=imageCreateFromJpeg( $this->bgImage );
else
{
$r=hexDec( subStr($this->bgColor, 0, 2) );
$g=hexDec( subStr($this->bgColor, 2, 2) );
$b=hexDec( subStr($this->bgColor, 4, 2) );
$image=imageCreateTrueColor($width, $height);
$color=imageColorAllocate($image, $r, $g, $b);
imageFill($image, 0, 0, $color);
}
imageCopyResampled($image, $this->srcImage, $x, $y, 0, 0, $newWidth, $newHeight, $this->srcWidth, $this->srcHeight);
break;
}
if( is_null($this->srcImage) )
die('Can\'t resize image');
switch($saveAs)
{
case IMAGETYPE_JPEG: if( imageJpeg($image, "$dest.jpg") ) return "$dest.jpg"; break;
case IMAGETYPE_PNG: if( imagePng($image, "$dest.png") ) return "$dest.png"; break;
case IMAGETYPE_GIF: if( imageGif($image, "$dest.gif") ) return "$dest.gif"; break;
}
die('Can\'t save image');
}
}
?>
ACC SHELL 2018