Create Graphics Image In php

Graphics image create in php
Graphics image create in php




Embedding an image in a page

•Astandard web page containing text and graphics is created through a series of HTTP requests from the web browser.
•Each response can contain one and only one type of data, and each image requires a separate HTTP request and web server response.
•If we see a page that contains some text and two images, we know that it has taken three HTTP requests and corresponding responses to construct this page.

Example

Take this HTML page, for example:

<html>
<head>
<title>Example Page</title>
</head><body>
This page Contains Two Images.
<img src=”image.png” alt=”image1″ />
<img src=”image2.png” alt=”image2″ />
</body>
</html>

•The series of requests sent by the web browser for this page looks something like this:

GET /page.html HTTP/1.0
GET /image1.png HTTP/1.0
GET /image2.png HTTP/1.0

Basic Graphics Concepts

•An image is a rectangle of pixels of various colors.
•Various file formats (GIF, JPEG, PNG, etc.) have been created that attempt to compress the data somewhat to make smaller files.
•Colorsare identified by their position in the palette, an array of colors.
•Each entry in the palette has three separate colorvalues—one for red, one for green, and one for blue.

<?php

$image = imagecreate(200, 200);

$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);$

black = imagecolorallocate($image, 0x00, 0x00, 0x00);

imagefilledrectangle($image, 50, 50, 150, 150, $black);

header(“Content-Type: image/png”);

imagepng($image);

?>

The Structure of a Graphics Program

•You can create a 256-color image with the imagecreate() function, which returns animage handle:$image = imagecreate(width, height);
•All colorsused in an image must be allocated with the imagecolorallocate() function.
•The first colorallocated becomes the background colorfor the image:$color= imagecolorallocate(image, red, green, blue);
•We uses imagefilledrectangle(), in which you specify the dimensions of the rectangle by passing the coordinates of the top-left and bottom-right corners:imagefilledrectangle(image, tlx, tly, brx, bry, color);
•We useContent-Type header to the browser with the appropriate content type for the kind of image being created.

Create Image With Text In Php

Imagecreate(height,width)
imagefilledrectangle(resource$image,int$x1,int$y1,int$x2,int$y2,int$color)
x1:xcoordinateforpoint1,y1:ycoordinateforpoint1.
x2:xcoordinateforpoint2,y2:ycoordinateforpoint2.
imagettftext(resource$image,$size,$angle,$x,$y,$color,$fontfile,$text).

The angle in degrees, with 0 degrees being left-to-right reading text. Higher values represent a

counter-clockwise rotation. For example, a value of 90 would resultin bottom-to-top reading text.

Example :

Adding text to an image

<?php$im= ImageCreate(200,200);

$white = ImageColorAllocate($im,255,255,255);

$black =ImageColorAllocate($im,0,0,0);

ImageFilledRectangle($im,50,50,150,150,$black);

ImageString($im,5,50,160,”A Black Box”,$black);

Header(‘Content-Type: image/png’);

ImagePNG($im);

?>

This example would be called from a page with a tag like: <img src=”eclipse.php” />. The above button.php script on top of a base image which in this case is “images/button1.png” and outputs the resulting image. This is a very convenient way to avoid having to draw new button images every time you want to change the text of a button. With this method they are dynamically generated.

eclipse.php
<?php
$image = imagecreatetruecolor(250, 250);
//imagecreatetruecolor(width, height)
$white = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image,0,255,0);
imagefilledrectangle($image, 0, 0, 250, 250, $white);$color = imagecolorallocatealpha($image, 0, 0, 255, 30);
//imagecolorallocatealpha(image, red, green, blue, alpha)
//The alpha value is between 0 (opaque) and 127 (transparent).
imagefilledellipse($image, 120, 120, 80, 63, $color);
imagestring($image,10,40,190,”Joalmediapoint Blog”,$text_color);
header(“Content-Type: image/png”);
imagepng($image);
?>

Output

Create Image In Php Dynamic
Create Image In Php Dynamic

Demo

eclipse1.php

Create image in php using Two String

