Page 1 of 1

Calling a php file from image?

Posted: Mon Feb 27, 2006 2:35 pm
by kyoru
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi there i'm trying to make a php file which returns an image for use in a website. The php file takes a string from the call and explodes it char's then uses an image for each char and returns the whol thing to the img tag. what excatly do i return so that it works?

example of it in use..

Code: Select all

<img src="images/text_bar/image.php?text=hello">
Code i've written so far...

Code: Select all

<?php {


	$text = $_GET['text'];
	$mode = $_GET['mode'];
	
	$text_l = strlen($text);
	$seperator_count = $text_l - 1;
	$str_position = 0;
	$char_array = str_split($text,1);


	
	//Start loop to print out image
	while ($text_l > $str_position && $mode == '') {
		$current_char = $char_array[$str_position];
		$output = $output . '<img src="' . $current_char . '.gif" border="0">';
		if ($seperator_count > 0) {
			$output = $output . '<img src="seperator.gif" border="0">';
			$seperator_count--;
		}
		$str_position ++;
	}

        //Alternate color printout
	while ($text_l > $str_position && $mode == 'b') {
		$current_char = $char_array[$str_position];
		$output = $output . '<img src="' . $current_char . '_b.gif" border="0">';
		if ($seperator_count > 0) {
			$output = $output . '<img src="seperator.gif" border="0">';
			$seperator_count--;
		}
		$str_position ++;
	}

       //return/output $ouput?

} ?>

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Mon Feb 27, 2006 2:43 pm
by feyd
An actual image, not any text or HTML. Something from say imagegif().

As far as your existing code goes, ignoring the broken image that'll result..
  • Your script doesn't output anything.
  • $str_split isn't defined.
  • $mode and $text may create a notice level error to fire
  • 'gif' is not a defined constant, you'll likely generate a notice/warning from that.

Posted: Mon Feb 27, 2006 3:26 pm
by kyoru
sorry i fixed the thigns around, str_split is a function, but i cahgned around the script because i don't have php 5. i don't really understand what to put inside imagegif(), i'm guessing it is only called once to display a picture so how would i be able to combine my existing pictures? thank you

Posted: Mon Feb 27, 2006 3:32 pm
by feyd
You can use the other image functions to create a new image internally in php, and combine the images together to create the final image. I believe onion2k has an example of collaging like this somewhere here or on his site (phpgd.com)