Jump to content

Any Of You Into Png


section31

Recommended Posts

Okay, but how do they do it? I do they post the info into the picture file like that and have it show up on the server? I see nothing but a picture file and that's it, nothing else. So obviously its a server side script that make the whole image but I don't see how it's doing.

 

Any suggestions on this?

 

Mav

Link to comment
Share on other sites

The hard part on this is to work with the image.

 

I don't know which graphics package they're using for it but I think you can do it with GD and pretty much any other graphics package for PHP/PERL/etc

 

The idea is to make a script that gets the browser's information and then, using GD (or whatever graphics package you choose), you open the basic image file and add the client's browser data.

 

You will want to save this script as a .jpg, .png or .gif file to add the extra l33t touch - you could leave it as a plain .php, .pl or .cgi file but it wouldn't be as funny :D

 

The only thing left for you to do is add a .htaccess file to the directory where your "image" is, containing something like this:

 

><Files secret_info.jpg>

  ForceType application/x-httpd-php

</Files>

 

This will tell Apache to treat the file "secret_info.jpg" as a PHP script, meaning it will be parsed through PHP and it's output sent to the browser.

 

The only thing I can't really tell you how to do is the image related operations, since I only worked with that kind of thing once (using PHP and GD) but I really don't know how to do it anymore.

But it shouldn't be difficult for you to find some information about this on the web, using google ;)

Link to comment
Share on other sites

Okay, um, what is GD? Graphics ??????? what? Is it something like the imagemagic stuff where it takes the graphic and adds the file text into as a image file everytime the script is run?

 

Mav

 

Also, what would I look under when I go on my web looking spree. What key words should I look for to single out a script like this? Kick Me

Link to comment
Share on other sites

Yes, GD is something like ImageMagik and yes, that's basically what the script has to do.

 

As t what you should look for, learn the basic rule: talk to google. ;)

I mean it!

Just use the most basic words you can think of.

For example, in this case you could try something like "adding text to images with PHP and GD" ;)

Or replace "GD" with "ImageMagik", if you prefer :o

Link to comment
Share on other sites

Thanks, I just started working on the new Invision setup. It's a little daunting now that they switched things all around. I'm working on the changing the colors and the icons over now, hopefully in a week or two I'll have it all color matched with my main site.

 

Okay, here is another question on this issue. I'm assuming TCH supports the GD and freestyle font things that are required to run the imagettftext portion. I'm just trying to figure out where in the code that the image I have would be inserted so that the text can write over top of it. I see where the script makes the dimensions and color selections, but where would I put my html/mav/somepicture.png link in to use that picture as the source to write the text over top of it?

 

<?php

Header ("Content-type: image/gif");

$im = imagecreate (400, 30);

$black = ImageColorAllocate ($im, 0, 0, 0);

$white = ImageColorAllocate ($im, 255, 255, 255);

ImageTTFText ($im, 20, 0, 10, 20, $white, "/path/arial.ttf",

              "Testing... Omega: Ω");

ImageGif ($im);

ImageDestroy ($im);

?>

 

So if anyone has any solutions I'm open for them.

 

Mav Head Bash

Link to comment
Share on other sites

I have found the PHP portion that enables this feature, now I just need to figure out how the hell to use it.

 

imagettftext

 

 

So if anyone knows how to get this feature working, help us out please. I'll be fiddling with it until I can figure it out.

 

 

Mav

Link to comment
Share on other sites

I'm not quite sure what your asking there twowheels.

 

hmmm, it doesn't recognize Opera!

 

 

You are You are running on...

 

Could you clarify that? :blink:

 

Mav

Link to comment
Share on other sites

By George I've done it! I've figured it out, thank you Borfast for the extra tip on the .htaccess file info for spoofing the php with an image extension. I did not know that was possible, but as always, a new day = new discoveries!!!

 

Now here is my only question I have left on this little scenerio. I've learned to figure some basic PHP in 5 hours but I'm no expert, so I want to know how in the text area of the script I'm suppose to call the Apache items needed to show that as the text on the image.

 

How these and other functions fit into the code area below where the text would normally go?

 

$http_referer

$http_user_agent

$request_uri

$remote_addr ect...ect....

 

ImageTTFText ($image, $font_size, 0, 11, 36, $black, "/images/arial.ttf","????????>>>> How do the tags fit in here to show as text on the image <<<<<<<<<????????");

 

 

I'm assuming that's where they would go, some how just as the text, there is a way to make it print the info from those tags as text also. Which is how the vipersig from above is working. How do you insert php into that area I've marked in red?

 

