优化Imagick annotateImage [英] Optimizing Imagick annotateImage

查看:105
本文介绍了优化Imagick annotateImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Imagick生成文本图像(想想网站横幅-它们看起来像那样).此功能(特别是annotate行)耗尽了服务器上的资源.

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}'/>"; 
    }

在我的本地环境(win 8.1,xampp,4gb ram)上,这很快.

On my local environment (win 8.1, xampp, 4gb ram), this is fast.

在服务器(godaddy linux,1 GB内存)上,它可以最大限度地利用资源,并且比我的本地环境花费10倍的时间(句子长度最多<4.5> ).

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).

我已经对类中的每个函数进行了计时,发现时间花在了annotateImage()行上.

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)?

推荐答案

在(linux)服务器上,shell_exec的确比php扩展要快得多.给出了更好的窗口时间(甚至不到0.1秒).另一方面,Windows对shell_exec的性能影响很小.

It appears that on the (linux) server, shell_exec is indeed much much faster than the php extension; giving better times that the windows was (even sub 0.1 seconds). On the other hand, windows takes a tiny performance hit with shell_exec.

我认为这是由于Godaddy上的版本-到今天为止,它是6.5.4-7,它是2009年的版本.我在Windows框上运行6.7.7-4.如果他们运行的是该程序的5年旧版本,此后php扩展可能已经有了显着改善.

I'm assuming it's because of the version on godaddy - as of today, it's 6.5.4-7, which is a 2009 version. I was running 6.7.7-4 on my windows box. If they're running a 5 year old version of the program, the php extension may have undergone significant improvement since then.

这篇关于优化Imagick annotateImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