php缩放图片(根据宽高的等比例缩放)实例介绍
程序员文章站
2022-04-08 15:50:55
推荐一个简单实用的缩放图片工具 simpleimage,参考http://www.white-hat-web-design.co.uk/blog/resizing-imag...
推荐一个简单实用的缩放图片工具 simpleimage,参考http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/
使用方法:
设定宽高,不等比例缩放
<?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 源码请轻点文章开头链接,到那下载
使用方法:
设定宽高,不等比例缩放
复制代码 代码如下:
<?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 源码请轻点文章开头链接,到那下载
上一篇:
<
推荐阅读