SlideShare a Scribd company logo
1 of 16
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 (20)

Document Object Model
Document Object ModelDocument Object Model
Document Object Model
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Php.ppt
Php.pptPhp.ppt
Php.ppt
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Python's magic methods
Python's magic methodsPython's magic methods
Python's magic methods
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Computer graphics lab assignment
Computer graphics lab assignmentComputer graphics lab assignment
Computer graphics lab assignment
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
Small Basic - Branching and Loop
Small Basic - Branching and LoopSmall Basic - Branching and Loop
Small Basic - Branching and Loop
 
Php gd library
Php gd libraryPhp gd library
Php gd library
 
HTML & CSS
HTML & CSSHTML & CSS
HTML & CSS
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
file handling c++
file handling c++file handling c++
file handling c++
 
Web browser architecture.87 to 88
Web browser architecture.87 to 88Web browser architecture.87 to 88
Web browser architecture.87 to 88
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Html frames
Html framesHtml frames
Html frames
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01Cascading Style Sheets - Part 01
Cascading Style Sheets - Part 01
 
File in c
File in cFile in c
File in c
 

Similar to Drawing images

Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Image manipulation in WordPress 3.5
Image manipulation in WordPress 3.5Marko 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.pdfBe 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 buildingJonny Allbut
 
Themeroller 2.0: Refactoring for Speed
Themeroller 2.0: Refactoring for SpeedThemeroller 2.0: Refactoring for Speed
Themeroller 2.0: Refactoring for SpeedDoug Neiner
 
Presentation-1-1.pptx
Presentation-1-1.pptxPresentation-1-1.pptx
Presentation-1-1.pptxIvanPasana
 
Practical Responsive Images - from Second Wednesday
Practical Responsive Images - from Second WednesdayPractical Responsive Images - from Second Wednesday
Practical Responsive Images - from Second WednesdayBen Seymour
 
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 2013GetSource
 
Responsive WordPress workflow
Responsive WordPress workflowResponsive WordPress workflow
Responsive WordPress workflowJames Bundey
 
Rapid Prototyping
Rapid PrototypingRapid Prototyping
Rapid PrototypingEven Wu
 
DIWE - Using Extensions and Image Manipulation
DIWE - Using Extensions and Image ManipulationDIWE - Using Extensions and Image Manipulation
DIWE - Using Extensions and Image ManipulationRasan 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 2014Christian 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-phpapp02PL 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.pdfShaiAlmog1
 
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 anymoreRemy Sharp
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationMevin Mohan
 
Web application, cookies and sessions
Web application, cookies and sessionsWeb application, cookies and sessions
Web application, cookies and sessionshamsa nandhini
 

Similar to Drawing images (20)

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
 
Web application, cookies and sessions
Web application, cookies and sessionsWeb application, cookies and sessions
Web application, cookies and sessions
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 

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