推薦一個簡單實用的縮放圖片工具 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 源碼請輕點文章開頭鏈接,到那下載