I'm writing an application which uses the GD library to plot graphs. I don't know yet which version of PHP it will eventually run under, and this makes a difference since earlier versions have .gif support, later versions have .jpeg and .png support. Therefore, I'm not sure yet which image manipulation functions I'll have to use - for example, I could be using either Imagegif($graph) or Imagepng($graph).
Since there are quite a few calls to these functions within the code, I'd like to use a variable $IMAGE_TYPE in my config file and use this to generate the appropriate function name throughout - that way I only have to change one line if necessary. To call the function, I'm thinking something like:
$IMAGE_TYPE = "png"; // (In config)
$str = "Image" . $IMAGE_TYPE . "(\$graph);";
exec($str);
(where $graph is an image identifier) should do the job. But exec() fails to evaluate this expression successfully. Why should this be? Imagepng($graph) works fine, exec("Imagepng(\$graph);") does nothing.
I suspect the answer is something blindingly obvious, but I'm pretty much a novice at this and I'm stumped. Apologies if it's already been addressed here but I couldn't find anything relevant when I searched.
Thanks for listening,
Paul