FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[PHP] Calling dynamic pictures





PatTheGreat42
I recently created for a friend a PHP script that creates a dynamic image by pulling a random Chuck Norris fact from 4q.cc and putting it in a nifty PNG image. Now, to use this, one would normally use a regular image tag, but have the src call the php file. For example, <img src=http://www.patthegreat.com/Steven/chucknorrissig.php>.

However, the forums in which he wants to use this do not allow this. When he tries to make it his sig, it pops up an error message that says that it isn't a valid format. So I was wondering if there was any way to be able to call an image file, but run the script so the image is dynamic? Like, have the image tag be <img src=chucknorrissig.jpg>, but still have it call the chucknorrissig.php script?

And just to show off, here's the sig pic in it's full glory:

http://www.patthegreat.com/Steven/chucknorrissig.php
Marston
PatTheGreat42 wrote:
I recently created for a friend a PHP script that creates a dynamic image by pulling a random Chuck Norris fact from 4q.cc and putting it in a nifty PNG image. Now, to use this, one would normally use a regular image tag, but have the src call the php file. For example, <img src=http://www.patthegreat.com/Steven/chucknorrissig.php>.

However, the forums in which he wants to use this do not allow this. When he tries to make it his sig, it pops up an error message that says that it isn't a valid format. So I was wondering if there was any way to be able to call an image file, but run the script so the image is dynamic? Like, have the image tag be <img src=chucknorrissig.jpg>, but still have it call the chucknorrissig.php script?

And just to show off, here's the sig pic in it's full glory:

http://www.patthegreat.com/Steven/chucknorrissig.php
Dude, Chuck Norris is amazing. His roundhouse kicks can go right through the fabric of time. Essentially, he can kick his own ass - with his own foot! Also, one time, Chuck Norris broke his leg just for the sake of beating everyone else in the Special Olympics.

Chuck Norris is great... Smile
thnn
Yes it is possible.

I recommend putting putting it in a seperate folder and in that folder make the php file have a .png extension and then in an .htaccess file in that folder make php parse .png files as php files.

Then you will be able to do it I think.
MWANGI
Marston wrote
Quote:

Dude, Chuck Norris is amazing. His roundhouse kicks can go right through the fabric of time. Essentially, he can kick his own *** - with his own foot! Also, one time, Chuck Norris broke his leg just for the sake of beating everyone else in the Special Olympics.

Chuck Norris is great..


Wow

Did you know the only reason World war 2 started was because Chuck norris was asleep too.

This guy is a hero and a half! Shocked
n0obie4life
How to do what BlackSkad said

Code:
<FilesMatch "^.*\.png">
   SetHandler application/x-httpd-php
</FilesMatch>
BlackSkad
[OFFTOPIC] Hey n00bie, I didn't say anything in this topic, but thank you for thinking about me Laughing [/OFFTOPIC]

To give this post a little sense:
I can't help you, I only know very little about the .htaccess files Sad
Stubru Freak
You could also use mod rewrite
Bondings
What about placing the following code in a file named .htaccess in that directory:

Code:
RewriteEngine On

RewriteRule ^chucknorrissig.png$ chucknorrissig.php [L]

Then ask your friend to use the chucknorrissig.png picture and it will show the dynamic image.
PatTheGreat42
Well that was freakishly useful. Thanks.
Marston
MWANGI wrote:
Marston wrote
Quote:

Dude, Chuck Norris is amazing. His roundhouse kicks can go right through the fabric of time. Essentially, he can kick his own *** - with his own foot! Also, one time, Chuck Norris broke his leg just for the sake of beating everyone else in the Special Olympics.

Chuck Norris is great..


Wow

Did you know the only reason World war 2 started was because Chuck norris was asleep too.

This guy is a hero and a half! Shocked
Clearly, you've been misinformed. Chuck Norris doesn't sleep. He waits.
Daniel15
An even easier way: You don't need to edit the script, or a .htaccess file!

Just call the script as http://www.patthegreat.com/Steven/chucknorrissig.php/chucknorrissig.png! The script will ignore the /chucknorrissig.png at the end (it gets stored in $_SERVER['PATH_INFO'], and will still run normally.
n0obie4life
BlackSkad wrote:
[OFFTOPIC] Hey n00bie, I didn't say anything in this topic, but thank you for thinking about me Laughing [/OFFTOPIC]

