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;
}
감사합니다 모두
당신의 장소에서 나는 이미지의 수를 생각할 것입니다. 사용자 당 1 개의 이미지를 만드는 것이 무엇이든간에 도움이 될 것입니다. –