I'm generating images of text using Imagick (think site banners - they look like that). I'm running out of resources on the server in this function, specifically the annotate
line.
public function output_image($type = 'png') {
$this->set_draw($this->font_size);
$this->image->newImage($this->width*1.3,
$this->line_height*2.5,
'transparent'); // make an image that's too big
$this->image->annotateImage($this->draw,
$this->font_size*0.5, //x offset for cursive fonts
$this->font_size, // vertical offset for tall ascenders
0, //angle
$this->text); // add the text
$this->image->trimImage(0); // trim it.
$this->image->setImageFormat($type);
$this->base64 = base64_encode($this->image);
echo "<img src='data:image/$type;base64,{$this->base64}'/>";
}
On my local environment (win 8.1, xampp, 4gb ram), this is fast.
On the server (godaddy linux, 1 GB ram), it maxes out the resources and it takes 10x longer than it does on my local environment (up to 4.5 seconds for sentence-length).
I've timed every function in the class and found that the time is being spent in the line annotateImage()
.
I can throw hardware at the problem, but I was wondering if there's a better way to write text on an image? Or a way to speed up how annotate works (lower the image quality, etc)?