You can see a working example I just thru up on my server here. Test Image Warning, slightly nekkid Milla Jovanvich image from 5th Element.

 

Once I understand a little more I'll attempt something like random quotes or something on an image. But one step at a time, first the calling of the server functions onto the image.

 

 

TIA,

Mav woooot

Link to comment
Share on other sites

I've figured out the format on the insertion now.

 

ImageTTFText ($image, $font_size, 0, 11, 36, $black, "/images/arial.ttf"," . $http_user_agent . ");

 

Now how do I shorten the whole code of what it shows ".Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; NET CLR 1.1.4322). to just say IE 6 or something like that? Or is there an easier way? Any Suggestions?

 

Mav

Link to comment
Share on other sites

Hey, glad you made it :rolleyes:

 

Sorry for not answering your previous posts but I went to bed after I posted the first time :D

 

As for the text stuff, you want to take a look at PHP's text functions, especially stristr.

 

If you want to check for IE, for example, you'd put all that browser agent string into a variable and then check for an occurrence of "MSIE".

Here's a simple example:

 

>$browserinfo = $_SERVER['HTTP_USER_AGENT'];
if ( !strstr($browserinfo, "MSIE") ) // The string "MSIE" was found
  // output your stuff for IE
else if ( !strstr($browserinfo, "Opera") ) // The string "Opera" was found
  // output for Opera
else if.........

 

This is just a very simple example, it will not work for everything but it should get you started. :)

Link to comment
Share on other sites

Ah, I recognize the format, I'm having JavaScript flash backs. Amazing how all coding is fundamentally almost the same structure. I'll have to fiddle with it and see what else I can come up with.

 

I will still need to find a random script cycler for text, so I can insert random thoughts of insanity into a picture also. Oh yeah, the vision of it all "Man who stands on toilet, is high on Pot". eheh

 

Off to the scripting dungeon I go! Kick Me

 

Mav

Link to comment
Share on other sites

Oh, I wasn't sure what you talking about? :D

Link to comment
Share on other sites

Thanks, I just started working on the new Invision setup. It's a little daunting now that they switched things all around. I'm working on the changing the colors and the icons over now, hopefully in a week or two I'll have it all color matched with my main site.

 

Okay, here is another question on this issue. I'm assuming TCH supports the GD and freestyle font things that are required to run the imagettftext portion. I'm just trying to figure out where in the code that the image I have would be inserted so that the text can write over top of it. I see where the script makes the dimensions and color selections, but where would I put my html/mav/somepicture.png link in to use that picture as the source to write the text over top of it?

 

<?php

Header ("Content-type: image/gif");

$im = imagecreate (400, 30);

$black = ImageColorAllocate ($im, 0, 0, 0);

$white = ImageColorAllocate ($im, 255, 255, 255);

ImageTTFText ($im, 20, 0, 10, 20, $white, "/path/arial.ttf",

              "Testing... Omega: Ω");

ImageGif ($im);

ImageDestroy ($im);

?>

 

So if anyone has any solutions I'm open for them.

 

Mav Head Bash

 

 

but where would I put my html/mav/somepicture.png link in to use that picture as the source to write the text over top of it?

 

So how did u put your picture on there after all. IT works fine for me when I use the imagecreate, but how I do I use a jpeg or another file instead. I need a so called "resource image to use the imagettftext() function and also the imagejpeg() function. So what do I use to make a jpeg resource image using a pre existing image file.

Link to comment
Share on other sites

If you can wait a little bit I'll be typing up a little tutorial. The script is actual quite a bit different than the what I listed before. And it grows as we speak now to incorporate all the script inserts. I'll be working on it this week and I'll make sure all the items work fully with out a problem before I send out the finished script.

 

Be patient I'll have it completely functional real soon. Along with how to make everything work on TCH's servers and what functions can be used. Then all you'll have to do is cut and paste, then add your own touches..

 

Mav Kick Me

Link to comment
Share on other sites

I'll post part of the code here that I have so far. I'm working on the random quote part right now. Well, when I get some time this week to work on it that is.

 

