simonjk Posted April 16, 2012 Share Posted April 16, 2012 Hi, I have an image (a weather map) which is created using php which pulls data from a mysql database. I would like to be able to output the result image as a gif or jpg file. Can anyone suggest how this could be done? Many thanks, Simon Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/ Share on other sites More sharing options...
Gibbs Posted April 16, 2012 Share Posted April 16, 2012 You have two main options off the top of my head. You can base64 encode the image an put it directly into the HTML document. This is perfectly acceptable for small images. <?php // Not tested $image = base64_encode($row['image']); $output = 'data:image/jpg;base64,' . $image; ?> <img src="<?php echo $output ?>" /> Or you will have to create a separate script and set the content type in a header. Then you would link to the script in the src attribute. <?php // Not tested $image = $row['image']; header("Content-type: image/jpg"); echo $image; Or you could write the image to the filesystem, which I doubt you want to do. Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337836 Share on other sites More sharing options...
simonjk Posted April 16, 2012 Author Share Posted April 16, 2012 Thanks Gibbs...I'll give that a try and see how I get on. Is it possible to capture the output of a browser window, say as a screen shot? Simon Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337853 Share on other sites More sharing options...
Gibbs Posted April 16, 2012 Share Posted April 16, 2012 Thanks Gibbs...I'll give that a try and see how I get on. Is it possible to capture the output of a browser window, say as a screen shot? Simon I have done this before but not in PHP. I don't think it would be possible in PHP unless you are allowed to use some dangerous functions such as exec. That would still rely on external software though. Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337874 Share on other sites More sharing options...
Psycho Posted April 16, 2012 Share Posted April 16, 2012 Wait a sec, you say you are already creating the image. How are you creating it now and how are you using it? If you already have an image resource you can create a Jpeg or Gif using imagejpeg() or imagegif(), respectively. Not sure why you are wanting to get a screenshot of the users browser. That's not possible without some client-side code that would require installation by the user and, most likely for the user to lower their security settings. Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337888 Share on other sites More sharing options...
simonjk Posted April 16, 2012 Author Share Posted April 16, 2012 Thanks for your reply. What I have is a base map over which I then place weather icons using PHP. It is this resulting 'image' (which of course is not an image at all really) that I want to output as a gif or jpg. Hope that makes more sense? Thanks again, Simon Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337895 Share on other sites More sharing options...
litebearer Posted April 16, 2012 Share Posted April 16, 2012 using gd you can overlay images and save or display the result Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337897 Share on other sites More sharing options...
Psycho Posted April 16, 2012 Share Posted April 16, 2012 using gd you can overlay images and save or display the result Yeah, what he said. You can create a "real" image using the same type of logic you are using now - one image as the based and then placing other images on top. You'll have to do some research though. I've not worked with images a lot so I can't give a lot of pointers. But, if the icons are not rectangular then you will want the source image to have transparency as needed. Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337920 Share on other sites More sharing options...
simonjk Posted April 16, 2012 Author Share Posted April 16, 2012 Thanks so much for this, looking into it further and will report back. Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337921 Share on other sites More sharing options...
Psycho Posted April 16, 2012 Share Posted April 16, 2012 I think this is the main function you will need: http://php.net/manual/en/function.imagecopymerge.php Using the map image use that function repeatedly for each icon you need to add. Quote Link to comment https://forums.phpfreaks.com/topic/261040-output-data-as-an-image/#findComment-1337923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.