SlideShare a Scribd company logo
Drawing images on the Server
****(GD-Graphics Designing)
****Image Manipulations in PHP
Page no.501 to 536
Chapter 14
JPEG – Joint Photographic Experts Group
PNG- Portable Network Graphics
BMP - bitmap image
GIF-Graphics Interchange Format
TIF – Tag Image File Format
Creating an Imagephpimg.php
<?php
$h = 100;
$w = 300;
$i= imagecreate($w, $h);
$bcolor= imagecolorallocate($i, 200, 200, 200);
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
• Similar to
Imagegif(), imagewbmp(),imagepng()
• Displaying images in HTML Page
<html>
….
…..
<img src=“phpimg.php”>
….
</html>
Drawing Lines
imageline(image,x1,y1,x2,y2,color)
<?php
$h = 100;
$w = 300;
$i= imagecreate($w, $h);
$bcolor= imagecolorallocate($i, 200, 200, 200);
$blkcolor=imagecolorallocate($i,0, 0, 0);
imageline($i, 40, 20, 90, 80, $blkcolor);
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
Setting Line Thickness
imagesetthickness(image,thickness)
• <?php
$h = 100;
$w = 300;
$i= imagecreate($w, $h);
imagesetthickness($i, 6);
$bcolor= imagecolorallocate($i, 200, 200, 200);
$blkcolor=imagecolorallocate($i,0, 0, 0);
imageline($i, 40, 20, 90, 80, $blkcolor);
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
Drawing Rectangle
imagerectangle(image,x1,y1,x2,y2,color)
• <?php
$h = 100;
$w = 300;
$i= imagecreate($w, $h);
$bcolor= imagecolorallocate($i, 200, 200, 200);
$blkcolor=imagecolorallocate($i,0, 0, 0);
imagerectangle($i, 30, 20, 50, 90, $blkcolor);
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
Drawing Ellipses
imageellipse(image,cx,cy,w,h,color)
• <?php
$h = 100;
$w = 300;
$i= imagecreate($w, $h);
$bcolor= imagecolorallocate($i, 200, 200, 200);
$blkcolor=imagecolorallocate($i,0, 0, 0);
imageellipse($i, 100,40,150,50,$blkcolor);
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
Drawing Arcs
imagearc(image,cx,cy,w,h,s,e,color)• <?php
$h = 100;
$w = 300;
$i= imagecreate($w, $h);
$bcolor= imagecolorallocate($i, 200, 200, 200);
$blkcolor=imagecolorallocate($i,0, 0, 0);
// draw the mouth
imagearc($i, 100, 100, 150, 150, 25, 155, $blkcolor);
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
Drawing Polygons
imagepolygon(image,points,num-points,color)
• <?php
$h = 100;
$w = 300;
$points=array{120,60,130,60,150,80,170,40,150,40,110,20,110,90};
$i= imagecreate($w, $h);
$bcolor= imagecolorallocate($i, 200, 200, 200);
$blkcolor=imagecolorallocate($i,0, 0, 0);
imagepolygon($i, $points, 7, $blkcolor);
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
Filling in Figures
imagefilledarc()
imagefilledellipse(), imagefilledpolygon(), imagefilledrectangle()
• <?php
$h = 100;
$w = 300;
$i= imagecreate($w, $h);
$bcolor= imagecolorallocate($i, 200, 200, 200);
$rcolor=imagecolorallocate($i, 255, 0, 0);
imagefilledrectangle($i,30,20,50,90,$rcolor)
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
Drawing Individual Pixels
imagesetpixel(image,x,y,color)
• <?php
$h = 100;
$w = 300;
$i= imagecreate($w, $h);
$bcolor= imagecolorallocate($i, 200, 200, 200);
$rcolor=imagecolorallocate($i, 255, 0, 0);
for($L=50;$L<270,$L+=3)
{
imagesetpixel($i, $L, $L/3, $rcolor);
}
header(‘Content-Type:image/jpeg’); // to set the image type (browser)
imagejpeg($i); //output a jpeg image to browser or file
imagedestroy($i);
?>
Adding text to an image/Drawing Text
• imagestring takes six arguments
imagestring($image, $font, $x, $y, $string, $colour);
• The font can be 1, 2, 3, 4, 5, where higher numbers produce bigger characters
Drawing vertical Text
• imagestring takes six arguments
imagestringup($image, $font, $x, $y, $string, $colour);
• The font can be 1, 2, 3, 4, 5, where higher numbers produce bigger characters
Helloworld!
We can also import images and then edit them /
working with image files
• imagecreatefromgif
– Example usages:
$im=imagecreatefromgif("someImage.gif");
$im=imagecreatefromgif("someUrlPointingToAGifFile");
• Similarly, there is
– imagecreatefrompng
– Imagecreatefromjpeg
– Imagecreatefromwbmp
– Imagecreatefromxbm
– Imagecreatefromxpm
Drawing on an existing image
Tiling Images
Example #1 imagesettile() example
<?php
// Load an external image
$zend = imagecreatefromgif('./zend.gif');
// Create a 200x200 image
$im = imagecreatetruecolor(200, 200);
// Set the tile
imagesettile($im, $zend);
// Make the image repeat
imagefilledrectangle($im, 0, 0, 199, 199, IMG_COLOR_TILED);
// Output image to the browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
imagedestroy($zend);
?>
Copying Images (Flip image)
imagecopy — Copy part of an image
imagecopy ($dst_im , $src_im , $dst_x , $dst_y , $src_x, $src_y ,$src_w ,$src_h )
Copy a part of src_im on to dst_im starting at the x,y coordinates src_x, src_y with a width
of src_w and a height of src_h. The portion defined will be copied onto the x,y
coordinates, dst_x and dst_y.
Example #1 Cropping the PHP.net logo
<?php
// Create image instances
$src = imagecreatefromgif('php.gif');
$dest = imagecreatetruecolor(80, 40);
// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);
// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);
imagedestroy($dest);
imagedestroy($src);
?>

