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

前端之家收集整理的这篇文章主要介绍了php缩放图片(根据宽高的等比例缩放)实例介绍前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

使用方法

设定宽高,不等比例缩放
<div class="codetitle"><a style="CURSOR: pointer" data="15122" class="copybut" id="copybut15122" onclick="doCopy('code15122')"> 代码如下:
<div class="codebody" id="code15122">
<?PHP
include('SimpleImage.PHP');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resize(250,400);
$image->save('picture2.jpg');?> 设定宽度,等比例缩放<?PHP
include('SimpleImage.PHP');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(250);
$image->save('picture2.jpg');?> 设定高度,等比例缩放<?PHP
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%<?PHP
include('SimpleImage.PHP');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->scale(50);
$image->save('picture2.jpg');?>缩放后直接输出到屏幕<?PHP
header('Content-Type: image/jpeg');
include('SimpleImage.PHP');
$image = new SimpleImage();
$image->load('picture.jpg');
$image->resizeToWidth(150);
$image->output();?>

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

原文链接:https://www.f2er.com/php/26325.html

猜你在找的PHP相关文章