Calling a php file from image?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kyoru
Forum Commoner
Posts: 26
Joined: Mon Feb 13, 2006 9:35 pm

Calling a php file from image?

Post 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]
Last edited by kyoru on Mon Feb 27, 2006 2:58 pm, edited 2 times in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
kyoru
Forum Commoner
Posts: 26
Joined: Mon Feb 13, 2006 9:35 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
Post Reply