More Related Content

What's hot

JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
WebStackAcademy
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
Chris Simmonds
 
Hardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for AndroidHardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for Android
National Cheng Kung University
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
Eyal Vardi
 
Compute shader DX11
Compute shader DX11Compute shader DX11
Compute shader DX11
민웅 이
 
Ethereum Basics Part 2
Ethereum Basics Part 2Ethereum Basics Part 2
Ethereum Basics Part 2
Soobok Jin
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
Dominic Arrojado
 
Html media
Html mediaHtml media
Html media
Webtech Learning
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
National Cheng Kung University
 
Doxygen - Source Code Documentation Generator Tool
Doxygen -  Source Code Documentation Generator ToolDoxygen -  Source Code Documentation Generator Tool
Doxygen - Source Code Documentation Generator Tool
Guo Albert
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
NexThoughts Technologies
 
Graphics & Animation with HTML5
Graphics & Animation with HTML5Graphics & Animation with HTML5
Graphics & Animation with HTML5
Knoldus Inc.
 
멀티스레드 렌더링 (Multithreaded rendering)
멀티스레드 렌더링 (Multithreaded rendering)멀티스레드 렌더링 (Multithreaded rendering)
멀티스레드 렌더링 (Multithreaded rendering)
Bongseok Cho
 
CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations
Rob LaPlaca
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
nationalmobileapps
 
CSS
CSS CSS
CSS
Sunil OS
 
Introduction to Web Programming - first course
Introduction to Web Programming - first courseIntroduction to Web Programming - first course
Introduction to Web Programming - first course
Vlad Posea
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
Russ Weakley
 
Shadow mapping 정리
Shadow mapping 정리Shadow mapping 정리
Shadow mapping 정리
changehee lee
 

What's hot (20)

JavaScript - Chapter 15 - Debugging Techniques
 JavaScript - Chapter 15 - Debugging Techniques JavaScript - Chapter 15 - Debugging Techniques
JavaScript - Chapter 15 - Debugging Techniques
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Hardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for AndroidHardware Accelerated 2D Rendering for Android
Hardware Accelerated 2D Rendering for Android
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Compute shader DX11
Compute shader DX11Compute shader DX11
Compute shader DX11
 
