linein designs

29 Mar, 2011

Text to Image Using PHP and img4me

Posted by: john In: php|tutorial|web

img4me just released an API to their text to image service. This basically allows you to send any peice of text through a URL and have it convert it into an image. Now you wouldn’t want to convert a whole paragraph, but this does work especially nice for email addresses or other information you don’t want to be crawled by the search bots.

Here is a quick function that allows you to easily add this to any project.

Example | Download Files

function img4me($text,$font,$fcolor,$size,$bcolor,$type)
{
	/*
	Parameters
	text*		= text to be converted. (required)
	font		= arial, comic, georgia, impact, lucida, simsun, tahoma, times, trebuchet, verdana (default: courier)
	size		= font size in number 5-35 (default: 12)
	fcolor	= font color in HEX (default: 000000)
	bcolor	= background color in HEX - leave empty for transparent background
	type		= gif, jpg, png (default: png)
	*/

	if(!empty($text))
	{
		$optional = array('font','fcolor','size','bgcolor','type');
		foreach($optional as $key => $value){
			if(!empty($$value)){$get_prams .= '&'.$value.'='.$$value;}
		}

		$url = 'http://api.img4me.com/?text='.urlencode($text).$get_prams;

		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
		curl_setopt($ch, CURLOPT_HEADER,0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		$return_data = curl_exec($ch);
		return '';
	}
	else{return 'error: text was empty';}
}

Similar Posts:

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post


  • Seren: Thanks - google did not fail me in finding this snippet (after 2 hours of 'why isn't this working!' before I choose to look for answers. That select
  • zdenis: type your scp command with nohup at the beginning: >nohup scp... enter your password stop temporarily the command with CTRL+z put on b
  • Criz: php script >> How to get the number of hours and minutes of a two set of time like this sample. 1st set of time : 8:00 to 17:00 2nd set of


Please Support Our Friends

Banner
FreshBooks

About

My name is John Veldboom and have been in design and web programing for just over 8 years now. Started off as a hobby in high school but it has developed into a full time job now. I always tell people that if I wasn't doing this at work each day, I would be at home doing it for free. I love it!

Please visit the contact page to drop me a message.