Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How to create a canvas image in php?

user-image
Question added by Maalik Muhamed , Deputy Mill Manager , AZANIA GROUP OF COMPANYS
Date Posted: 2014/05/24
Afsheen Atif
by Afsheen Atif

If your question is how to draw a canvas (canvas is a rectangular area on a page)and an image over it in Php then here is a simple example to draw a black  rectangular canvas and a pink rectangle over that canvas:

 

<?php

// Create a200 x200 canvas image

$canvas = imagecreatetruecolor(250,200);

 

// Allocate color for rectangle

$pink = imagecolorallocate($canvas,255,105,180);

 

// Draw rectangle with its color

imagerectangle($canvas,50,50,200,150, $pink);

 

// Output and free from memory

header('Content-Type: image/jpeg');

 

imagejpeg($canvas);

imagedestroy($canvas);

?>

 

Cheers!

Jasim Ahmed
by Jasim Ahmed , Technical and Engineering Lead , alkamilbooking.com

Well there are lots of ways to create Canvases in PHP. There is ImageManipulation Library ann Canvas Class I used once. I do not know what you need actually and why you asked this question so I take it as general knowledge discussion.

Once you have the class you can call it this way to use an Image Canvas:

 

require_once "canvas.php"; // Canvas Class Path

$img = new canvas("image/test.jpg"); // Image to be manipulate

$img->resize("1024", "768") // Resizing Image if needed

    ->filter("grayscale") // FIltering to Grey Scall, web optimized

    ->text("JayZee", array( // Text you want to put on Canvas, text properties

           "color" => "#fff", 

           "background_color" => "#000",

           "size" =>10,

           "x" => "right",

           "y" => "bottom"))

    ->save("temp/new_image.png"); // Saving image to new format, PNG

 

So thats how you do it. And there are many other features in PHP Canvas . I hope thats clear how to use Image Canvas using PHP Canvas.

More Questions Like This