我在使用PHP的WideImage库- http://wideimage.sourceforge.net/时遇到了严重的性能问题。使用WideImage::load()加载2.2MB的.png文件时,内存使用量峰值为93MB!此外,加载、调整大小和写入750KB .jpg的文件系统几乎需要30秒。我在两个不同的服务器上运行了这些基准测试,结果相似。
还有没有人遇到过这些问题?仅仅是因为WideImage是一个资源大户吗?如果我用直接的GD而不是WideImage重写我的图像处理,我能期望更好的性能吗?我知道PHP不是处理图像的最佳语言,但我不希望用C编写代码,然后在PHP中调用它:(
感谢你抽出时间-安迪
发布于 2012-06-07 02:09:52
运行了一些简化的基准测试,我想我已经弄明白了。WideImage的resize方法不是持久的。示例:
$image = WideImage::load('path/to/file.png');
$image->getWidth(); <-- lets say that returns a width of 2000 pixels
$image->resize(100, 100);
$image->getWidth(); <-- that will still return a width of 2000 pixels, the original $image has not been alteredWideImage操作返回一个新的图像实例,并保持前一个图像不变,因此要获得操作结果,您需要将其赋给一个变量:
$image = WideImage::load('path/to/file.png');
$image->getWidth(); // 2000 px
$resizedImage = $image->resize(100, 100);
$image->getWidth(); // still 2000 px
$resizedImage->getWidth(); // 100 px所以我移动的图像比我想象的要大得多,因为我的调整大小方法实际上并没有改变我的源图像。
发布于 2012-09-17 16:24:59
也许你应该使用自定义解决方案。WideImage可能存在一些性能问题。这是一个有趣的调查WideImage performance and memory issues。
https://stackoverflow.com/questions/10917821
复制相似问题