putty Posted October 25, 2007 Share Posted October 25, 2007 I have the link to an image generated using an unknown graphic library, I need to be able to take this image and save it to my server. This is what I have so far, all I get is the error image. <?PHP $imageType = 'image/'.$Type; $fname = 'test.jpeg'; "$theURL = 'http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&layers=global_mosaic&styles=&srs=EPSG:4326&bbox=110,-45.5,160,-8&WIDTH=1024&HEIGHT=768&format=image/jpeg'; $backgroundimage = "$theURL"; $im = @imagecreatefromgd($backgroundimage); // Attempt to open //OR //$im = @imagecreatefromjpeg($backgroundimage); // Attempt to open if (!$im) { // See if it failed // $im = imagecreatetruecolor($Width, $Hight); // Create a black image $bgc = imagecolorallocate($im, 135, 206, 250); $tc = imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im, 0, 0, $Width, $Hight, $bgc); // Output an errmsg // imagestring($im, 5, 5, 5, "Error loading Satellite Map", $tc); } header("Content-Type: image/jpeg"); $outfile= $fname; imagejpeg($im,$outfile,100); echo "<br><IMG SRC='$fname' width='500px'>"; ?> Any help would be appreciated. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/74809-save-image-to-server/ Share on other sites More sharing options...
KrisNz Posted October 25, 2007 Share Posted October 25, 2007 This worked for me. I suggest not supressing errors with @ especially when you're trying to figure out whats wrong with something <?PHP $fname = 'test.jpeg'; $theURL = 'http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&layers=global_mosaic&styles=&srs=EPSG:4326&bbox=110,-45.5,160,-8&WIDTH=1024&HEIGHT=768&format=image/jpeg'; $im = imagecreatefromjpeg($theURL); // Attempt to open if (!$im) { // See if it failed // exit("nothing happened"); $im = imagecreatetruecolor($Width, $Hight); // Create a black image $bgc = imagecolorallocate($im, 135, 206, 250); $tc = imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im, 0, 0, $Width, $Hight, $bgc); // Output an errmsg // imagestring($im, 5, 5, 5, "Error loading Satellite Map", $tc); } imagejpeg($im,$fname,100); imagedestroy($im); /** we're echoing out the image using html and reading it from disk so this is incorrect, it would only apply if there was an error so you'll have to adjust the code accordingly or save the error image to disk with the $fname Since that error image IS the same every time it displays you'd be better off not creating it on the fly header("Content-Type: image/jpeg"); */ echo "<br><IMG SRC='$fname' >"; exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/74809-save-image-to-server/#findComment-378285 Share on other sites More sharing options...
putty Posted October 26, 2007 Author Share Posted October 26, 2007 This code is a part of a much larger set of code. I am creating an online mapping application, $theURL is a link to a satellite map image dynamically generated to the longitude and latitude I need. I have many of the satellite images cached on my local system, if my map server can’t find the image on the local cache it gets the image from the $theURL and tries to save it to the local cache, if it cant create the image from the url it creates a blank image to stop the mapping tool from breaking. What I really need to do is workout how to save the satellite image at $theURL to my server. However imagecreatefromjpeg($theURL); or imagecreatefromjpeg($theURL) never create an image. I am using NASA Blue Marble satellite images. You can see an example of the code i use to creat the sat map url at: http://www.ozblog.com.au/?p=276 Or http://www.ozblog.com.au/SatelliteMapGenerator/?Xmin=110&Ymin=8&Dx=50&Dy=37.5&type=jpeg&width=1024&hight=768 I appreciate any help, this problem has slowed me down and dragged my project off schedule. Quote Link to comment https://forums.phpfreaks.com/topic/74809-save-image-to-server/#findComment-378353 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.