我目前正在使用一个php gd实现来调整内存不断耗尽的图像 - 相当快。我想这个问题是PHP的功能,如imagecreatefromstring等使用php生成图像缩略图 - 内存不足
是否有一个简单的实施调整图像大小不使用此功能,所以我不会增加我的php.ini内存限制?
我目前正在使用一个php gd实现来调整内存不断耗尽的图像 - 相当快。我想这个问题是PHP的功能,如imagecreatefromstring等使用php生成图像缩略图 - 内存不足
是否有一个简单的实施调整图像大小不使用此功能,所以我不会增加我的php.ini内存限制?
GD不使用那么多的内存,所以你在你的代码中有其他问题。
如果您调整多个图像的大小并且不在新创建的图像上调用imagedestroy
,则会在内存泄漏中运行。
真彩色图像可以用'宽×高×4×内存中的字节。 500万像素图像上的'createimagefromjpg'和20MB内存限制将立即耗尽所有内存。 – 2013-02-26 12:17:38
我知道,但PHP5.3中的默认内存限制是128M,这肯定适合。如果您的主机不支持合适的内存限制,并且不会为您更换它,则应该寻找其他主机。 – Philipp 2013-02-26 12:28:24
这里是你
function make_thumb($src, $dest, $desired_width,$desired_h) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
$desired_height = $desired_h;
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image, $dest);
}
PHP函数也许有在你的代码中的内存泄漏,但谁在乎:)(我们展示代码) – AmazingDreams 2013-02-26 12:05:47