[TUTORIAL] [PHP]How-To: Create dynamic pics

Remis

Well-Known Member
Messages
663
In this tutorial you learn how to create dynamic pics like this:
wwwm-e-hcom.jpg


I hope you like it and understand it:

1. mode_rewrite must be activated on your webspace.
2.Choice it should be a .png .gif or .jpg:
Code:
<?
header("Content-type: image/png"); // For a PNG
//header("Content-type: image/jpeg"); // For a JPG
//header("Content-type: image/gif"); //For a Gif
?>

Note: I use .png in this tut.
Now we choice a background-image. It doesnt matter how big the your picture is (not too small for the text, not too big..).

3.Now we choice which picture to load:

Code:
$img = imagecreatefrompng("your_pic.png"); //if the picture is in other path e.g.  /img/your_pic.png

Now we choice what you should see on the pic.
In this tut I make an information about OS, IP etc.

4.Colors:
We have to define the colors:
Code:
$white = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,0,0,0);
$red = imagecolorallocate($img,255,0,0);
$blue = imagecolorallocate($img,0,0,255);
You can also use your colors :tongue: Google will give a hand.
Das Auslesen der Infos:
Now we read out the information about your PC with [HTTP_USER_AGENT]
Code:
/ reading out
if (ereg( 'MSIE',$_SERVER[HTTP_USER_AGENT])) {
if (strstr($_SERVER[HTTP_USER_AGENT],'MSIE 5.0')) {
$browser = "Internet Explorer 5";
} elseif (strstr($_SERVER[HTTP_USER_AGENT],'MSIE 5.5')) {
$browser = "Internet Explorer 5.5";
} elseif (strstr($_SERVER[HTTP_USER_AGENT],'MSIE 6.0')) {
$browser = "Internet Explorer 6";
} else {
$browser = "Internet Explorer";
}
} elseif (ereg( 'Opera',$_SERVER[HTTP_USER_AGENT])) {
$browser = "Opera";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Firefox")) {
$browser = "Firefox";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Safari")) {
$browser = "Safari";
} elseif (ereg("Lynx", $_SERVER["HTTP_USER_AGENT"])) {
$browser = "Lynx";
} elseif(ereg("WebTV", $_SERVER["HTTP_USER_AGENT"])) {
$browser = "WebTV";
} elseif(ereg("Konqueror", $_SERVER["HTTP_USER_AGENT"])) {
$browser = "Konqueror";
} elseif (ereg( 'Mozilla/([0-9].[0-9]{1,2})',$_SERVER[HTTP_USER_AGENT])) {
$browser = "Mozilla";
} else {
$browser = "Unknown";
}

And now the OS:
Code:
// reading out OS
if (strstr($_SERVER[HTTP_USER_AGENT], "Windows 95")) {
$os = "Windows 95";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Windows 98")) {
$os = "Windows 98";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "NT 4.0")) {
$os = "Windows NT";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "NT 5.0")) {
$os = "Windows 2000";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "NT 5.1")) {
$os = "Windows XP";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Win")) {
$os = "Windows";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Mac")) {
$os = "MacOS";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Linux")) {
$os = "Linux";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "FreeBSD")) {
$os = "FreeBSD";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "SunOS")) {
$os = "SunOS";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "IRIX")) {
$os = "IRIX";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "BeOS")) {
$os = "BeOS";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "OS/2")) {
$os = "OS/2";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "AIX")) {
$os = "AIX";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Unix")) {
$os = "Unix";
} else {
$os = "Unknown system";
}

host and ip:
Code:
// reading out ip and host
$ip = getenv("REMOTE_ADDR");   
$host = gethostbyaddr($ip);
Now we have to create the text.
We need position and size of the letters, font, color and the text:
Only Example: ($img, 12, 0, 120, 45, $black, "fonts/kr1.ttf", "Dein OS ist: ")