To give this post a little sense:
I can't help you, I only know very little about the .htaccess files Sad


Oops, it's thnn Embarassed
shabda
Erm I probably making a huge fool of myself but still,
Quote:
<img src=http://www.patthegreat.com/Steven/chucknorrissig.php>.

Have you tried <img src="http://www.patthegreat.com/Steven/chucknorrissig.php">. I mean once it is quoted, its just a string.
Daniel15
shabda wrote:
Erm I probably making a huge fool of myself but still,
Quote:
<img src=http://www.patthegreat.com/Steven/chucknorrissig.php>.

Have you tried <img src="http://www.patthegreat.com/Steven/chucknorrissig.php">. I mean once it is quoted, its just a string.


He actually wanted to use it on a forum, as a signature or something. However, the forum doesn't allow him to use PHP files as images. So, he needs to trick the forum into thinking that the PHP file is just a normal image.

@PatTheGreat42: Is this picture on your 404 page the guy from that Microsoft skiing game?:
n0obie4life
lol. That Microsoft skiing game Smile. I love it.

Back on topic.

Code:
[img]http://bondings-world.frihost.net/sig/frih1bday.png[/img]




There, my dynamic sig, I was using it for a while until I had that huge sig thing. Feel free to use it, anyone (as with that code, using my bandwidth..you won't be able to get the PHP part Razz).
Daniel15
Look at my dynamic sig Very Happy

<offtopic>
n0obie4life wrote:
lol. That Microsoft skiing game Smile. I love it.

Well, searching for 'SkiFree' in Google returns 26,500 results. It must be popular Very Happy

For anyone that doesn't know what game we're taking about, see http://ski.ihoc.net/
n0obie4life
BTW, when you are offline, it still shows your system uptime. Doesn't make sense.
ChesterB
hi, can You paste here php code?

big thanks

Greets.
Atomo64
you can use .htaccess or the file.php/image.png trick where with your PHP script you have to retrieve the real path... that's how a lot of CMS's or other systems does the trick
SNES350
MWANGI wrote:
Marston wrote
Quote:

Dude, Chuck Norris is amazing. His roundhouse kicks can go right through the fabric of time. Essentially, he can kick his own *** - with his own foot! Also, one time, Chuck Norris broke his leg just for the sake of beating everyone else in the Special Olympics.

Chuck Norris is great..


Wow

Did you know the only reason World war 2 started was because Chuck norris was asleep too.

This guy is a hero and a half! Shocked

When deciding on what to do to Hiroshima, the president nearly sent in Chuck Norris, but decided to use a nuclear bomb instead, as it was the more "humane" thing to do.

I would also like the PHP code for this if you wouldn't mind giving it out.
PatTheGreat42
Well, that garnered some feedback...

Anyways, here's the code for the actual PHP page. You'll notice that the code requires a suitable PNG background. I also used the .htaccess solution, so I've got a .htaccess file running too.

I also tried to add the occasional helpful comment here and there.

Code:

<?php
//Grab text from RSS feed.
$rss = file("http://www.4q.cc/chuck/rss.php");
$clean = trim(strip_tags($rss[13]));
//Backup facts, in case original fact is too long.
if(strlen($clean) > 200 or $clean == "")
{
   $foo[] = "There once was a man from Nantucket. Chuck Norris paralyzed him from the waist down.";
   $foo[] = "Chuck Norris's communication with The Afterlife is made possible by talking to the black guy on Walker Texas Ranger.";
   $foo[] = "If you see Chuck Norris crying he will grant you a wish, if your wish is dying.";
   $foo[] = "If you make Chuck Norris stroke his beard in confusion, you're finished, because Norris doesn't understand confusion, only pain.";
   $foo[] = "The only reason World War II occured was because Chuck Norris was taking a nap.";
   $foo[] = "What's behind Chuck Norris' beard? Nothing. Just another fist.";
   $clean = $foo[rand(0,5)];
}
//Explode the fact and put each word into it's own part of an array.  Then, I can string the words back together, all the while making sure each line isn't too long.  The lines go into a new array, $fact.
foreach(explode(" ",$clean) as $blargh)
{
   $linelength = $linelength + 1 + strlen($blargh);
   if($linelength < 33)
   {$fact[$arraynum] = $fact[$arraynum]." ".$blargh;}
   else
   {
      $linelength = strlen($blargh) + 1;
      $arraynum++;
      $fact[$arraynum] = $fact[$arraynum]." ".$blargh;
   }
}
//Put it in the picture.  I have no idea how this works.
Header ("Content-type: image/png");
$img_handle = imageCreateFromPNG("chucknorris.png");
$color = ImageColorAllocate($img_handle,255,255,0); //RGB values for font color.
//Font size, x-offset, and y-offset.  Font values 1-5.  1 smallest.
$yoffset = 5;
//Put each item in array $fact into the picture.
foreach($fact as $chuck)
{
   ImageString($img_handle,3,140,$yoffset,$chuck,$color);
   //Increase y offset for new line.
   $yoffset+=15;
}
ImagePng($img_handle);
ImageDestroy($img_handle);
//Original Code:  http://www.icemelon.com/tutorials/9/Dynamic_Images.htm.
//This is some of the prettiest code I've ever done, I'd like to say.
?>


And as a side note, I screwed up the first time. The pic should really be (I hope) here: http://www.patthegreat.com/Steven/chuck/chucknorrissig.php.

Here's the final product:
sharibody
I'm new to all of this, I was wondering, since my site is not up yet, if someone knows a way I can put that fantastic Chuck Norris quote generator into my myspace.

Would I just insert the code or is there something else I need to do?
PatTheGreat42
Dude, if you just want a text-only version of the fact generator, I would suggest just grabbing it from his RSS feed. I think it's 4q.cc/chuck/rss.php. At any rate it's in the code somewhere. That's where I get the facts.

If you want the full dynamic picture version, it's slightly more complicated. Although you could concievably just hotlink from mine, it's more fun I say to set it up on your own server. What you need is that above code in a PHP file. It can be named whatever you want, like chuckisthegreatest.php. Then, you also need a background picture. If you don't want to do much work, you can either use the one I already made, or make something very similar. Make it a PNG file. I named mine chuck.png I think, and you may want to do something similar. But once these two files are in the same directory on a server that supports PHP, it's a simple matter of calling up the PHP file.
sharibody
Thanks for your help! I know this sounds ridiculous, but how would I go about using the feed in my page?

Like I said, I'm really new to this, html boggles my mind a bit.
PopCultureLSU
Does anyone know of a website that gives free tutorials for photoshop. I went to this webpage that had some of the most amzaing graphics and art design and I asked the person how they made them. She told me that there are websites out there that have "tutorials" which give step by step instrucitons on how to create cool and uniqe graphics. She said they have everything from changing pictures, creating backgrounds, and everything in between. If anyone out there knows of a good site like that please send me it!
PatTheGreat42
If you just wanted a plain text version (as I'm pretty sure that's what sharibody was asking for) the simplest method would be to slap the following code wherever you wanted a quote to appear. Of course, the file has to be a php file.

Code:

<?php
$rss = file("http://www.4q.cc/chuck/rss.php");
echo trim(strip_tags($rss[13]));
?>


That should work. I think. What it should do is just grab the rss feed, take of the rss tags and such, and then just display it. It should come out as plain text, so you would have to stick other HTML tags around it to make it pretty.
sharibody
thanks!
secretagenttomtom1388
this sounds like a simple coding error. try to use a code checker to make sure that the script is completely correct. that may or may not fix the problem. let me know how it works out.
Related topics
What Is CSS and PHD?
Flash Portfolio examples
HTML Help
Reading Directories
how did you learn about html, php or other languages???
if() and else(): Help needed!
Creating a member system
Collect funny dog pictures - They don't have to be your own!
What happened to Perl?
Can Php call command line interfaces on the OS
renaming uploaded image file?
Php , Making Dynamic sig
dynamic sig help
[PHP] Some beginner questions
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.