Ethereum Basics Part 2
Ethereum Basics Part 2Ethereum Basics Part 2
Ethereum Basics Part 2
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
Html media
Html mediaHtml media
Html media
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Doxygen - Source Code Documentation Generator Tool
Doxygen -  Source Code Documentation Generator ToolDoxygen -  Source Code Documentation Generator Tool
Doxygen - Source Code Documentation Generator Tool
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Graphics & Animation with HTML5
Graphics & Animation with HTML5Graphics & Animation with HTML5
Graphics & Animation with HTML5
 
멀티스레드 렌더링 (Multithreaded rendering)
멀티스레드 렌더링 (Multithreaded rendering)멀티스레드 렌더링 (Multithreaded rendering)
멀티스레드 렌더링 (Multithreaded rendering)
 
CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations CSS Transitions, Transforms, Animations
CSS Transitions, Transforms, Animations
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
CSS
CSS CSS
CSS
 
Introduction to Web Programming - first course
Introduction to Web Programming - first courseIntroduction to Web Programming - first course
Introduction to Web Programming - first course
 
CSS3 Media Queries
CSS3 Media QueriesCSS3 Media Queries
CSS3 Media Queries
 
Shadow mapping 정리
Shadow mapping 정리Shadow mapping 정리
Shadow mapping 정리
 

Similar to Drawing images

Php gd library
Php gd libraryPhp gd library
Php gd library
JIGAR MAKHIJA
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
Marko Heijnen
 
Image Converter script for PNG to JPG & JPG to PNG.pdf
Image Converter script for PNG to JPG & JPG to PNG.pdfImage Converter script for PNG to JPG & JPG to PNG.pdf
Image Converter script for PNG to JPG & JPG to PNG.pdf
Be Problem Solver
 
WordCamp Bristol 2019 - WordPress custom theme building
WordCamp Bristol 2019 - WordPress custom theme buildingWordCamp Bristol 2019 - WordPress custom theme building
WordCamp Bristol 2019 - WordPress custom theme building
Jonny Allbut
 
Themeroller 2.0: Refactoring for Speed
Themeroller 2.0: Refactoring for SpeedThemeroller 2.0: Refactoring for Speed
Themeroller 2.0: Refactoring for Speed
Doug Neiner
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
George Stephanis
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
Jussi Pohjolainen
 
Presentation-1-1.pptx
Presentation-1-1.pptxPresentation-1-1.pptx
Presentation-1-1.pptx
IvanPasana
 
Practical Responsive Images - from Second Wednesday
Practical Responsive Images - from Second WednesdayPractical Responsive Images - from Second Wednesday
Practical Responsive Images - from Second Wednesday
Ben Seymour
 
Images and PWA in magento
Images and PWA in magentoImages and PWA in magento
Images and PWA in magento
Rrap Software Pvt Ltd
 
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
GetSource
 
Responsive WordPress workflow
Responsive WordPress workflowResponsive WordPress workflow
Responsive WordPress workflow
James Bundey
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
Even Wu
 
DIWE - Using Extensions and Image Manipulation
DIWE - Using Extensions and Image ManipulationDIWE - Using Extensions and Image Manipulation
DIWE - Using Extensions and Image Manipulation
Rasan Samarasinghe
 
The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014
Christian Heilmann
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
PL dream
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
ShaiAlmog1
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
Remy Sharp
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
Mevin Mohan
 

Similar to Drawing images (20)

Php gd library
Php gd libraryPhp gd library
Php gd library
 
Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5
 
Image Converter script for PNG to JPG & JPG to PNG.pdf
Image Converter script for PNG to JPG & JPG to PNG.pdfImage Converter script for PNG to JPG & JPG to PNG.pdf
Image Converter script for PNG to JPG & JPG to PNG.pdf
 
WordCamp Bristol 2019 - WordPress custom theme building
WordCamp Bristol 2019 - WordPress custom theme buildingWordCamp Bristol 2019 - WordPress custom theme building
WordCamp Bristol 2019 - WordPress custom theme building
 
