Help with an Image Script

Hello! =3

Let me preface this by saying I am very much the beginner, but I’ve placed this here since it seems a bit more complex than something like “How do I allocate a color”? If I’ve done wrong, I apologize. ^.^;

I’ve written a script which is supposed to dynamically draw a progress bar onto an existing png, and for the most part, it works. However, I’m having an issue with the colors. =/

Here is the script:

[php]<?php
$v1 = $_GET[‘goal’];
$v2 = $_GET[‘auro’];
$v3 = 300*($v2/$v1);
$hex = $_GET[‘bar’];

$color[‘r’] = hexdec(substr($hex, 0, 2));
$color[‘g’] = hexdec(substr($hex, 2, 2));
$color[‘b’] = hexdec(substr($hex, 4, 2));

$my_img = imagecreatefrompng ( ‘bgbubble.png’ );
$bar = imagecreate ( 300, 12 );
$background_color = imagecolorallocate($bar, $color[‘r’], $color[‘g’], $color[‘b’]);

if ($v2<=$v1)
imagecopy ( $my_img , $bar , 14 , 64 , 0 , 0 , $v3 , 12 );
elseif ($v2>$v1)
imagecopy ( $my_img , $bar , 14 , 64 , 0 , 0 , 300 , 12 );

$text_colour = imagecolorallocate( $my_img, 0, 0, 0 );
imagestring( $my_img, 2, 135, 63, “$v2 // $v1”, $text_colour );

header( “Content-type: image/png” );
imagepng( $my_img );

imagecolordeallocate( $text_color );
imagecolordeallocate( $background_color );
imagedestroy( $bar );
imagedestroy( $my_img );
?>[/php]

Here is what ‘bgbubble’ looks like:

Here is what it looks like scripted using this url:


The problem? The end of the url is a hex color. In this case, yellow, and its clearly not displaying that way.

It works on this image just fine:

Since I don’t make the images, I can’t speak to their details, unfortunately.

But as far as the script goes, I’ve tried everything I can google. So… help, please?

What you’ll want to do is see if there’s a way for you to pull and echo the values of $color[‘r’], $color[‘g’], $color[‘b’] to see what they are. Make sure they’re the same values as what you’re using for your other “yellow”. If not, you’ll want to look at the source of the values, or if there’s anywhere they might change along the way.

I’m afraid I don’t entirely understand. ^.^;

The variables $color[‘r’], $color[‘g’], $color[‘b’] are created from the hex color in the url, and I used the same color for both images. So, both images are using the same set of variables.

What I think is happening, is that the yellow is being blended with the background color in bgbubble, which I’m told is a shade of brown. I don’t know how to make it stop doing that.

It clearly doesn’t mix the colors in the other image, in which the background color is red, or in several other images I’m using it on. I’ve tried turning off alpha blending, and I’ve tried converting the png to a palette image. My artist tried saving it as a gif instead, all to no avail. (Of course, I may have scripted any of that wrong, newb that I am. XD)

Maybe the problem is in the composition of the image itself, but I was hoping it was something I could fix with the script.

Thank you for your reply. =3

I noticed your background image ‘bgbubble’ is paletted - 256 colors. I think you need to add this desired color to a image palette. Or just try to convert image to true color, draw color bar, and then convert result image back to 256 colors.

As a side note, I think this method is too resource intensive. I would consider drawing progress bar as a CSS element with the background image.

Oh, its already paletted? That was probably my problem. I though PNGs were truecolor. XD
I’ve spoken with my artist, and she’s fixed it. ^.^

Thank you for your reply! ^____^

(The images are meant for others to use in forum signatures.)

Sponsor our Newsletter | Privacy Policy | Terms of Service