GD Library in PHP CH. Pradeep Reddy Assistant Professor VIT University, Vellore.

Slides:



Advertisements
Similar presentations
PHP Sample Application Simple graphics and database.
Advertisements

Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Cosc 5/4730 Blackberry Drawing. Screen size With Blackberry devices, they have a known screen size in pixels. If you are programming for specific device.
Chapter 2 Programming by Example. A Holistic Perspective Three sections separated by blank lines. Program comment File: FileName.java
Graphics Programming. In this class we will cover: Drawing lines, rectangles, and ellipses Copying an area Drawing an image.
1 Cascading Style Sheets Continued Different kinds of selectors in a style sheet –Simple- Pseudo-Class –Contextual- Pseudo-Element –Class Image Styles.
HTML 5 Previous version: HTML4.01, 1999 Still work in progress, most browsers support some of it.
Copyright © 2004 ProsoftTraining, All Rights Reserved. Lesson 4: Horizontal Rules and Graphical Elements.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
Higher-level PHP constructs for manipulating image files (contd.)
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Java Applets What is an Applet? How do you create.
Higher-level PHP constructs for manipulating image files.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Applets and Graphics.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
Graphics and Multimedia. Introduction The language contains many sophisticated drawing capabilities as part of namespace System.Drawing and the other.
Copyright © 2004 ProsoftTraining, All Rights Reserved. Lesson 4: Horizontal Rules and Graphical Elements © 2007 Prosoft Learning Corporation All rights.
Graphics and Multimedia Part #2
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
 Pearson Education, Inc. All rights reserved. 1 Ch 12 Graphics and Java 2D In this chapter you will learn:  To understand graphics contexts.
Python Image Library PIL 10/13/05. PIL – What is it? Pythonic library for Loading and Saving images (diverse formats) Scaling, cropping, compositing,
1 Web Developer Foundations: Using XHTML Chapter 4 Key Concepts.
1 Web Developer & Design Foundations with XHTML Chapter 4 Key Concepts.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Image Representation. Objectives  Bitmaps: resolution, colour depth and simple bitmap file calculations.  Vector graphics: drawing list – objects and.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved CheckWriter Application Introducing Graphics and Printing.
Macromedia Studio 8 Step-by-Step MACROMEDIA FIREWORKS 8 Project 2: Experience Bank Logo.
Lecture 16 Image Document Formats. Bitmap vs. Vector Images Bitmaps do not generally.
2010/11 : [1]Building Web Applications using MySQL and PHP (W1)Graphics.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Merete S COLLEGEFACULTY OF ENGINEERING & SCIENCE Graphics ikt403 – Object-Oriented Software Development.
Intro to VRML Let’s build something! The source code examples in this tutorial WORK!
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Fall UI Design and Implementation1 Lecture 6: Output.
Graphics and Image Data Representations 1. Q1 How images are represented in a computer system? 2.
Georgia Institute of Technology Drawing in Java – part 1 Barb Ericson Georgia Institute of Technology September 2005.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
3. Drawing Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
[Charts| Generating Graphic| Creating Graphic]
12 Graphics and Java 2D™.
Representation of image data
Images and 2D Graphics COMP
Pixels, Colors and Shapes
Logo with Curved Text.
Learn Animations in Fireworks
Inserting and Working with Images
Barb Ericson Georgia Institute of Technology September 2005
PHP Image Manipulation
Graphics and Multimedia
9. Drawing Let's Learn Python and Pygame
Tag Basics.
Chapter 5 Working with Images
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Representing Images 2.6 – Data Representation.
Geb Thomas Adapted from the OpenGL Programming Guide
Formatting a Workbook Part 1
Chapter 2 Graphics Programming with C++ and the Dark GDK Library
Tutorial 3 Working with Cascading Style Sheets
Lesson 3: Cascading Style Sheets (CSS) and Graphical Elements
Chapter 7 The Game Loop and Animation
TITLE BYOT Half Circle (Advanced)
Presentation transcript:

GD Library in PHP CH. Pradeep Reddy Assistant Professor VIT University, Vellore

About GD Library The PHP GD Library is one of the most used image- processing libraries used in the PHP programs. IT is one of the robust library to create GIF, JPG and PNG images through PHP program. You can use this library to create, modify, resize, crop image on the fly. The GD library is used to create dynamic image creation. GD is an open source code library

How to set up GD library in WAMP ;extension=php_gd2.dll Remove the comments for this in php.ini extension=php_gd2.dll Then restart the WAMP server. Will enable GD library in WAMP

