web 2.0

How to use PHP & Create image

How to use PHP & Create image The guideline/example scripts how to using PHP and GD library create image.

ShotDev Focus:
- PHP & GD Library (Create Image)

Example 1


<?
header("Content-type: image/jpeg");
$images = ImageCreate(300,200);
$photo = ImageColorAllocate($images,0,0,0);
ImageJpeg($images);
ImageDestroy($images);
?>

PHP & GD (Create Image)

Example 2


<?
header("Content-type: image/jpeg");
$images = ImageCreate(300,200);
$color = ImageColorAllocate($images,200,255,255);
$photo = ImageColorAllocate($images,0,0,0);
ImageRectangle($images, 0, 0, 299, 199, $photo);
ImageJpeg($images);
ImageDestroy($images);
?>

PHP & GD (Create Image)

Example 3


<?php
header("Content-type: image/gif");
$im = imagecreate( 200, 200 );
$red = imagecolorallocate($im, 255,0,0);
$blue = imagecolorallocate($im, 0,0,255 );
imageline( $im, 0, 0, 199, 199, $blue );
imagegif($im);
?>

PHP & GD (Create Image)


<?php
header("Content-type: image/gif");
$im = imagecreate( 200, 200 );
$red = imagecolorallocate($im, 255,0,0);
$blue = imagecolorallocate($im, 0,0,255 );
$green = ImageColorAllocate ($im, 0, 255, 0);
imagefilledrectangle($im,19,19,179,179,$blue);
imagefilledrectangle($im,40,50,155,150,$green);
imagegif($im);
?>

PHP & GD (Create Image)


<?
echo "<img src=MyResize/image1.png>";
echo "<br><br>";
echo "<img src=image2.png>";
$im = ImageCreate(300, 200);
$background_color = imagecolorallocate($im, 255, 255, 0);
$red = ImageColorAllocate($im, 255, 0, 0);
$blue = ImageColorAllocate($im, 0, 0, 255);

//*** line ***//
ImageLine($im,5,5,280,5,$red);
ImageLine($im,5,5, 195, 170,$blue);

//** Box ***//
ImageRectangle ($im,5,10,250,50,$red);
ImageFilledrectangle ($im,5,100,250,140,$blue);

ImagePng($im,"MyResize/image1.png");
ImagePng($im,"MyResize/image2.png");
imageDestroy($im);
?>

PHP & GD (Create Image)

Example 4


<?php
$im = ImageCreate(250,200);

$white = ImageColorAllocate ($im, 255, 255, 255);
$red  = ImageColorAllocate ($im, 255, 0, 0);
$green = ImageColorAllocate ($im, 0, 255, 0);
$blue = ImageColorAllocate ($im, 0, 0, 255);

ImageFilledArc($im, 120, 100, 200, 150, 0, 90, $green, IMG_ARC_PIE);
ImageFilledArc($im, 120, 100, 200, 150, 90, 180 , $red, IMG_ARC_PIE);
ImageFilledArc($im, 120, 100, 200, 150, 180, 360 , $blue, IMG_ARC_PIE);

echo "<img src=MyResize/image.png>";
ImagePNG($im,"MyResize/image.png");

ImageDestroy($im);
?>

PHP & GD (Create Image)

Example 5


<?php
header ("Content-type: image/png");

$im = ImageCreate (150, 150);
$grey = ImageColorAllocate ($im, 230, 230, 230);
$red = ImageColorAllocate ($im, 255, 0, 0);
$green = ImageColorAllocate ($im, 0, 255, 0);
$blue = ImageColorAllocate ($im, 0, 0, 255);

ImageArc($im, 55, 60, 50, 50, 0, 360, $red);
ImageArc($im, 85, 60, 50, 50, 0, 360, $green);
ImageArc($im, 70, 85, 50, 50, 0, 360, $blue);

ImagePng ($im);
ImageDestroy ($im);
?>

PHP & GD (Create Image)

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (2 votes, average: 1.00 out of 10)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.