使用Imagine调整图像的宽度:调用未定义的方法Imagine \ Gd \ Image :: widen()在第11行的resize.php中

时间:2017-02-19 16:03:22

标签: php php-imagine

尝试调整大小并将图像调整为宽度。这是代码:

<?php
require 'vendor/autoload.php';

use Imagine\Image\Box;
use Imagine\Image\Point;

$imagine = new Imagine\Gd\Imagine();

$image = $imagine->open('img.jpg');

$image->widen(600)->save('resized_img.jpg');

?>

和错误:

PHP Fatal error:  Call to undefined method Imagine\Gd\Image::widen() in resize.php on line 11

我做错了什么?

1 个答案:

答案 0 :(得分:1)

好的,所以这是正确的方法:

<?php
require 'vendor/autoload.php';

use Imagine\Image\Box;
use Imagine\Image\Point;

$imagine = new Imagine\Gd\Imagine();

$image = $imagine->open('img.jpg');

$image->resize($image->getSize()->widen(600))->save('resized_img.jpg');

?>