12 is the letter´s size, 0 width of the letters, 120 beginning of the letter ,45 beginning of the letter from the top .
fonts/kr1.ttf: Download a font here http://www.myfont.de/fonts/techno/shadowed-3d-2.html, put it in "fonts" file and change the name.
You can also change Positions:
i
Code:
magettftext($img, 12, 0, 120, 45, $black, "fonts/kr1.ttf", "Dein OS ist: ");
imagettftext($img, 12, 0, 200, 45, $red, "fonts/kr1.ttf", "". $os);

imagettftext($img, 12, 0, 120, 60, $black, "fonts/kr1.ttf", "Your browser: ");
imagettftext($img, 12, 0, 230, 60, $blue, "fonts/kr1.ttf", "". $browser);

imagettftext($img, 12, 0, 120, 75, $black, "fonts/kr1.ttf", "your ip: ");
imagettftext($img, 12, 0, 230, 75, $red, "fonts/kr1.ttf", "". $ip);

imagettftext($img, 12, 0, 120, 90, $black, "fonts/kr1.ttf", "your host: ");
imagettftext($img, 12, 0, 120, 105, $blue, "fonts/kr1.ttf", "". $host);
And at the end:

Code:
imagepng($img);
:wink:

All in one :
Code:
<?
header("Content-type: image/png"); // for a PNG 
//header("Content-type: image/jpeg"); //for a JPG 
//header("Content-type: image/gif"); //for a Gif 

$img = imagecreatefrompng("s.png");  //name of you background pic!
$white = imagecolorallocate($img,255,255,255);
$black = imagecolorallocate($img,0,0,0);
$red = imagecolorallocate($img,255,0,0);
$blue = imagecolorallocate($img,0,0,255);


// Auslesen der Browser
if (ereg( 'MSIE',$_SERVER[HTTP_USER_AGENT])) {
if (strstr($_SERVER[HTTP_USER_AGENT],'MSIE 5.0')) {
$browser = "Internet Explorer 5";
} elseif (strstr($_SERVER[HTTP_USER_AGENT],'MSIE 5.5')) {
$browser = "Internet Explorer 5.5";
} elseif (strstr($_SERVER[HTTP_USER_AGENT],'MSIE 6.0')) {
$browser = "Internet Explorer 6";
} else {
$browser = "Internet Explorer";
}
} elseif (ereg( 'Opera',$_SERVER[HTTP_USER_AGENT])) {
$browser = "Opera";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Firefox")) {
$browser = "Firefox";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Safari")) {
$browser = "Safari";
} elseif (ereg("Lynx", $_SERVER["HTTP_USER_AGENT"])) {
$browser = "Lynx";
} elseif(ereg("WebTV", $_SERVER["HTTP_USER_AGENT"])) {
$browser = "WebTV";
} elseif(ereg("Konqueror", $_SERVER["HTTP_USER_AGENT"])) {
$browser = "Konqueror";
} elseif (ereg( 'Mozilla/([0-9].[0-9]{1,2})',$_SERVER[HTTP_USER_AGENT])) {
$browser = "Mozilla";
} else {
$browser = "Unknown";
}

// OS
if (strstr($_SERVER[HTTP_USER_AGENT], "Windows 95")) {
$os = "Windows 95";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Windows 98")) {
$os = "Windows 98";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "NT 4.0")) {
$os = "Windows NT";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "NT 5.0")) {
$os = "Windows 2000";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "NT 5.1")) {
$os = "Windows XP";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Win")) {
$os = "Windows";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Mac")) {
$os = "MacOS";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Linux")) {
$os = "Linux";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "FreeBSD")) {
$os = "FreeBSD";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "SunOS")) {
$os = "SunOS";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "IRIX")) {
$os = "IRIX";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "BeOS")) {
$os = "BeOS";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "OS/2")) {
$os = "OS/2";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "AIX")) {
$os = "AIX";
} elseif (strstr($_SERVER[HTTP_USER_AGENT], "Unix")) {
$os = "Unix";
} else {
$os = "unknown system";
}

// pi and host
$ip = getenv("REMOTE_ADDR");
$host = gethostbyaddr($ip);

