Forum Moderators: coopster

Message Too Old, No Replies

PHP Images Functions

Only showing part of an image

         

chriswragg

7:56 am on Oct 2, 2005 (gmt 0)

10+ Year Member



I am making a rating system on my website, where the number out of 10 is displayed as stars. I want to create an image that only shows part of my original image, for example half of a star. I tried the following code,

<?php
$w = 16 - ((16/10)*$_GET['id']);
header("Content-type: image/gif");
$im = imagecreatefromgif("full.gif");
$col = imagecolorallocate($im,30,30,42);
imagefilledrectangle($im, 16-$x,0,16,16,$col);
imagegif($im);
imagedestroy($im);

?>

but it just returned a normal full.gif image.

Please can I have some advice on where my code is going wrong.

The image is 16 by 16 px and the background color of my page is in $col

Thanks for any help

Chris

ergophobe

4:01 pm on Oct 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



These images don't really need to be generated dynamically, which is a resource-intensive endeavour (though these are small images, so not that intensive).

Frankly, I would simply create a star and a half star in GIMP or PS and, depending on the rating, display as required. It's simple requires no server image processing and you'll get more caching benefit since you'll only have 2 images instead of 19 for every value from .5 to 10 stars.

chriswragg

4:42 pm on Oct 2, 2005 (gmt 0)

10+ Year Member



Thanks for the advice

StupidScript

11:20 pm on Oct 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ergophobe is right ... again! ;)

But re: your code:

imagefilledrectangle($im, 16-$x,0,16,16,$col);

Where's the value for

$x
? If it's not initiallized, your line says:

imagefilledrectangle($im, 16-NULL,0,16,16,$col);

which is to say ... don't crop it at all.