【发布时间】:2014-05-30 21:07:12
【问题描述】:
我遇到了几个解决方案,但所有这些都是基于上传图片。我想要的是它应该从一个文件夹中获取图像,将其调整为特定大小,然后将其保存在另一个文件夹中。
【问题讨论】:
-
不是要求我们提供代码,而是先谷歌它,然后尝试它,如果它不起作用,然后问我们一个建设性的问题。
标签: php image-processing image-resizing resize-image
我遇到了几个解决方案,但所有这些都是基于上传图片。我想要的是它应该从一个文件夹中获取图像,将其调整为特定大小,然后将其保存在另一个文件夹中。
【问题讨论】:
标签: php image-processing image-resizing resize-image
我通常为此使用 GD 库。它工作正常。例如,请看这个网址:http://runnable.com/UnF-tFdudNt1AABt/how-to-resize-an-image-using-gd-library-for-php
【讨论】:
试试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
【讨论】: