如何在PHP中动态组合图像和文本

时间:2010-07-10 18:09:38

标签: php text widget

我希望动态组合文本和图像来创建jpg小部件。我想为筹款网站这样做,我需要每天更新一次图像,以便反映更新的筹款进度条。我想要一个jpg(图像)小部件的原因是因为它更友好地添加到博客,网站等。

2 个答案:

答案 0 :(得分:3)

您可以使用gd

执行此操作
//open up the image you want to put text over 

$im = imagecreatefromjpeg($imagePath);  

//The numbers are the RGB values of the color you want to use 
$black = ImageColorAllocate($im, 255, 255, 255); 

//The canvas's (0,0) position is the upper left corner 
//So this is how far down and to the right the text should start 
$start_x = 10; 
$start_y = 20; 

//This writes your text on the image in 12 point using verdana.ttf 
//For the type of effects you quoted, you'll want to use a truetype font 
//And not one of GD's built in fonts. Just upload the ttf file from your 
//c: windows fonts directory to your web server to use it. 
Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', 'text to write'); 

//Creates the jpeg image and sends it to the browser 
//100 is the jpeg quality percentage 
Imagejpeg($im, '', 100); 

ImageDestroy($im); 

答案 1 :(得分:2)

我建议你看一下Imagemagick。