SlideShare a Scribd company logo
IMAGE FUNCTION
• <?php
create_image();
print "<img src=image.png?".date("U").">";
function create_image(){
$im = @imagecreate(200, 200) or die("Cannot
Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255,
255, 0); // yellow
imagepng($im,"image.png");
imagedestroy($im);
}
?>
line
• <?php
create_image();
print "<img src=image.png?".date("U").">";
function create_image(){
$im = @imagecreate(200, 200) or die("Cannot Initialize new GD image
stream");
$background_color = imagecolorallocate($im, 255, 255, 0); // yellow
$red = imagecolorallocate($im, 255, 0, 0); // red
$blue = imagecolorallocate($im, 0, 0, 255); // blue
imageline ($im, 5, 5, 195, 5, $red);
imageline ($im, 5, 5, 195, 195, $blue);
imagepng($im,"image.png");
imagedestroy($im);
}
?>
Php image functions.pptx
Rectangle
• <?php
create_image();
print "<img src=image.png?".date("U").">";
function create_image(){
$im = @imagecreate(200, 200) or die("Cannot Initialize new GD image
stream");
$background_color = imagecolorallocate($im, 255, 255, 0); // yellow
$red = imagecolorallocate($im, 255, 0, 0); // red
$blue = imagecolorallocate($im, 0, 0, 255); // blue
imagerectangle ($im, 5, 10, 195, 50, $red);
imagefilledrectangle ($im, 5, 100, 195, 140, $blue);
imagepng($im,"image.png");
imagedestroy($im);
}
?>
Php image functions.pptx
Circle
• <?php
create_image();
print "<img src=image.png?".date("U").">";
function create_image(){
$im = @imagecreate(200, 200) or die("Cannot Initialize new GD image
stream");
$background_color = imagecolorallocate($im, 255, 255, 0); // yellow
$red = imagecolorallocate($im, 255, 0, 0); // red
$blue = imagecolorallocate($im, 0, 0, 255); // blue
imageellipse($im, 50, 50, 40, 60, $red);
imagefilledellipse($im, 150, 150, 60, 40, $blue);
imagepng($im,"image.png");
imagedestroy($im);
}
?>
Php image functions.pptx
Arc
• <?php
create_image();
print "<img src=image.png?".date("U").">";
function create_image(){
$im = @imagecreate(200, 200) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 0); // yellow
$red = imagecolorallocate($im, 255, 0, 0); // red
$blue = imagecolorallocate($im, 0, 0, 255); // blue
imagearc($im, 20, 50, 40, 60, 0, 90, $red);
imagearc($im, 70, 50, 40, 60, 0, 180, $red);
imagearc($im, 120, 50, 40, 60, 0, 270, $red);
imagearc($im, 170, 50, 40, 60, 0, 360, $red);
imagefilledarc($im, 20, 150, 40, 60, 0, 90, $blue, IMG_ARC_PIE);
imagefilledarc($im, 70, 150, 40, 60, 0, 180, $blue, IMG_ARC_PIE);
imagefilledarc($im, 120, 150, 40, 60, 0, 270, $blue, IMG_ARC_PIE);
imagefilledarc($im, 170, 150, 40, 60, 0, 360, $blue, IMG_ARC_PIE);
imagepng($im,"image.png");
imagedestroy($im);
}
?>
Php image functions.pptx
Text
• <?php
create_image();
print "<img src=image.png?".date("U").">";
function create_image(){
$im = @imagecreate(200, 200)or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 0); // yellow
$red = imagecolorallocate($im, 255, 0, 0); // red
imagestring($im, 1,file:///C:/apache2triad/htdocs/0image/tutorial1.html 5, 10, "Hello !",
$red);
imagestring($im, 2, 5, 50, "Hello !", $red);
imagestring($im, 3, 5, 90, "Hello !", $red);
imagestring($im, 4, 5, 130, "Hello !", $red);
imagestring($im, 5, 5, 170, "Hello !", $red);
imagestringup($im, 5, 140, 150, "Hello !", $red);
imagepng($im,"image.png");
imagedestroy($im);
}
?>
Image Rotate Example
• <?php
$im = imagecreatefrompng("image.png");
$yellow = imagecolorallocate($im, 255, 255, 0);
$rotate = imagerotate($im, 90,$yellow);
imagepng($rotate,"image_rotated.png");
imagedestroy($im);
print "<img src=image.png> - <img
src=image_rotated.png>";
?>
Image Create From
• imagecreatefromgif -- Create a new image from file or
URL
• imagecreatefromjpeg -- Create a new image from file
or URL
• imagecreatefrompeg -- Create a new image from file
or URL
• imagecreatefromwbmp -- Create a new image from
file or URL
• imagecreatefromxbm -- Create a new image from file
or URL
• imagecreatefromxpm -- Create a new image from file
or URL
Resize Image
• <?php
$original_image = imagecreatefrompng("image.png");
// obtain data from selected image
$image_info = getimagesize("image.png");
// data contained in array $image_info may be displayed in next line
// print_r($image_info)
$width = $image_info[0]; // width of the image
$height = $image_info[1]; // height of the image
// we will reduce image size to 70%, so new dimensions must be calculate
$new_width = round ($width*0.7);
$new_height = round ($height*0.7);
$new_image = imagecreate($new_width, $new_height);
imagecopyresized($new_image, $original_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagepng($new_image,"resized_image.png");
imagedestroy($new_image);
print "<img src=image.png> <br>Resized image<BR> <img src=resized_image.png>";
?>
Php image functions.pptx
Get A Portion of Image
• <?php
// get the original image
$original_image = imagecreatefrompng("image.png");
// create new image
$new_image = imagecreate(200, 200);
// define red color (it will be the background of the new image)
$red = imagecolorallocate($new_image, 255, 0, 0);
imagecopyresized($new_image, $original_image, 75, 75, 0, 0, 100, 100, 100, 100);
imagepng($new_image,"new_image.png");
imagedestroy($new_image);
print "<img src=image.png> <br>New image<BR> <img src=new_image.png>";
?>
Modified an Image
• <?php
// get the original image
$im = imagecreatefrompng("image.png");
// new color
$blue = imagecolorallocate($im, 0, 0, 255); // blue
$red = imagecolorallocate($im, 255, 0, 0); // red
imagefilledrectangle ($im, 80, 5, 195, 60, $blue);
imagestring($im, 5, 80, 5, "Modified!", $red);
imagepng($im,"modified_image.png");
imagedestroy($im);
print "<img src=image.png> <br>Modified image<BR> <img
src=modified_image.png>";
?>
Image Created but not Saved
• <?php
header("Content-type: image/png");
$im = @imagecreate(200, 200) or die("Cannot Initialize new GD image
stream");
$background_color = imagecolorallocate($im, 255, 255, 0); // yellow
$blue = imagecolorallocate($im, 0, 0, 255); // blue
imagestring($im, 3, 5, 5, "My Text String", $blue);
imagepng($im);
imagedestroy($im);
?>

More Related Content

PPTX
DIGITAL_COMMUNITY PPT ABOUT ONLINE SOCIAL LIFE
switipatel4
 
PPTX
Coding_Guidelines for the better and maintainable coding
switipatel4
 
PPT
PPT for Advanced Relational Database Management System
switipatel4
 
PPT
Expert System in artificial intelligence
switipatel4
 
PDF
Mobile application and android with java questions
switipatel4
 
PPTX
OOP in PHP.pptx
switipatel4
 
PPT
E-Mail.ppt
switipatel4
 
PPTX
Software ppt
switipatel4
 
DIGITAL_COMMUNITY PPT ABOUT ONLINE SOCIAL LIFE
switipatel4
 
Coding_Guidelines for the better and maintainable coding
switipatel4
 
PPT for Advanced Relational Database Management System
switipatel4
 
Expert System in artificial intelligence
switipatel4
 
Mobile application and android with java questions
switipatel4
 
OOP in PHP.pptx
switipatel4
 
E-Mail.ppt
switipatel4
 
Software ppt
switipatel4
 
Ad

Php image functions.pptx

  • 1. IMAGE FUNCTION • <?php create_image(); print "<img src=image.png?".date("U").">"; function create_image(){ $im = @imagecreate(200, 200) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 0); // yellow imagepng($im,"image.png"); imagedestroy($im); } ?>
  • 2. line • <?php create_image(); print "<img src=image.png?".date("U").">"; function create_image(){ $im = @imagecreate(200, 200) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 0); // yellow $red = imagecolorallocate($im, 255, 0, 0); // red $blue = imagecolorallocate($im, 0, 0, 255); // blue imageline ($im, 5, 5, 195, 5, $red); imageline ($im, 5, 5, 195, 195, $blue); imagepng($im,"image.png"); imagedestroy($im); } ?>
  • 4. Rectangle • <?php create_image(); print "<img src=image.png?".date("U").">"; function create_image(){ $im = @imagecreate(200, 200) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 0); // yellow $red = imagecolorallocate($im, 255, 0, 0); // red $blue = imagecolorallocate($im, 0, 0, 255); // blue imagerectangle ($im, 5, 10, 195, 50, $red); imagefilledrectangle ($im, 5, 100, 195, 140, $blue); imagepng($im,"image.png"); imagedestroy($im); } ?>
  • 6. Circle • <?php create_image(); print "<img src=image.png?".date("U").">"; function create_image(){ $im = @imagecreate(200, 200) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 0); // yellow $red = imagecolorallocate($im, 255, 0, 0); // red $blue = imagecolorallocate($im, 0, 0, 255); // blue imageellipse($im, 50, 50, 40, 60, $red); imagefilledellipse($im, 150, 150, 60, 40, $blue); imagepng($im,"image.png"); imagedestroy($im); } ?>
  • 8. Arc • <?php create_image(); print "<img src=image.png?".date("U").">"; function create_image(){ $im = @imagecreate(200, 200) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 0); // yellow $red = imagecolorallocate($im, 255, 0, 0); // red $blue = imagecolorallocate($im, 0, 0, 255); // blue imagearc($im, 20, 50, 40, 60, 0, 90, $red); imagearc($im, 70, 50, 40, 60, 0, 180, $red); imagearc($im, 120, 50, 40, 60, 0, 270, $red); imagearc($im, 170, 50, 40, 60, 0, 360, $red); imagefilledarc($im, 20, 150, 40, 60, 0, 90, $blue, IMG_ARC_PIE); imagefilledarc($im, 70, 150, 40, 60, 0, 180, $blue, IMG_ARC_PIE); imagefilledarc($im, 120, 150, 40, 60, 0, 270, $blue, IMG_ARC_PIE); imagefilledarc($im, 170, 150, 40, 60, 0, 360, $blue, IMG_ARC_PIE); imagepng($im,"image.png"); imagedestroy($im); } ?>
  • 10. Text • <?php create_image(); print "<img src=image.png?".date("U").">"; function create_image(){ $im = @imagecreate(200, 200)or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 0); // yellow $red = imagecolorallocate($im, 255, 0, 0); // red imagestring($im, 1,file:///C:/apache2triad/htdocs/0image/tutorial1.html 5, 10, "Hello !", $red); imagestring($im, 2, 5, 50, "Hello !", $red); imagestring($im, 3, 5, 90, "Hello !", $red); imagestring($im, 4, 5, 130, "Hello !", $red); imagestring($im, 5, 5, 170, "Hello !", $red); imagestringup($im, 5, 140, 150, "Hello !", $red); imagepng($im,"image.png"); imagedestroy($im); } ?>
  • 11. Image Rotate Example • <?php $im = imagecreatefrompng("image.png"); $yellow = imagecolorallocate($im, 255, 255, 0); $rotate = imagerotate($im, 90,$yellow); imagepng($rotate,"image_rotated.png"); imagedestroy($im); print "<img src=image.png> - <img src=image_rotated.png>"; ?>
  • 12. Image Create From • imagecreatefromgif -- Create a new image from file or URL • imagecreatefromjpeg -- Create a new image from file or URL • imagecreatefrompeg -- Create a new image from file or URL • imagecreatefromwbmp -- Create a new image from file or URL • imagecreatefromxbm -- Create a new image from file or URL • imagecreatefromxpm -- Create a new image from file or URL
  • 13. Resize Image • <?php $original_image = imagecreatefrompng("image.png"); // obtain data from selected image $image_info = getimagesize("image.png"); // data contained in array $image_info may be displayed in next line // print_r($image_info) $width = $image_info[0]; // width of the image $height = $image_info[1]; // height of the image // we will reduce image size to 70%, so new dimensions must be calculate $new_width = round ($width*0.7); $new_height = round ($height*0.7); $new_image = imagecreate($new_width, $new_height); imagecopyresized($new_image, $original_image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagepng($new_image,"resized_image.png"); imagedestroy($new_image); print "<img src=image.png> <br>Resized image<BR> <img src=resized_image.png>"; ?>
  • 15. Get A Portion of Image • <?php // get the original image $original_image = imagecreatefrompng("image.png"); // create new image $new_image = imagecreate(200, 200); // define red color (it will be the background of the new image) $red = imagecolorallocate($new_image, 255, 0, 0); imagecopyresized($new_image, $original_image, 75, 75, 0, 0, 100, 100, 100, 100); imagepng($new_image,"new_image.png"); imagedestroy($new_image); print "<img src=image.png> <br>New image<BR> <img src=new_image.png>"; ?>
  • 16. Modified an Image • <?php // get the original image $im = imagecreatefrompng("image.png"); // new color $blue = imagecolorallocate($im, 0, 0, 255); // blue $red = imagecolorallocate($im, 255, 0, 0); // red imagefilledrectangle ($im, 80, 5, 195, 60, $blue); imagestring($im, 5, 80, 5, "Modified!", $red); imagepng($im,"modified_image.png"); imagedestroy($im); print "<img src=image.png> <br>Modified image<BR> <img src=modified_image.png>"; ?>
  • 17. Image Created but not Saved • <?php header("Content-type: image/png"); $im = @imagecreate(200, 200) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 0); // yellow $blue = imagecolorallocate($im, 0, 0, 255); // blue imagestring($im, 3, 5, 5, "My Text String", $blue); imagepng($im); imagedestroy($im); ?>