NOTE: it seems some think I am asking the question "Should I use this code style?", but I am actually asking "How can I achieve this?". Sorry If my question is confusing.
To create an image with PHP you can use these kind of base functions:
http://php.net/manual/en/ref.image.php
But by default it seems rather static. Example:
/* file: PHPImage.php */
$img = imagecreatefrompng('logo.png');
// Do some stuff to that image
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
I would like to create a class that can manipulate images on the fly and pass it a function that can manipulate the $img on a call back, and do all of that inline.. something like this:
<?php
$img = new PHPImage("baseimage.png", function(&$thisimg){
// Color functions here etc
});
?>
<img src="<?php echo $img->URLResource; ?>" />
I see that this is a feeble example but just wondering if this kind of workflow is possible.
What I'm wondering is: I get that you could pass GET parameters to a constant page setup for this eg. scripts/PHPImage.php?w=160&h=160&bgcol=255-0-0, and then use the passed parameters to run the actual image functions on that page. But is there anyway you could use the actual functions on the image and generate it in a casual workflow, like my PHPImage class example above?
Thanks in advance for any help!
like my PHPImage class example aboveyes make a "wrapper" or "decorator" class. I have a very old one I wrote some years ago not sure how much of it still works. Your welcome to use it as a starting place GitHub. I wrote it for a specific site back in probably 2010, so somethings are only partial implemented, I never got around to finishing it up... :-/&should work by reference, but I never tried it with a resource. I imagine it works though, I have yet another class on github that is an ajax wrapper same kind of idea HERE it traps output and exceptions thrown when returning AJAX, something that's incredibly useful.