func_thumb.php

来自「采用模块化设计,自由组合文章,软件,论坛等模块,安装方便快捷 模板支持Dre」· PHP 代码 · 共 47 行

PHP
47
字号
<?php

if (!defined('ROOT'))
    exit('Access Denied');
function thumb($filename,$sourfile) {
	$imagetype = strtolower(str_replace('.', '', strrchr($sourfile, '.')));
	if (!$data = @getimagesize($sourfile))
	return false;
	if ($imagetype == 'gif') {
		$img = imagecreatefromgif($sourfile);
	} else
	if ($imagetype == 'jpg' || $imagetype == 'jpeg') {
		$img = imagecreatefromjpeg($sourfile);
	} else
	if ($imagetype == 'png') {
		$img = imagecreatefrompng($sourfile);
	} else {
		return false;
	}

	if (empty($img)) return false;

	$width = 200;
	$height = 200;

	$width = ($width > $data[0]) ? $data[0] : $width;
	$height = ($height > $data[1]) ? $data[1] : $height;
	$srcW = $data[0];
	$srcH = $data[1];
	if ($srcW * $width > $srcH * $height)
	$height = round($srcH * $width / $srcW);
	else
	$width = round($srcW * $height / $srcH);

	if (function_exists('imagecreatetruecolor')) {
		$new = imagecreatetruecolor($width, $height);
		ImageCopyResampled($new, $img, 0, 0, 0, 0, $width, $height, $data[0], $data[1]);
	} else {
		$new = imagecreate($width, $height);
		ImageCopyResized($new, $img, 0, 0, 0, 0, $width, $height, $data[0], $data[1]);
	}
	ImageJPEG($new, $filename);
	ImageDestroy($new);
	ImageDestroy($img);
	return true;
}
?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?