<?php
$image = imagecreatetruecolor(250, 250);
//imagecreatetruecolor(width, height)
$white = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image,0,255,0);
imagefilledrectangle($image, 0, 0, 250, 250, $white);
$color = imagecolorallocatealpha($image, 0, 0, 255, 30);
//imagecolorallocatealpha(image, red, green, blue, alpha)
//The alpha value is between 0 (opaque) and 127 (transparent).
imagefilledellipse($image, 120, 120, 80, 63, $color);
imagestring($image,5,25,20,”Blog.Joalmediapoint.com “,$text_color);
imagestring($image,15,45,200,”Joalmediapoint.com”,$text_color);
header(“Content-Type: image/png”);
imagepng($image);
?>
Output
Create Image Two String Text in php
Create Image Two String Text in php

Demo

Fonts.php

 

Use Different font for create image
<?php
$image = imagecreate(200, 200);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($image, 0x00, 0x00, 0x00);
$color = imagecolorallocate($image, 255,0,255);
$color1 = imagecolorallocate($image,0,0,255);$color2 = imagecolorallocate($image,255,0,0);
//imagestring(image, font_id, x, y, text, color);
imagestring($image, 1, 10, 10, “Joalmediapoint”, $black);
imagestring($image, 2, 10, 30, “Happy”, $black);
imagestring($image, 3, 10, 50, “Childrens”, $color);
imagestring($image, 4, 10, 70, “Day”, $color1);
imagestring($image, 5, 10, 90, “Have a good day”, $color2);
header(“Content-Type: image/png”);
imagepng($image);
?>
Output
Using Diffrent font for creating image
Using Diffrent font for creating image

Demo

 

Create rectangle image in php

 

gray_rectangle.php
<?php
$image = imagecreatetruecolor(150, 150);
$white = imagecolorallocate($image, 255, 255, 255);
imagefilledrectangle($image, 0, 0, 150, 150, $white);
$red = imagecolorallocatealpha($image, 255, 50, 0, 36);
//imagecolorallocatealpha(image, red, green, blue, alpha)imagefilledellipse($image, 75, 75, 80, 50, $red);
$gray = imagecolorallocatealpha($image, 70, 70, 70, 5);
//imagecolorallocatealpha(image, red, green, blue, alpha)
imagefilledrectangle($image, 60, 60, 120, 120, $gray);
header(“Content-Type: image/png”);
imagepng($image);
?>
Create rectangle image in php
how to create rectangle in php

Demo

Create Image in php
image_black.php
<?php
$image = imagecreate(200, 200);
$white = imagecolorallocate($image, 255, 255, 255);
//$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($image, 0, 0, 0);
//$black = imagecolorallocate($image, 0x00, 0x00, 0x00);
imagefilledrectangle($image, 80, 50, 500, 300, $black);
header(“Content-Type: image/png”);
imagepng($image);
?>
Output
Create Image in php
Create Image in php

Demo

Create Rotate Image In Php

•The image rotate() function allows you to rotate an image by an arbitrary angle.
•Syntax –imagerotate(image, angle, background_color);
•The black box image is rotated by 45 degrees.
•The background coloroption, used to specify the colorof the uncovered area after the image is rotated.
•It has been set to 1 to show the contrast of the black and white colors.

 

image_rotate.php

 

<?php
$image = imagecreate(200, 200);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image,255,0,255);
imagefilledrectangle($image, 50, 50, 150, 150, $black);
ImageString($image,2,50,160,”Joalmediapoint”,$color);
$rotated = imagerotate($image, 45, 1);
header(“Content-Type: image/png”);
imagepng($rotated);
?>
Output:
Create Rotate image in php
Create Rotate image in php

Demo

Create Rotate With Rectangle or text

 

image_rotate1.php
<?php
$image = imagecreate(200, 200);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
$color = imagecolorallocate($image,255,0,255);
//imagefilledrectangle($image, 50, 50, 150, 150, $black);imagefilledellipse($image, 100, 90, 100, 100, $color);
imagestring($image,4,40,145,”Joalmediapoint”,$color);
$rotated = imagerotate($image, 45, 1);
header(“Content-Type: image/png”);
imagepng($rotated);
?>

 

