私は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;
}
助けてくれてありがとう