Forum Moderators: coopster
Where $picName holds the parameters needed for a particular image
generateimage.php sends the request to the server which generates the image as $pngstr and responds:
header("Content-Type: image/png".chr(13).chr(10));
header("Content-Length: ".strlen($pngstr).chr(13).chr(10).chr(13).chr(10));
echo $pngstr;
Now, I want the user to be able to right click the image and save it with a given name - related to but not exactly $picName, as a png.
Can anyone help me do this?
I also have a set of images forming an animation generated in much the same way as the single image described above. How could I have the user save these? is there an animated png yet?
$img = imagecreatefrompng("test.png");
imagepng($img);
That will open test.png and then output it to the browser. You would have to do some interpretation to give the image a different name. If you are on an apache server you could force the filetypes *.png to be handled as php (using htaccess directives), then place a link like:
<img id = "picid" src= "myimage.png">
'myimage.png' would really be a php file that generates a dynamic PNG image (like the example above). To get around having to create a seperate file for each image you'd have to use htaccess again with apache's mod_rewrite rule to force all requests to be handled by the one file (and pull your 'virtual' image name from the REQUEST_URI).
It's probably getting a little advanced, I'm not sure of your skill level. Does anyone have any simpler ideas?
If not, and you are using php on an apache server look up apache mod_rewrite rules and force application type directives and they should hopefully get you pointed in the right direction. Post again if you need help with the actual PHP to deliver the image.