Output:

Create image in php with text and cricle or triangle

Demo

In Image Create Image Line Using Php

imageline.php
<?php
$image = imagecreatetruecolor(256, 60);
for ($x = 0; $x < 256; $x++) {
imageline($image, $x, 0, $x, 19, $x);
//imageline($image, 255 – $x, 20, 255 – $x, 39, $x << 8);
//imageline($image, $x, 40, $x, 59, $x<<16);
}
header(“Content-Type: image/png”);
imagepng($image);
?>

 

Output:

Image Line In php
Image Line In php

Demo

Create Box Image In Php

 

jpeg_image.php
<?php
$image = imagecreate(200, 200);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$black = imagecolorallocate($image, 0x00, 0x00, 0x00);
imagefilledrectangle($image, 50, 50, 150, 150, $black);
header(“Content-Type: image/jpeg”);
imagejpeg($image);
?>

 

Output:

Create Box Image In Php
Create Box Image In Php

Demo

Resize Image Using Php

resize.php
<?php
$source = imagecreatefromjpeg(“php.jpg”);
$width = imagesx($source);
$height = imagesy($source);
//$x = $width;
$x = $width * 4 ;
//$y = $height;
$y = $height * 4;
$destination = imagecreatetruecolor($x, $y);
imagecopyresampled($destination, $source, 0, 0, 0, 0, $x, $y, $width, $height);
//imagecopyresampled(dest, src, dx, dy, sx, sy, dw, dh, sw, sh);
header(“Content-Type: image/png”);
imagepng($destination);
?>

Demo

Download ALL

Scaling Image

•There are two ways to change the size of an image.
•The imagecopyresized() function and imagecopyresampled() function are those functions.
•Both functions take the same arguments:imagecopyresized(dest, src, dx, dy, sx, sy, dw, dh, sw, sh);imagecopyresampled(dest, src, dx, dy, sx, sy, dw, dh, sw, sh);
•The destand srcparameters are image handles.
•The point (dx, dy) is the point in the destination image where the region will be copied.
•The point (sx, sy) is the upper-left corner of the source image.
•The sw, sh, dw, and dh parameters give the width and height of the copy regions in the source and destination.

Color Heading

•To create an image, use the imagecreate() function.
•The image’s background is subsequently filled with the first coloryou allocate using imagecolorallocate().
$width = 128;
$height = 256;
$image = imagecreate($width, $height);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
•To create a true colorimage , use the imagecreatetruecolor()function.
$image = imagecreatetruecolor(width, height);
•Use imagecolorallocatealpha() to create a colorindex that includes transparency:
$color= imagecolorallocatealpha(image,red,green,blue,alpha);
•The alpha value is between 0 (opaque) and 127 (transparent).


2 Comments

  1. nike huarache said:

    I am glad for writing to make you understand what a nice discovery my child had studying yuor web blog. She even learned too many details, most notably what it’s like to have an excellent coaching heart to let certain people with ease know precisely specified impossible subject matter. You actually surpassed our own expectations. Thank you for providing the valuable, dependable, revealing as well as cool thoughts on your topic to Lizeth.

    January 2, 2018
    Reply
  2. zenithclippingpath said:

    This is very nice post. It is also very helpful for us. I have been searching types of posts. Some days ago I read an article about post. But this better than post.
    Services
    • Photoshop Clipping Path Service
    • Neck joint s invisible mannequin service
    • 360° products images editing
    • Photoshop shadow service
    • Raster to Vector (R2V) Conversion
    • Advertising Design
    • multiple clipping path or color mask service
    • Photoshop Image Masking Service
    • Remove The Backgrounds
    • photoshop color correction service
    • Photo retouching service
    • Photo restoration service
    • Isolating image service
    • photoshop cutout service
    • I Image cleaning photo dust removal service
    • clipping mask illustrator
    • Photoshop Image manipulation services
    • Photo cropping /Resizing service
    • Image Editing Service
    • Photoshop layer mask service.

    July 23, 2018
    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code