📄 class.image.php
字号:
@ImageCopyResampled($this->_imgFinal, $this->_imgOrig, 0, 0, 0, 0, $new_x, $new_y, $this->_imgInfoOrig['width'], $this->_imgInfoOrig['height']);
} else {
@ImageCopyResized($this->_imgFinal, $this->_imgOrig, 0, 0, 0, 0, $new_x, $new_y, $this->_imgInfoOrig['width'], $this->_imgInfoOrig['height']);
}
@imagesavealpha($this->_imgFinal, true);
}else
{//for the rest image
if(function_exists('ImageCopyResampled'))
{
@ImageCopyResampled($this->_imgFinal, $this->_imgOrig, 0, 0, 0, 0, $new_x, $new_y, $this->_imgInfoOrig['width'], $this->_imgInfoOrig['height']);
} else {
@ImageCopyResized($this->_imgFinal, $this->_imgOrig, 0, 0, 0, 0, $new_x, $new_y, $this->_imgInfoOrig['width'], $this->_imgInfoOrig['height']);
}
}
$this->_imgInfoFinal['width'] = $new_x;
$this->_imgInfoFinal['height'] = $new_y;
$this->_imgInfoFinal['name'] = basename($this->_imgInfoOrig['name']);
$this->_imgInfoFinal['path'] = $this->_imgInfoOrig['path'];
if($this->_imgFinal)
{
return true;
}else
{
$this->_debug('Unable to resize the image on the fly.');
return false;
}
}
/**
* Get the extension of a file name
*
* @param string $file
* @return string
* @copyright this function originally come from Andy's php
*/
function _getExtension($file)
{
$ext = '';
if (strrpos($file, '.')) {
$ext = strtolower(substr($file, (strrpos($file, '.') ? strrpos($file, '.') + 1 : strlen($file)), strlen($file)));
}
return $ext;
}
/**
* Validate whether image reading/writing routines are valid.
*
* @param string $filename
* @param string $extension
* @param string $function
* @param bool $write
* @return bool
* @access private
* @copyright this function originally come from Andy's php
*/
function _isSupported($filename, $extension, $function, $write = false)
{
$giftype = ($write) ? ' Create Support' : ' Read Support';
$support = strtoupper($extension) . ($extension == 'gif' ? $giftype : ' Support');
if (!isset($this->gdInfo[$support]) || $this->gdInfo[$support] == false) {
$request = ($write) ? 'saving' : 'reading';
$this->_debug("Support for $request the file type '$extension' cannot be found.");
return false;
}
if (!function_exists($function)) {
$request = ($write) ? 'save' : 'read';
$this->_debug("The '$function' function required to $request the '$filename' file cannot be found.");
return false;
}
return true;
}
/**
* flip image horizotally or vertically
*
* @param string $direction
* @return boolean
*/
function flip($direction="horizontal")
{
$this->_createFinalImageHandler($this->_imgInfoOrig['width'], $this->_imgInfoOrig['height']);
if($direction != "vertical")
{
$dst_x = 0;
$dst_y = 0;
$src_x = $this->_imgInfoOrig['width'] -1;
$src_y = 0;
$dst_w = $this->_imgInfoOrig['width'];
$dst_h = $this->_imgInfoOrig['height'];
$src_w = 0 - $this->_imgInfoOrig['width'];
$src_h = $this->_imgInfoOrig['height'];
}else
{
$dst_x = 0;
$dst_y = 0;
$src_x = 0;
$src_y = $this->_imgInfoOrig['height'] - 1;
$dst_w = $this->_imgInfoOrig['width'];
$dst_h = $this->_imgInfoOrig['height'];
$src_w = $this->_imgInfoOrig['width'];
$src_h = 0 - $this->_imgInfoOrig['height'];
}
if(function_exists('ImageCopyResampled')){
ImageCopyResampled($this->_imgFinal, $this->_imgOrig, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
} else {
ImageCopyResized($this->_imgFinal, $this->_imgOrig, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
}
$this->_imgInfoFinal['width'] = $dst_w;
$this->_imgInfoFinal['height'] = $dst_h;
$this->_imgInfoFinal['name'] = basename($this->imageFile);
$this->_imgInfoFinal['path'] = $this->imageFile;
if($this->_imgFinal)
{
return true;
}else
{
$this->_debug('Unable to resize the image on the fly.');
return false;
}
}
/**
* flip vertically
*
* @return boolean
*/
function flipVertical()
{
return $this->flip('vertical');
}
/**
* flip horizontal
*
* @return string
*/
function flipHorizontal()
{
return $this->flip('horizontal');
}
/**
* get the GD version information
*
* @param bool $versionOnly
* @return array
* @access private
* @copyright this function originally come from Andy's php
*/
function getGDInfo($versionOnly = false)
{
$outputs = array();
if (function_exists('gd_info'))
{
$outputs = gd_info();
} else
{
$gd = array(
'GD Version' => '',
'GIF Read Support' => false,
'GIF Create Support' => false,
'JPG Support' => false,
'PNG Support' => false,
'FreeType Support' => false,
'FreeType Linkage' => '',
'T1Lib Support' => false,
'WBMP Support' => false,
'XBM Support' => false
);
ob_start();
phpinfo();
$buffer = ob_get_contents();
ob_end_clean();
foreach (explode("\n", $buffer) as $line) {
$line = array_map('trim', (explode('|', strip_tags(str_replace('</td>', '|', $line)))));
if (isset($gd[$line[0]])) {
if (strtolower($line[1]) == 'enabled') {
$gd[$line[0]] = true;
} else {
$gd[$line[0]] = $line[1];
}
}
}
$outputs = $gd;
}
if (isset($outputs['JIS-mapped Japanese Font Support'])) {
unset($outputs['JIS-mapped Japanese Font Support']);
}
if (function_exists('imagecreatefromgd')) {
$outputs['GD Support'] = true;
}
if (function_exists('imagecreatefromgd2')) {
$outputs['GD2 Support'] = true;
}
if (preg_match('/^(bundled|2)/', $outputs['GD Version'])) {
$outputs['Truecolor Support'] = true;
} else {
$outputs['Truecolor Support'] = false;
}
if ($outputs['GD Version'] != '') {
$match = array();
if (preg_match('/([0-9\.]+)/', $outputs['GD Version'], $match)) {
$foo = explode('.', $match[0]);
$outputs['Version'] = array('major' => isset($foo[0])?$foo[0]:'', 'minor' => isset($foo[1])?$foo[1]:'', 'patch' => isset($foo[2])?$foo:"");
}
}
return ($versionOnly) ? $outputs['Version'] : $outputs;
}
/**
* Destroy the resources used by the images.
*
* @param bool $original
* @return void
* @access public
* @copyright this function originally come from Andy's php
*/
function DestroyImages($original = true)
{
if(!is_null($this->_imgFinal))
{
@imagedestroy($this->_imgFinal);
}
$this->_imgFinal = null;
if ($original && !is_null($this->_imgOrig)) {
@imagedestroy($this->_imgOrig);
$this->_imgOrig = null;
}
}
function getImageInfo($imagePath)
{
return $this->_getImageInfo($imagePath);
}
/**
* get image information, e.g. width, height, type
* @access public
* @return array
*/
function _getImageInfo($imagePath)
{
$outputs = array();
$imageInfo = @GetImageSize($imagePath);
if ($imageInfo && is_array($imageInfo))
{
switch($imageInfo[2]){
case 1:
$type = 'gif';
break;
case 2:
$type = 'jpeg';
break;
case 3:
$type = 'png';
break;
case 4:
$type = 'swf';
break;
case 5:
$type = 'psd';
case 6:
$type = 'bmp';
case 7:
case 8:
$type = 'tiff';
default:
$type = '';
}
$outputs['width'] = $imageInfo[0];
$outputs['height'] = $imageInfo[1];
$outputs['type'] = $type;
$outputs['ext'] = $this->_getExtension($imagePath);
} else {
$this->_debug('Unable locate the image or read images information.');
}
return $outputs;
}
function rotate($angle, $bgColor=0)
{
$angle = intval($angle) -360;
while($angle <0)
{
$angle += 360;
}
if(!function_exists("imagerotate"))
{
function imagerotate($src_img, $angle)
{
$src_x = @imagesx($src_img);
$src_y = @imagesy($src_img);
if ($angle == 180)
{
$dest_x = $src_x;
$dest_y = $src_y;
}
elseif ($src_x <= $src_y)
{
$dest_x = $src_y;
$dest_y = $src_x;
}
elseif ($src_x >= $src_y)
{
$dest_x = $src_y;
$dest_y = $src_x;
}
$this->_createFinalImageHandler($dest_x,$dest_y);
$rotate = $this->_imgFinal;
@imagealphablending($rotate, false);
switch ($angle)
{
case 270:
for ($y = 0; $y < ($src_y); $y++)
{
for ($x = 0; $x < ($src_x); $x++)
{
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $dest_x - $y - 1, $x, $color);
}
}
break;
case 90:
for ($y = 0; $y < ($src_y); $y++)
{
for ($x = 0; $x < ($src_x); $x++)
{
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $y, $dest_y - $x - 1, $color);
}
}
break;
case 180:
for ($y = 0; $y < ($src_y); $y++)
{
for ($x = 0; $x < ($src_x); $x++)
{
$color = imagecolorat($src_img, $x, $y);
imagesetpixel($rotate, $dest_x - $x - 1, $dest_y - $y - 1, $color);
}
}
break;
default: $rotate = $src_img;
};
return $rotate;
}
}
if($this->_imgFinal = @imagerotate($this->_imgOrig, $angle, $bgColor))
{
return true;
}else
{
return false;
}
}
/**
* get the original image info
*
* @return array
*/
function getOriginalImageInfo()
{
return $this->_imgInfoOrig;
}
/**
* return the final image info
*
* @return array
*/
function getFinalImageInfo()
{
if($this->_imgInfoFinal['width'] == '')
{
if(is_null($this->_imgFinal))
{
$this->_imgInfoFinal = $this->_imgInfoOrig;
}else
{
$this->_imgInfoFinal['width'] = @imagesx($this->_imgFinal);
$this->_imgInfoFinal['height'] = @imagesy($this->_imgFinal);
}
}
return $this->_imgInfoFinal;
}
/**
* create final image handler
*
* @access private
* @param $dst_w width
* @param $dst_h height
* @return boolean
* @copyright original from noname at nivelzero dot ro
*/
function _createFinalImageHandler($dst_w, $dst_h)
{
if(function_exists('ImageCreateTrueColor'))
{
$this->_imgFinal = @ImageCreateTrueColor($dst_w,$dst_h);
} else {
$this->_imgFinal = @ImageCreate($dst_w,$dst_h);
}
if (!is_null($this->transparentColorRed) && !is_null($this->transparentColorGreen) && !is_null($this->transparentColorBlue)) {
$transparent = @imagecolorallocate($targetImageIdentifier, $this->transparentColorRed, $this->transparentColorGreen, $this->transparentColorBlue);
@imagefilledrectangle($this->_imgFinal, 0, 0, $dst_w, $dst_h, $transparent);
@imagecolortransparent($this->_imgFinal, $transparent);
}
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -