有谁能请我提供一个非常容易理解的示例在PHP中使用PEAR调整图像大小 ...
提前致谢...
答案 0 :(得分:1)
答案 1 :(得分:1)
您正在寻找来自PEAR的Image_Transform套餐。相关手册页位于http://pear.php.net/manual/en/package.images.image-transform.scaling.php
考虑到你正在寻找一个梨包以完成这项工作,我认为你已经知道如何安装image_transform。它很简单:
$ sudo pear install image_transform-0.9.3
使用该软件包的一个例子:
<?php
require_once 'Image/Transform.php';
// factory pattern - returns an object
$a = Image_Transform::factory('GD');
// load the image file
$a->load("teste.jpg");
// scale image by percentage - 40% of its original size
$a->scalebyPercentage(40);
// displays the image
$a->display();
?>
和另一个例子:
<?php
require_once 'Image/Transform.php';
$it = Image_Transform::factory("IM");
$it->load("image.png");
$it->resize(2,2);
$it->save("resized.png");
?>
包中提供的其他示例可以通过以下方式找到: $ pear list image_transform
答案 2 :(得分:0)
您可以将imagecopyresampled功能用作:
示例程序(来源:php.net)
<?php
// Image source.
$filename = 'http://valplibrary.files.wordpress.com/2009/01/5b585d_merry-christmas-blue-style.jpg';
$percent = 0.5; // percentage of resize
// send header with correct MIME.
header('Content-type: image/jpeg');
// Get image dimensions
list($width, $height) = getimagesize($filename);
// compute new dimensions.
$new_width = $width * $percent;
$new_height = $height * $percent;
// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Output the resized image.
imagejpeg($image_p, null, 100);
?>