gd_info gd_info — Retrieve information about the currently installed GD library Description array gd_info ( void ) – Gets information about the version and capabilities of the installed GD library. Return Values – Returns an associative array.

AttributeMeaning GD Versionstring value describing the installed libgd version Freetype Supportboolean value. TRUE if Freetype Support is installed Freetype Linkagestring value describing the way in which Freetype was linked. Will only be defined if Freetype Support evaluated to TRUE T1Lib Supportboolean value. TRUE if T1Lib support is included GIF Read Supportboolean value. TRUE if support for reading GIF images is included GIF Create SupportBoolean value. TRUE if support for creating GIF images is included JPEG SupportBoolean value. TRUE if JPEG support is included PNG SupportBoolean value. TRUE if PNG support is included WBMP SupportBoolean value. TRUE if WBMP support is included XBM SupportBoolean value. TRUE if XBM support is included

Example <?php $x=gd_info(); Print-r($x); ?> The above example will output something similar to: array { ["GD Version"]=> string(24) "bundled (2.0 compatible)" ["FreeType Support"]=> bool(false) ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(false) ["JPEG Support"]=> bool(false) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XBM Support"]=> bool(false) }

imagecreate imagecreate — Create a new palette based image Description resource imagecreate ( int $width, int $height ) imagecreate() returns an image identifier representing a blank image of specified size. – We recommend the use of imagecreatetruecolor(). Parameters width : The image width. height : The image height. Return Values Returns an image resource identifier on success, FALSE on errors.

imagecolorallocate imagecolorallocate — Allocate a color for an image Description int imagecolorallocate ( resource $image, int $red, int $green, int $blue ) – Returns a color identifier representing the color composed of the given RGB components. imagecolorallocate() must be called to create each color that is to be used in the image represented by image. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). – red : Value of red component. – green : Value of green component. – blue : Value of blue component. These parameters are integers between 0 and 255 or hexadecimals between 0x00 and 0xFF. Return Values A color identifier or FALSE if the allocation failed.

imagestring imagestring — Draw a string horizontally Description bool imagestring ( resource $image, int $font, int $x, int $y, string $string, int $color ) Draws a string at the given coordinates. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). – font: Can be 1, 2, 3, 4, 5 for built-in fonts in latin2 encoding (where higher numbers corresponding to larger fonts) or any of your own font identifiers registered with imageloadfont(). – x : x-coordinate of the upper left corner. – y : y-coordinate of the upper left corner. – string : The string to be written. – color : A color identifier created with imagecolorallocate(). Return Values Returns TRUE on success or FALSE on failure. imagestringup — Draw a string vertically

imagepng imagepng — Output a PNG image to either the browser or a file Description – bool imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] ) Outputs or saves a PNG image from the given image. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). – filename :: The path to save the file to. If not set or NULL, the raw image stream will be outputted directly. Note: NULL is invalid if the quality and filters arguments are not used. – quality : Compression level: from 0 (no compression) to 9. – filters : Allows reducing the PNG file size. It is a bitmask field which may be set to any combination of the PNG_FILTER_XXX constants. PNG_NO_FILTER or PNG_ALL_FILTERS may also be used to respectively disable or activate all filters. More Functions used imagegif() - Output image to browser or file imagewbmp() - Output image to browser or file imagejpeg() - Output image to browser or file imagetypes() - Return the image types supported by this PHP build

imagedestroy imagedestroy — Destroy an image Description bool imagedestroy ( resource $image ) – imagedestroy() frees any memory associated with image image. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). Return Values – Returns TRUE on success or FALSE on failure. Example: <?php // create a 100 x 100 image $im = imagecreatetruecolor(100, 100); // alter or save the image // frees image from memory imagedestroy($im); ?>

Example <?php header("Content-Type: image/png"); // used to display image on fly $im 20) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 0, 0, 0); $text_color = imagecolorallocate($im, 233, 14, 91); imagestring($im, 1, 5, 5, "A Simple Text String", $text_color); // used to add string to an image imagepng($im); // used to save image imagedestroy($im); //used to free memory space occupied by image ?> The above example will output something similar to:

Imageline() Imageline imageline — Draw a line : Draws a line between the two given points. Description bool imageline ( resource $image, int $x1, int $y1, int $x2, int $y2, int $color ) Parameters image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). X1 : x-coordinate for first point. Y1 : y-coordinate for first point. X2 : x-coordinate for second point. Y2 : y-coordinate for second point. Color : The line color. A color identifier created with imagecolorallocate(). Return Values Returns TRUE on success or FALSE on failure.