Themeroller 2.0: Refactoring for Speed
Themeroller 2.0: Refactoring for SpeedThemeroller 2.0: Refactoring for Speed
Themeroller 2.0: Refactoring for Speed
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Presentation-1-1.pptx
Presentation-1-1.pptxPresentation-1-1.pptx
Presentation-1-1.pptx
 
Practical Responsive Images - from Second Wednesday
Practical Responsive Images - from Second WednesdayPractical Responsive Images - from Second Wednesday
Practical Responsive Images - from Second Wednesday
 
Images and PWA in magento
Images and PWA in magentoImages and PWA in magento
Images and PWA in magento
 
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
Image Manipulation in WordPress 3.5 - WordCamp Phoenix 2013
 
Responsive WordPress workflow
Responsive WordPress workflowResponsive WordPress workflow
Responsive WordPress workflow
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid Prototyping
 
DIWE - Using Extensions and Image Manipulation
DIWE - Using Extensions and Image ManipulationDIWE - Using Extensions and Image Manipulation
DIWE - Using Extensions and Image Manipulation
 
The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014The things browsers can do! SAE Alumni Convention 2014
The things browsers can do! SAE Alumni Convention 2014
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
create-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdfcreate-netflix-clone-06-client-ui.pdf
create-netflix-clone-06-client-ui.pdf
 
HTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymoreHTML5: where flash isn't needed anymore
HTML5: where flash isn't needed anymore
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 

Recently uploaded

What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
haiqairshad
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
Amin Marwan
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
RAHUL
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 

Recently uploaded (20)

What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skillsspot a liar (Haiqa 146).pptx Technical writhing and presentation skills
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
 
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdfIGCSE Biology Chapter 14- Reproduction in Plants.pdf
IGCSE Biology Chapter 14- Reproduction in Plants.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UPLAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
LAND USE LAND COVER AND NDVI OF MIRZAPUR DISTRICT, UP
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 