<?php

  $http_user_agent = $_SERVER["HTTP_USER_AGENT"];  //my script for showing what browser a person is using

  $remote_addr = $_SERVER["REMOTE_ADDR"];  //this one will display the ip address of the person viewing the image

 

  $image = imagecreatefrompng ("/home/yourTCHloginname/public_html/folderontheserver/button1.png");  /* I find that using the entire address works best when I run php scripts.  This will point to where ever the image you'll be using is at.  I use the imagecreatefrompng as my picture is a png file*/

  $font_size = 12;  //Font size for the text

  $color = imagecolorallocate ($image, 255,255,255);

  $black = imagecolorallocate ($image, 0,0,0);

  ImageTTFText ($image, $font_size, 0, 11, 36, $black, "/home/yourTCHloginname/public_html/folderontheserver/arial.ttf"," . $http_user_agent . ");  /*This is where your font ttf file is at along with where you'll put your text message.  I have the user_agent thing running in this example.*/

  ImageTTFText ($image, $font_size, 0, 10, 35, $color, "/home/yourTCHloginname/public_html/folderontheserver/arial.ttf"," . $http_user_agent . ");

  ImageTTFText ($image, $font_size, 0, 11, 60, $black, "/home/yourTCHloginname/public_html/folderontheserver/arial.ttf"," . $remote_addr . ");

  ImageTTFText ($image, $font_size, 0, 10, 59, $color, "/home/yourTCHloginname/public_html/folderontheserver/arial.ttf"," . $remote_addr . ");

 

  header("Content-type: image/png");  /*Also png since my image is a png or it could be a jpg if that is your format also.*/

  imagepng($image);

  imagedestroy($image);

?>

 

I use a png file for my image, you can also use a jpg if you wish and I think a .gif file to. I have mine display the users browser info and IP address on the picture. You'll notice I have four lines for the text with each one repeated twice. The first text is white and the second is black but only one pixel off on it's alignment. I did this to produce a slight drop shadow effect for the text. You can leave it out or add it whichever floats your boat.

 

Remember for each line of text you need to change the position of the next line of text. It also depends on the size of the font you use also. I find trial and error on this is a good way to see how it looks. After that you'll get the feel for how many pixels between the lines of text there should be.

 

Now I'm working on the if and then statement portions for the HTTP_USER_AGENT and REMOTE_ADDR portions of the script so that instead of giving the long line of browser info it will say something like "You are using IE 5" or "Your using Netscape, stop now" hehe, had to add that in there. There are a lot of other nice features you could have fun with.

 

Also take note of what Borfast said earlier on how to make your PHP a png or jpg extension and then direct the .htaccess file to still open as a php file. So when a user checks the pictures property it actually appears to be a png or a jpg file. This is adding to the illusion that it's a picture generating a text string, even when they save the picture it will have the text on the picuture. But in reality it's just the PHP file renamed with the png or jpg file extentsion. If you don't do the .htaccess trick, when you click on the file it will show up as a somename.php for the picture properties. Here is the quote from Borfast on how to do this.

You will want to save this script as a .jpg, .png or .gif file to add the extra l33t touch - you could leave it as a plain .php, .pl or .cgi file but it wouldn't be as funny

 

The only thing left for you to do is add a .htaccess file to the directory where your "image" is, containing something like this:

 

 

CODE 

<Files secret_info.jpg>

 

  ForceType application/x-httpd-php

 

</Files>

 

 

 

 

This will tell Apache to treat the file "secret_info.jpg" as a PHP script, meaning it will be parsed through PHP and it's output sent to the browser.

 

So if any other PHP gurus out there can add something to this script, please do so. Post it here so those of us lacking in PHP skills can have some fun with other options. I hope this helps a little. I'm not a PHP wiz or anything, but I do understand a slight tiny bit. Basically enough to get me into trouble and enough to change the things I want in a script.

 

Have fun with the script and enjoy. I'll post other changes I do here also for everyone to play with as I go. I hope others will post their progress to, I like it when people share. That's what TCH forums are all about.

 

Rock Sign

 

Thumbs Up Mav

Link to comment
Share on other sites

Mav, the random part is quite simple too. A lot simpler than what you have already done ;)

 

If you want to have all your quotes in a text file and then display one of them, do something like this:

 

><?php
  $quotes = file("quotes.txt"); // $quotes becomes an array in which each element
                                                       // is a line of quotes.txt.
  $max = count($quotes) - 1;
  $i = mt_rand(0, $max); // Generate a random number between 0 and the last quote index
  echo $quotes[$i];
?>

 

That's it :)

 

If you plan on getting your quotes from a database, it's quite easy too:

 

><?php
  $db = mysql_connect("localhost", "yourusername", "yourpassword") or die("Unable to connect to database:".mysql_error());
  mysql_select_db("quotesdatabase", $db) or die ("Unable to select database.");

  
  $query = "SELECT quote FROM quotes WHERE id='RAND()*(COUNT(*)-1)'";
  $result = mysql_query($query, $db);

  $count = mysql_num_rows($result);
  for ($i = 0; $i < $count; $i++)
