PHP image tutorial

Patrick S.

Seasoned Veteran
Joined
Apr 1, 2011
Messages
3,378
Reaction score
0
FP$
6
Here is a tutorial on how to make PHP Images Like this:
glock.png


First Code:
Code:
<?php
$my_img = imagecreate( 200, 80 );
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
imagestring( $my_img, 4, 30, 25, "gamernetblog.tk",
  $text_colour );
imagesetthickness ( $my_img, 5 );
imageline( $my_img, 30, 45, 165, 45, $line_colour );

header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );
?>

First off:
$my_img = imagecreate( 200, 80 );

This is the Image it's self the 200 is width and the 80 is height

Now for colors:
$background = imagecolorallocate( $my_img, 0, 0, 255 );
$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
The Numbers there are For colors (You will have to experiment with them)

Now for the Writing:
imagestring( $my_img, 4, 30, 25, "gamernetblog.tk", $text_colour );

4 is for text size

30 for distance from left side(Bigger number more towards the right side)

25 distance from top(Bugger number more towards the bottom it will be)

Change the "gamernetblog.tk" to any thing like "my site.com" (with the ")

The rest of the code:
header( "Content-type: image/png" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagedestroy( $my_img );

Header Creates them image Imagepng makes the <img src=""> think it's a PNG file

imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );

Combines the different colors into one image

imagedestroy( $my_img );

Destroy's image if it's not working

That's how you do it.

Thanks for Reading.
 
Back
Top Bottom