我遇到了几个解决方案,但所有这些都是基于上传图像。我想要的是它应该从一个文件夹中获取图像,将其调整为特定大小,然后将其保存在另一个文件夹中。
问问题
875 次
2 回答
0
试试 PHP 库函数imagecopyresized()
这是一个示例程序,
// File and new size
$filename = 'test.jpg';
$percent = 0.5;
// Content type
header('Content-Type: image/jpeg');
// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($thumb);
这是 imagecopyresized() 的手册。 http://www.php.net/manual/en/function.imagecopyresized.php
于 2014-04-16T06:43:00.797 回答
0
我通常为此使用 GD 库。它工作正常。例如,请查看此网址:http ://runnable.com/UnF-tFdudNt1AABt/how-to-resize-an-image-using-gd-library-for-php
于 2014-04-16T06:43:46.393 回答