Search
Syndication
Sponsors

Archive for the ‘Image’ Category

Use a specific font

Thursday, October 1st, 2009

This example shows how to use a specific font.


<?php
header("Content-type: image/gif");
$image = imagecreate( 500, 250 );
$blue = imagecolorallocate($image, 0,0,255 );
$font = "ARIALBD.TTF";
imageTTFtext( $image, 50, 0, 20, 100, $blue, $font, www.getphp.net );
imagegif($image);
?>

Get the size of an image

Tuesday, March 10th, 2009

Get the size of an image

<?php
$size = getimagesize (”test.jpg”);
echo $size[3];
?>

A GD Effect

Monday, March 9th, 2009

This is a user submitted example of a ggraphical effect created using GD, quite a nice example of what you can do with PHP and GD

<?php
$img_disp = imagecreate(1000,1000);
$backcolor = imagecolorallocate($img_disp,0,0,0);
imagefill($img_disp,0,0,$backcolor);
$textcolor = imagecolorallocate($img_disp,255,0,0);
$x1 = 0;
$y1 = 0;
$x2 = 0;
$y2 = 1000;
for(;;){
$y1 = $y1 + 20;
$x2 = $x2 + 20;
imageline($img_disp,$x1,$y1,$x2,$y2,$textcolor);
if ($y1 == 1000){
break;
}
}
header(”Content-type: image/png”);
imagepng($img_disp); // Draw the image
imagedestroy($img_disp); // Delete the image from the server’s memory
?>

Random Image

Thursday, March 5th, 2009

<?php    
$images=array(’a.jpg’,'b.jpg’,'c.jpg’,'d.jpg’);    
$image=$images[array_rand($images)];   
echo ‘<img src=”path/to/’.$image.’” />’;
?>

Create A PNG

Wednesday, March 4th, 2009

This example shows how to create a PNG file

<html>
<body>
<?php
 //create a 300 by 300 image
    $img=ImageCreate(300,300);
 //a black background
    $bgcolor=ImageColorAllocate($img,0,0,0);
 //red color
    $red=ImagecolorAllocate($img,255,0,0);
 //create a red rectangle
    Imagerectangle($img,50,50,150,250,$red);
 //create a filled red rectangle
    Imagefilledrectangle($img,50,170,150,270,$red);
 //create the png file
    ImagePNG($img,”sample.png”);
 //clean up resources
    ImageDestroy($img);
?>
<img src=”sample.png”>
</body>
</html>