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); ?>
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); ?>
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 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); ?>
<? 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); ?>
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); ?>
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); ?>