开发者

How to combine image and text on the fly in php

i want to combine text and image on the fly to create a jpg widget. I want to do this for a fundraising website, i will need to update the image once a day so it reflect the updated fundraising progress bar. The reason why i want a jpg (开发者_JAVA技巧image) widget is because it is much more friendly to add to blogs, website etc.


you can do it with 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); 


I'd suggest you look into Imagemagick.

  • http://php.net/manual/en/book.imagick.php
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