Drawing images

  • 1. Drawing images on the Server ****(GD-Graphics Designing) ****Image Manipulations in PHP Page no.501 to 536 Chapter 14 JPEG – Joint Photographic Experts Group PNG- Portable Network Graphics BMP - bitmap image GIF-Graphics Interchange Format TIF – Tag Image File Format
  • 2. Creating an Imagephpimg.php <?php $h = 100; $w = 300; $i= imagecreate($w, $h); $bcolor= imagecolorallocate($i, 200, 200, 200); header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?> • Similar to Imagegif(), imagewbmp(),imagepng() • Displaying images in HTML Page <html> …. ….. <img src=“phpimg.php”> …. </html>
  • 3. Drawing Lines imageline(image,x1,y1,x2,y2,color) <?php $h = 100; $w = 300; $i= imagecreate($w, $h); $bcolor= imagecolorallocate($i, 200, 200, 200); $blkcolor=imagecolorallocate($i,0, 0, 0); imageline($i, 40, 20, 90, 80, $blkcolor); header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?>
  • 4. Setting Line Thickness imagesetthickness(image,thickness) • <?php $h = 100; $w = 300; $i= imagecreate($w, $h); imagesetthickness($i, 6); $bcolor= imagecolorallocate($i, 200, 200, 200); $blkcolor=imagecolorallocate($i,0, 0, 0); imageline($i, 40, 20, 90, 80, $blkcolor); header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?>
  • 5. Drawing Rectangle imagerectangle(image,x1,y1,x2,y2,color) • <?php $h = 100; $w = 300; $i= imagecreate($w, $h); $bcolor= imagecolorallocate($i, 200, 200, 200); $blkcolor=imagecolorallocate($i,0, 0, 0); imagerectangle($i, 30, 20, 50, 90, $blkcolor); header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?>
  • 6. Drawing Ellipses imageellipse(image,cx,cy,w,h,color) • <?php $h = 100; $w = 300; $i= imagecreate($w, $h); $bcolor= imagecolorallocate($i, 200, 200, 200); $blkcolor=imagecolorallocate($i,0, 0, 0); imageellipse($i, 100,40,150,50,$blkcolor); header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?>
  • 7. Drawing Arcs imagearc(image,cx,cy,w,h,s,e,color)• <?php $h = 100; $w = 300; $i= imagecreate($w, $h); $bcolor= imagecolorallocate($i, 200, 200, 200); $blkcolor=imagecolorallocate($i,0, 0, 0); // draw the mouth imagearc($i, 100, 100, 150, 150, 25, 155, $blkcolor); header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?>
  • 8. Drawing Polygons imagepolygon(image,points,num-points,color) • <?php $h = 100; $w = 300; $points=array{120,60,130,60,150,80,170,40,150,40,110,20,110,90}; $i= imagecreate($w, $h); $bcolor= imagecolorallocate($i, 200, 200, 200); $blkcolor=imagecolorallocate($i,0, 0, 0); imagepolygon($i, $points, 7, $blkcolor); header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?>
  • 9. Filling in Figures imagefilledarc() imagefilledellipse(), imagefilledpolygon(), imagefilledrectangle() • <?php $h = 100; $w = 300; $i= imagecreate($w, $h); $bcolor= imagecolorallocate($i, 200, 200, 200); $rcolor=imagecolorallocate($i, 255, 0, 0); imagefilledrectangle($i,30,20,50,90,$rcolor) header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?>
  • 10. Drawing Individual Pixels imagesetpixel(image,x,y,color) • <?php $h = 100; $w = 300; $i= imagecreate($w, $h); $bcolor= imagecolorallocate($i, 200, 200, 200); $rcolor=imagecolorallocate($i, 255, 0, 0); for($L=50;$L<270,$L+=3) { imagesetpixel($i, $L, $L/3, $rcolor); } header(‘Content-Type:image/jpeg’); // to set the image type (browser) imagejpeg($i); //output a jpeg image to browser or file imagedestroy($i); ?>
  • 11. Adding text to an image/Drawing Text • imagestring takes six arguments imagestring($image, $font, $x, $y, $string, $colour); • The font can be 1, 2, 3, 4, 5, where higher numbers produce bigger characters
  • 12. Drawing vertical Text • imagestring takes six arguments imagestringup($image, $font, $x, $y, $string, $colour); • The font can be 1, 2, 3, 4, 5, where higher numbers produce bigger characters Helloworld!
  • 13. We can also import images and then edit them / working with image files • imagecreatefromgif – Example usages: $im=imagecreatefromgif("someImage.gif"); $im=imagecreatefromgif("someUrlPointingToAGifFile"); • Similarly, there is – imagecreatefrompng – Imagecreatefromjpeg – Imagecreatefromwbmp – Imagecreatefromxbm – Imagecreatefromxpm
  • 14. Drawing on an existing image
  • 15. Tiling Images Example #1 imagesettile() example <?php // Load an external image $zend = imagecreatefromgif('./zend.gif'); // Create a 200x200 image $im = imagecreatetruecolor(200, 200); // Set the tile imagesettile($im, $zend); // Make the image repeat imagefilledrectangle($im, 0, 0, 199, 199, IMG_COLOR_TILED); // Output image to the browser header('Content-Type: image/png'); imagepng($im); imagedestroy($im); imagedestroy($zend); ?>
  • 16. Copying Images (Flip image) imagecopy — Copy part of an image imagecopy ($dst_im , $src_im , $dst_x , $dst_y , $src_x, $src_y ,$src_w ,$src_h ) Copy a part of src_im on to dst_im starting at the x,y coordinates src_x, src_y with a width of src_w and a height of src_h. The portion defined will be copied onto the x,y coordinates, dst_x and dst_y. Example #1 Cropping the PHP.net logo <?php // Create image instances $src = imagecreatefromgif('php.gif'); $dest = imagecreatetruecolor(80, 40); // Copy imagecopy($dest, $src, 0, 0, 20, 13, 80, 40); // Output and free from memory header('Content-Type: image/gif'); imagegif($dest); imagedestroy($dest); imagedestroy($src); ?>