当前位置:Gxlcms > PHP教程 > php缩放图片(根据宽高的等比例缩放)实例介绍_PHP教程

php缩放图片(根据宽高的等比例缩放)实例介绍_PHP教程

时间:2021-07-01 10:21:17 帮助过:27人阅读

推荐一个简单实用的缩放图片工具 SimpleImage,参考http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

使用方法:

设定宽高,不等比例缩放
代码如下:

include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resize(250,400);
$image->save('picture2.jpg');?>

设定宽度,等比例缩放

include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(250);
$image->save('picture2.jpg');?>

设定高度,等比例缩放

include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToHeight(500);
$image->save('picture2.jpg');
$image->resizeToHeight(200);
$image->save('picture3.jpg');?>

按比例,缩放至50%

include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->scale(50);
$image->save('picture2.jpg');?>

缩放后直接
输出到屏幕

header('Content-Type: image/jpeg');
include('SimpleImage.php');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(150);
$image->output();?>


SimpleImage.php 源码请轻点文章开头链接,到那下载

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/327591.htmlTechArticle推荐一个简单实用的缩放图片工具 SimpleImage,参考http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/ 使用方法: 设定宽高,不等比例缩放...

人气教程排行