user439555
user439555

Reputation: 95

How to create image in PHP?

I am very new to create image in php.Basically i wanted to make static slider and values will come from database in terms of ratio.Suppose particular value is 0.9 then slider pointer will go at the very end of image

----------------
             | | 
----------------

How can i create this image? please help.

Upvotes: 1

Views: 2503

Answers (3)

SteeveDroz
SteeveDroz

Reputation: 6124

There is a whole library for that called gd2. Here is how it works:

1) Be sure to activate it in your php.ini

2) Copy-paste:

<?php
header('Content-type:image/png');
$image = imagecreate(200, 50); // (x, y)
$background = imagecolorallocate($image, 255, 127, 0); // The first color allocated is the background.
$red = imagecolorallocate($image, 255, 0, 0);
imagefilledrectangle($image, 0, 0, 10, 50, $red); // (x1, y1, x2, y2)
imagepng($image);
?>

3) On your page, use <img src="image.php" /> like if it was a PNG.

4) There is no step 4.

You can also use the power of PHP, things such as loops and math are allowed. You can use $_GET, $_POST, $_SESSION, $_COOKIE, ...

For more questions about that: http://www.astahost.com/info.php/Basic-Tutorial-Php-Gd_t1203.html

Upvotes: 4

RobertPitt
RobertPitt

Reputation: 57258

Sop log a progress metre ?

It's njot that complicated really, just take a look here:

Although i would advise that you do not extract $_GET !!

Upvotes: 0

Rudi Visser
Rudi Visser

Reputation: 21969

For a more generalized answer, if you take a look at the documentation on PHP's image support you'll see lots of methods relevant to you: http://www.php.net/manual/en/ref.image.php

In particular, if you want to go down the GD route, you'd need to look at imagecreate* methods, and then (to dynamically draw your slider at a certain position) imagefill* (probably imagefilledrectangle).

Upvotes: 2

Related Questions