0

私はGD2と画像関数を使用して文字列を取り込み、それをさまざまなサイズのさまざまなフォントを使用して画像に変換しています。私が使用する機能は以下のとおりです。

現在、かなり速いですが、十分な速さではありません。この関数はユーザーごとに約20回呼び出され、生成される画像は常に新しいもの(異なる)であるため、キャッシュは役に立ちません。

この機能をより速くする方法についていくつかのアイデアを得たいと思っていました。たぶん、実行中のスクリプトにより多くのRAMを供給しますか?このPHP関数に固有のものは他にありますか?

この関数のパフォーマンスを微調整するために他にできることはありますか?

  function generate_image($save_path, $text, $font_path, $font_size){

    $font = $font_path;

    /*
    * I have simplifed the line below, its actually a function that works out the size of the box
    * that is need for each image as the image size is different based on font type, font size etc
    */
    $measure = array('width' => 300, 'height'=> 120);

    if($measure['width'] > 900){ $measure['width'] = 900; }

    $im = imagecreatetruecolor($measure['width'], $measure['height']); 
    $white = imagecolorallocate($im, 255, 255, 255);
    $black = imagecolorallocate($im, 0, 0, 0);

    imagefilledrectangle($im, 0, 0, $measure['width'], $measure['height'], $white);     

    imagettftext($im, $font_size, 0, $measure['left'], $measure['top'], $black, $font, '    '.$text);

    if(imagepng($im, $save_path)){

        $status = true;

    }else{

        $status = false;

    }

    imagedestroy($im);

    return $status;

}

助けてくれてありがとう

4

2 に答える 2

1

いいと思います

于 2010-05-19T10:52:36.950 に答える
-1

毎回新しい画像を作成する代わりに、空白のPNGファイル(最大幅が900pxであることはすでにわかっていますが、使用できる最大高さは固定されていますか?)を作成し、それを開いてテキストを追加してからトリミングすることができます。それ(imagecopy()を参照)。

よくわかりませんが、現在行っているよりも速いかもしれません。

于 2010-05-19T11:36:41.877 に答える