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.
The problem I am having is load time. The below script takes ~12 seconds to load (about ~ 1 – 1.5 seconds per image)
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.
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.
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.