$_GET returns non well formed numeric value, but standard variable doesn't?

36 views Asked by At

I'm using a variable to define a color in a PHP image. Have some code.

<?php
header ("Content-type: image/png");
ini_set('display_errors', 0);

$width = 36;
$height = 24;
$handle = imagecreatetruecolor ($width, $height) or die ("Cannot Create image"); //image size

$black = 0x1c1c1c;           //Black
$hp = ImageColorAllocate ($handle, $_GET["red1"], $_GET["green1"], $_GET["blue1"]);
$mp = $_GET["c1"];

ImageFilledRectangle($handle, 0, 0, 12, 24, $black);
ImageFilledRectangle($handle, 13, 0, 24, 24, $hp);
ImageFilledRectangle($handle, 25, 0, 36, 24, $mp);

ImagePng ($handle);
imagedestroy ($handle);
?>

This produces an example image with the GD library that should have the ability to set two custom colors to the middle and right rectangles, with the left rectangle always being the color 0x1c1c1c, which is an off-black. The middle rectangle works fine - you're just passing three numbers to an ImageColorAllocate command, after all - but the right rectangle errors out, with a "non well formed numerical value". Why does this happen, when $black is formatted the same way? Is there a way for me to use a single variable to define a color, instead of three?

[Wed Mar 31 15:15:02.838650 2021] [php7:notice] [pid 10089] [client 45.74.102.92:62479] PHP Notice: A non well formed numeric value encountered in /var/www/html/test.php on line 15

1

There are 1 answers

0
Giga Otomia On

Trolling through the online PHP manual brought me to the hexdec() function. Instead of $mp = $_GET["c1"]; I can use $mp = hexdec($_GET["c1"]);, and it works like a dream. Answered my own stupid question, heh. Thank you for the hint, Quentin.