?>

 

I must say that query is probably the most weird SQL query I've ever written, so I'm not quite sure ti will work... :lol:

And I don't have the time to try it out now - I'm late for a math exam. :lol:

 

Give it a try, if you have get into trouble, post here and I'll take a better look at this when I return :)

Link to comment
Share on other sites

Sweetness!! Thumbs Up

 

That's what the doctor ordered. I haven't had time this week to even fiddle with it. Had two exams this week, had to write my speech for class tonight just before I went in, (oops I forgot). I still rastled and A out of the teacher, nothing like talking about computers for a speech. Like that is something hard to do for me. But what she don't know, gets me an A, hehe.

 

I'll try that out Borfast and let you know how it goes. I'm not sure why you would us a sql database unless someone had a but load of quotes or you had an interface which allowed you to change the quotes. Kinda like a cpanel interface using sql to store all the quotes or whatever.

 

I'll give it a whirl though. Thanks a million for the assist!

 

Mav

Link to comment
Share on other sites

How do you seperate the code into the existing code. I get an error when I just plop it into the rest of the code I posted earlier. I posted this into the code:

 

$quotes = file("quotes.txt"); // $quotes becomes an array in which each element

                                                       // is a line of quotes.txt.

  $max = count($quotes) - 1;

  $i = mt_rand(0, $max); // Generate a random number between 0 and the last quote index

  echo $quotes[$i];

 

It just renders the code for the random text and garbles everything else after it. I must be missing something in the insertion of this code into the existing PHP.

 

It kinda looks that some how you couldn't use the echo since it would execute the quote right away instead of where I wanted it in the ImageTTFtext line for my code. I'm not sure on how to make the PHP so I can insert it so it functions like the:

$http_user_agent = $_SERVER["HTTP_USER_AGENT"];

 

 

 

Mav

Link to comment
Share on other sites

echo prints out immediately what you pass to it. It doesn't wait.

That was just an example, it wasn't supposed to fit into your code. :P

 

You should use the $quotes[$i] variable (which contains the randomly selected quote) just like you're using $http_user_agent.

 

If you want, you can make it like this:

 

$quote = $quotes[$i];

 

and then use the variable $quote just like you use the variable $http_user_agent to print it into the image.

 

As for the database, yes, you'd probably want to use it only if you had a lot of quotes or wanted to do some other stuff with them.

If you just want to print a random quote into the image, forget about that :o

Link to comment
Share on other sites

Works like a charm Borfast! You got skills! Thumbs Up

 

I was looking at the code going I know it makes sense but what am I missing in order to make it call the function. Soon as you posted it was like "DUH", staring me dead in the face. Head Bash

 

The Text randomizer works good.

 

I think I'm going to go pickup a PHP book this weekend so I can get some skills wit PHP under my belt. Can you recommend and good PHP books?

 

I want to tackle the if and else and then portions so I can use the "HTTP_USER_AGENT" and make it say just the IE5 or NS 6.1 or what ever they are using instead of the long drawn out version.

 

Thanks again for the assist Borfast! woooot

 

Mav

Link to comment
Share on other sites

Glad I could help :D

 

About the PHP book, I'm really not the person to give you advice on that matter since I only bought one PHP book and I never finished reading it (I don't think I even got to the half of it).

At the time, it seemed like a good buy - the publisher was on my college campus, offering 40% discount to all students, so I bought their book about PHP. It turned out to be the worst piece of... well, you get the idea :)

Actually, all their books are bad. For all of you Portuguese guys out there, don't buy FCA books. They're full of spelling, grammatical and syntatical errors. I'm not Shakespear but I think I write better in English than their authors write in their mother tongue, Portuguese... :(

On top of that, many (most?) of their authors aren't even good on the subject they write about! :blink:

 

Anyway, enough ranting.

 

After that stupid buy, I learned how to search for books on Amazon.

For example, if I'm looking for books about PHP, I go to http://amazon.com(uk, whatever) and search for PHP in the books section. I order them by "Average customer rating" and then I read some of the reviews from each book, starting with the one with greatest rating.

 

Based on both of those parameters (customer rating and reviews) I choose the one that seems to fit my needs. :)

Link to comment
Share on other sites

Yeah, I'll just go down to Barnes & Noble and read the books on the shelf till I find one I like then order it through the college with my student discount.

 

Going back to school is at least having one advantage for getting discounts. Dance

 

 

Mav

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...