SlideShare une entreprise Scribd logo
1  sur  17
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);
}
?>
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);
}
?>
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);
}
?>
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);
}
?>
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>";
?>
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);
?>

Contenu connexe

En vedette

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

En vedette (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

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); } ?>
  • 3.
  • 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); } ?>
  • 5.
  • 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); } ?>
  • 7.
  • 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); } ?>
  • 9.
  • 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>"; ?>
  • 14.
  • 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); ?>