Jump to content

Save image to server


putty

Recommended Posts

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.

Link to comment
Share on other sites

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;

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.