php改变图像大小
Today I saw a post at digg.com on image resizing with PHP and there was quite a discussion. Let me share the laziest way (that I know of) how to do it - PEAR::Image_Transform is all it takes. Here goes:
今天,我在digg.com上看到了有关使用PHP调整图像大小的文章,并且进行了很多讨论。 让我分享最懒惰的方式(我知道)该怎么做-它只需要PEAR :: Image_Transform。 开始:
<?php
require_once 'Image/Transform.php';
$i =& Image_Transform::factory('');
$i->load('test.jpg');
$i->fit(100,100);
$i->save('resized.png', 'png');
?>
In addition, the Image_Transform library offers diffferent ways (to skin the old cat) to resize an image - by given pixel value, only on the X axis, on Y, scalling in percentage and so on. And, of course, the library can do much more than resizing, as you can see in the API docs.
另外, Image_Transform库提供了不同的方法(给老猫换皮)来调整图像大小-仅在X轴,Y轴上按给定像素值,按比例缩放等。 而且,当然,如您在API docs中所见,该库除了调整大小外还可以做更多的事情。
It supports all kinds of image manipulation extensions - GD, GD1, ImageMagick, NetPBM, Imlib... If you want to use a specific one, you set as a parameter to the factory()
method. In the example above I passed an empty string, so it will try to figure out what's available in my PHP setup and use it, trying Imagick2 first, then GD, then Imlib.
它支持各种图像处理扩展-GD,GD1,ImageMagick,NetPBM,Imlib ...如果要使用特定的扩展,则可以将其设置为factory()
方法的参数。 在上面的示例中,我传递了一个空字符串,因此它将尝试找出PHP设置中可用的内容并使用它,首先尝试Imagick2,然后尝试GD,然后再尝试Imlib。
You have setOption()
and setOptions()
methods if you want to play around with the image quality and those sort of things.
如果您想setOptions()
图像质量和诸如此类的东西,则可以使用setOption()
和setOptions()
方法。
Tell your friends about this post on Facebook and Twitter
在Facebook和Twitter上告诉您的朋友有关此帖子的信息
php改变图像大小