Example <?php create_image(); print " "; function create_image(){ $im 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); } ?>

imagerectangle imagerectangle — Draw a rectangle Description bool imagerectangle ( resource $image, int $x1, int $y1, int $x2, int $y2, int $color ) imagerectangle() creates a rectangle starting at the specified coordinates. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). – x1 : Upper left x coordinate. – y1 : Upper left y coordinate 0, 0 is the top left corner of the image. – x2 : Bottom right x coordinate. – y2 : Bottom right y coordinate. – Color: A color identifier created with imagecolorallocate(). Return Values – Returns TRUE on success or FALSE on failure. imagefilledrectangle — Draw a filled rectangle – Creates a rectangle filled with color in the given image starting at point 1 and ending at point 2: – 0, 0 is the top left corner of the image.

Example <?php // Create a 55x30 image $im = imagecreatetruecolor(55, 30); $white = imagecolorallocate($im, 255, 255, 255); // Draw a white rectangle imagefilledrectangle($im, 4, 4, 50, 25, $white); // Save the image imagepng($im, './imagefilledrectangle.png'); print " "; imagedestroy($im); ?>

imageellipse imageellipse — Draw an ellipse Description – bool imageellipse ( resource $image, int $cx, int $cy, int $width, int $height, int $color ) Draws an ellipse centered at the specified coordinates. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). – cx : x-coordinate of the center. – cy : y-coordinate of the center. – width : The ellipse width. – height : The ellipse height. – color : The color of the ellipse. A color identifier created with imagecolorallocate(). Return Values Returns TRUE on success or FALSE on failure. imagefilledellipse — Draw a filled ellipse

Example <?php create_image(); print " "; function create_image(){ $im 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); } ?>

imagearc imagearc — Draws an arc Description – bool imagearc ( resource $image, int $cx, int $cy, int $width, int $height, int $start, int $end, int $color ) imagearc() draws an arc of circle centered at the given coordinates. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). – cx : x-coordinate of the center. – cy : y-coordinate of the center. – width : The arc width. – height : The arc height. – start : The arc start angle, in degrees. – end : The arc end angle, in degrees. 0° is located at the three-o'clock position, and the arc is drawn clockwise. – Color: A color identifier created with imagecolorallocate(). Return Values Returns TRUE on success or FALSE on failure. imagefilledarc — Draw a partial arc and fill it

Example <?php create_image(); print " "; function create_image(){ $im 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); } ?>

imagepolygon imagepolygon — Draws a polygon Description – bool imagepolygon ( resource $image, array $points, int $num_points, int $color ) imagepolygon() creates a polygon in the given image. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). – points : An array containing the polygon's vertices, e.g.: points[0]= x0 points[1]= y0 points[2]= x1 points[3]= y1 – num_points: Total number of points (vertices). – color : A color identifier created with imagecolorallocate(). Return Values Returns TRUE on success or FALSE on failure. imagefilledpolygon — Draw a filled polygon

Example <?php create_image(); print " "; function create_image(){ $im 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); } ?>

imagecreatefrompng imagecreatefrompng — Create a new image from file or URL Description – resource imagecreatefrompng ( string $filename ) imagecreatefrompng() returns an image identifier representing the image obtained from the given filename. Parameters – Filename: Path to the PNG image. Return Values – Returns an image resource identifier on success, FALSE on error. imagecreatefromjpeg -- Create a new image from file or URL imagecreatefromwbmp -- Create a new image from file or URL errors.imagecreatefromgif -- Create a new image from file or URL

imagerotate imagerotate — Rotate an image with a given angle Description – resource imagerotate ( resource $image, float $angle, int $bgd_color [, int $ignore_transparent = 0 ] ) Rotates the image using the given angle in degrees. The center of rotation is the center of the image, and the rotated image may have different dimensions than the original image. Parameters – image: An image resource, returned by one of the image creation functions, such as imagecreatetruecolor(). – angle : Rotation angle, in degrees. The rotation angle is interpreted as the number of degrees to rotate the image anticlockwise. – bgd_color: Specifies the color of the uncovered zone after the rotation – ignore_transparent : If set and non-zero, transparent colors are ignored (otherwise kept). Return Values – Returns an image resource for the rotated image, or FALSE on failure.

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

References Library-PHP-Image-Manipulation Library-PHP-Image-Manipulation