I have a simple script that dynamically takes images from a Cloudfront bucket, resizes them, converts them to a valid data URL and displays them on a page.
我有一个简单的脚本,可以动态地从Cloudfront存储桶中获取图像,调整它们的大小,将它们转换为有效的数据URL并在页面上显示它们。
The problem I am having is load time. The below script takes ~12 seconds to load (about ~ 1 - 1.5 seconds per image)
我遇到的问题是加载时间。下面的脚本加载大约需要12秒(每张图像大约需要1到1.5秒)
Is there any suggested ways to speed this up?
有没有建议的方法来加快这个速度?
$mango = Mango::factory('illustration')->load(9)->as_array();
$images = array();
foreach($mango as $data)
{
$image = Image::factory('cloudfrontbucket' . urlencode($data->illustration), 'imagick');
$image = $this->data_uri($image->resize(200), 'image/png');
$images[$data->id]['image'] = $image;
$images[$data->id]['id'] = $data->id;
}
Thanks in advance.
提前致谢。
1 个解决方案
#1
0
You cannot, basically, speed up the image resizing process itself. The module uses GD or ImageMagick, which are core php extensions and run as fast as they can. The only overhead is the regular Kohana stuff. If you want to speed up the process you should look into a way to speed up Kohana itself, for instance Gearman as @ThePixelDeveloper noted.
基本上,您不能加快图像大小调整过程本身的速度。该模块使用GD或ImageMagick,它们是核心的php扩展,并尽可能快地运行。唯一的开销是常规的Kohana东西。如果你想加快这个过程,你应该研究一种加速Kohana本身的方法,例如@ThePixelDeveloper指出的Gearman。
If you cannot reduce the load enough you could workaround this problem to limit the pictures you process in one time. The next time the script runs (through a cronjob or if you do not have access to the crontab a poormans cron), just check which pictures are not processed yet and take a few.
如果无法减轻负载,则可以解决此问题,以限制您一次处理的图片。下一次脚本运行时(通过cronjob或者如果你没有访问crontab的穷人cron),只需检查哪些图片尚未处理并取一些。
#1
0
You cannot, basically, speed up the image resizing process itself. The module uses GD or ImageMagick, which are core php extensions and run as fast as they can. The only overhead is the regular Kohana stuff. If you want to speed up the process you should look into a way to speed up Kohana itself, for instance Gearman as @ThePixelDeveloper noted.
基本上,您不能加快图像大小调整过程本身的速度。该模块使用GD或ImageMagick,它们是核心的php扩展,并尽可能快地运行。唯一的开销是常规的Kohana东西。如果你想加快这个过程,你应该研究一种加速Kohana本身的方法,例如@ThePixelDeveloper指出的Gearman。
If you cannot reduce the load enough you could workaround this problem to limit the pictures you process in one time. The next time the script runs (through a cronjob or if you do not have access to the crontab a poormans cron), just check which pictures are not processed yet and take a few.
如果无法减轻负载,则可以解决此问题,以限制您一次处理的图片。下一次脚本运行时(通过cronjob或者如果你没有访问crontab的穷人cron),只需检查哪些图片尚未处理并取一些。