imagettftext($img, 12, 0, 120, 45, $black, "fonts/Sisterv2.ttf", "your os: ");
imagettftext($img, 12, 0, 200, 45, $red, "fonts/Sisterv2.ttf", "". $os);

imagettftext($img, 12, 0, 120, 60, $black, "fonts/Sisterv2.ttf", "your browser: ");
imagettftext($img, 12, 0, 230, 60, $blue, "fonts/Sisterv2.ttf", "". $browser);

imagettftext($img, 12, 0, 120, 75, $black, "fonts/Sisterv2.ttf", "your ip: ");
imagettftext($img, 12, 0, 230, 75, $red, "fonts/Sisterv2.ttf", "". $ip);

imagettftext($img, 12, 0, 120, 90, $black, "fonts/Sisterv2.ttf", "your host: ");
imagettftext($img, 12, 0, 120, 105, $blue, "fonts/Sisterv2.ttf", "". $host);

ImagePNG($img);
?>

here is mine :
dynamicimage.php

Post questions etc. here
 
Re:
PHP:
How-To: Create dynamic pics[/b]

thx.
Iam making one dynamic pic with random images now  :-*
 
Re:
PHP:
How-To: Create dynamic pics[/b]

thx for sharing, remis, if you wanna add fun stuff to themavesite, just ask, ill give you ftp access :-)
 
Re:
PHP:
How-To: Create dynamic pics[/b]

[quote="Mave"]
thx for sharing, remis, if you wanna add fun stuff to themavesite, just ask, ill give you ftp access :-)
[/quote]
thx.
If I have fun stuff I  ask you.  ;D
 
Re:
PHP:
How-To: Create dynamic pics[/b]

how would you rate your php skills? are you able to make simple html pages into php, with custom comments and ratings?
 
Re:
PHP:
How-To: Create dynamic pics[/b]

Zooh and the others are much  better than me. Iam usually programming "offline", like C++ and VB.  PHP only a bit, allrounder ;D

do you mean like this?
[url=http://remis93.piranho.de/htmlintophp/html/index.html]HTML[/url]
[url=http://remis93.piranho.de/htmlintophp/php/index.php]PHP[/url]
 
Re:
PHP:
How-To: Create dynamic pics[/b]

eh, those are free templates :p
 
Re:
PHP:
How-To: Create dynamic pics[/b]

yes, Iam not good at html/css.

In php version I added some scripts (comment and rating system, i remake the rating system soon.) :P

I made a new dynamic picture, it creates random texts from a array:
[code]<?
header("Content-type: image/png"); // Für eine PNG Datei
$img = imagecreatefrompng("dialog.png"); //sollte das Pic in einem Unterordner liegen müsst Ihr diesen mit angeben zB. /img/deine_Datei.png
$black = imagecolorallocate($img,0,0,0);
 $input = array("Games at themavesite.com", "Videos at themavesite.com", "Community at themavesite.com", "Visit themavesite.com", "Funny pics at themavesite.com", "Mave at themavesite.com", "Funny stuff at themavesite.com", "Pacman at themavesite.com");
$rand_keys = array_rand($input, 2);

imagettftext($img, 12, 0, 58, 32, $red, "fonts/Sisterv2.ttf", "". $input[$rand_keys[0]]);


ImagePNG($img);
?>[/code]
Example:
[IMG]http://remis93.piranho.de/dynamicimage2.php[/IMG]
 
Re:
PHP:
How-To: Create dynamic pics[/b]

nice, but you could do that easily with a gif too :p

btw, if I give you themavesite's files, can you try to make custom comments and ratings ?
 
Re:
PHP:
How-To: Create dynamic pics[/b]

I made a little image service.
http://remis93.piranho.de/phpdynamicpic/
It makes a pic with your text and saves it on the server.
Note: only the first 5 pics work because of broken links, and Iam a bit too lazy to correct them.

Do you want kind of this on themavesite? I could improve it with more fonts you want and pics you want. And I could add that you can choose text AND the lettersize.
 
Back
Top Bottom