最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 利用GD创建缩略图
时间:2010-02-01 编辑:简简单单 来源:一聚教程网
error_reporting(E_ALL);
$;
/*** the image file to thumbnail ***/
$image = 'spork.jpg';
if(!file_exists($image))
{
echo 'No file found';
}
else
{
/*** image info ***/
list($width_orig, $height_orig, $image_type) = getimagesize($image);
/*** check for a supported image type ***/
if($image_type !== 2)
{
echo 'invalid image';
}
else
{
/*** thumb image name ***/
$thumb = 'thumb.jpg';
/*** maintain aspect ratio ***/
$height = (int) (($width / $width_orig) * $height_orig);
/*** resample the image ***/
$image_p = imagecreatetruecolor($width, $height);
$image = imageCreateFromJpeg($image);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
/*** write the file to disc ***/
if(!is_writeable(dirname($thumb)))
{
echo 'unable to write image in ' . dirname($thumb);
}
else
{
imageJpeg($image_p, $thumb, 100);
}
}
}
?>
-
上一个: php checkdate日期验证
-
下一个: php 给GIF 缩略图实例代码
相关文章
- php创建高清缩略图详细使用方法 11-23
- PHP导出数据超时的优化建议解读 10-31
- PHP之mysql位运算解析 10-31
- Laravel实现登录跳转功能解析 10-31
- php双向队列解读 10-31
- Laravel异常上下文解决教程 10-24