0% found this document useful (0 votes)
2 views

Graphics,Images and PDF

The document discusses basic graphics concepts in PHP, including how to create images using functions like imagecreate() and imagecreatetruecolor(). It explains how to add images to PDF documents and provides syntax for various image manipulation functions. Additionally, it covers color allocation and string placement on images.

Uploaded by

bansalhemant
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Graphics,Images and PDF

The document discusses basic graphics concepts in PHP, including how to create images using functions like imagecreate() and imagecreatetruecolor(). It explains how to add images to PDF documents and provides syntax for various image manipulation functions. Additionally, it covers color allocation and string placement on images.

Uploaded by

bansalhemant
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Basic graphics concept

 There's more to documents than text.


Most PDF files contain some type of logo,
diagram, illustration, or picture. This
section shows how to include image files,
build your own line-art illustrations, and
repeat elements on every page (for
instance, a header with a logo).
docstore.mik.ua/orelly/webprog/php/ch10
_04.htm
PHP | imagecreate()
Function
 The imagecreate() function is an inbuilt
function in PHP which is used to create a
new image. This function returns the
blank image of given size. In
general imagecreatetruecolor() functio
n is used instead of imagecreate()
function
because imagecreatetruecolor() functi
on creates high quality images.
 Syntax:
 imagecreate( $width, $height )
<?php
// Create the size of image or blank image
$image = imagecreate(500, 300);

// Set the background color of image


$background_color = imagecolorallocate($image, 0, 153, 0);

// Set the text color of image


$text_color = imagecolorallocate($image, 255, 255, 255);

// Function to create image which contains string.


imagestring($image, 5, 180, 100, "GeeksforGeeks", $text_color);
imagestring($image, 3, 160, 120, "A computer science portal",
$text_color);

header("Content-Type: image/png");

imagepng($image);
imagedestroy($image);
?>
output
<?php

// Create the size of image or blank image


$image = imagecreate(500, 300);

// Set the vertices of polygon


$values = array(
50, 50, // Point 1 (x, y)
50, 250, // Point 2 (x, y)
250, 50, // Point 3 (x, y)
250, 250 // Point 3 (x, y)
);
// Set the background color of image
$background_color = imagecolorallocate($image, 0, 153, 0);

// Fill background with above selected color


imagefill($image, 0, 0, $background_color);

// Allocate a color for the polygon


$image_color = imagecolorallocate($image, 255, 255, 255);

// Draw the polygon


imagepolygon($image, $values, 4, $image_color);

// Output the picture to the browser


header('Content-type: image/png');

imagepng($image);
?>
output
Creating a pdf of
document
 PDF supports many different embedded
image formats: PNG, JPEG, GIF, TIFF, CCITT,
and a raw image format that consists of a
stream of the exact byte sequence of pixels.
Not every feature of every format is
supported, however.
 Adding an image to a PDF document is
relatively simple. The first step is to call the
appropriate open function for the type of
image you are using. These functions all take
the form pdf_open_ format( ). For instance:
$image = pdf_open_jpeg(pdf, filename);
 Once you have opened the image, use
pdf_place_image( ) to indicate where in your
document the image should be located. While
you have an image open, you can place it
multiple times throughout your document; your
generated file will contain only one copy of the
actual image data. When you are done placing
your image, call the pdf_close_image( ) function:
pdf_place_image(pdf, image, x, y, scale);
pdf_close_image(pdf, image); The scale
parameter indicates the proportional scaling
factor to be used when placing the image in the
document. You can get the dimensions of an
image via
 pdf_get_value( ) calls on the imagewidth and
imageheight keywords.
Some of the image creating
functions
 1 imagejpeg()
 2 imagegif()
 3imagepng()
 4imagewbmp()
Imagecolorallocate()
 It is used to set the color to image
 Syntax-
 Imagecolorallocate(image,red,green,blue)
Imagestring(_)
 It is used to drop the string on the given
image
 Syntax-
 imagrstring(image,fontsize,x,y,string,strin
g_color)
 Ex-
 <?php
 $i=imagecreate(500,500);
 $back=imagecolorallocate($i,0,200,0);
 $text=imagecolorallocate($i,255,255,255
);
 $imagestring($i,5,150,200,”Hello PHP “,
$text);
 Header(content type:image/jpeg);
 Imagejpeg($i);
 ?>
Scalling image
 (1)Imagecreatetruecolor()
 This inbuilt function is used to create
anew true color image. It returns an
image identifier representing a blank
image of the specified size.
 Syntax-
 imagecreatetruecolor(width,height);
 (2)imagecopyresampled()
 It copies rectangular portion of one image
to another image by smoothly
interpolating pixel values. So that in
particular reducing the size of an image
and still retains its clarity.
 Syntax-.
 Imagecopyresampled($dst _img,srs_img,
$dst_x,$dst_y,$src_x,$src_y,$dst_w,
$dst_h,$src_w,$src_h);

You might also like