473,765 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I save this image?

290 Contributor
Hi,

I am using snapcasa.com to provide me with an image.

They encourage you to cache the images on your own server so I am trying to do that.

When I use this code to display the image it works fine:

Expand|Select|Wrap|Line Numbers
  1. <img src=\"http://snapcasa.com/get.aspx?code=9360&size=l&url=$Db_url\" width='300px' height='200px' alt='Thumbnail for $title_sht'>
Now, I want to save this image locally so I tried this:

Expand|Select|Wrap|Line Numbers
  1. $image_data = file_get_contents("http://snapcasa.com/get.aspx?code=9360&size=l&url=$Db_url");
  2. file_put_contents($image_file, $image_data);
  3.  
When I do the above I don't get the real image returned but only their
default "Unregister ed Domain" image.

This maybe an anti-hammer reaction because of the quick succession of my image requests.

So since I already have the image displayed using the <img src=
tag, is there a way to save this image locally ?

If not, maybe I should use the file_get_conten ts() function to get the image data in the first place ?

Would appreciate any input on this :)



.
Mar 8 '10 #1
6 3450
Atli
5,058 Recognized Expert Expert
Hey.

When you use the file_get_conten ts function, are you displaying the image in the <img> tag using the remote URL, or the local URL?

It should be something like:
Expand|Select|Wrap|Line Numbers
  1. $url = "http://snapcasa.com/get.aspx?code=9360&size=l&url=$Db_url";
  2. $image_data = file_get_contents($url);
  3. file_put_contents($image_file, $image_data);
  4. echo "<img src='{$image_file}'  width='300px' height='200px' alt='Thumbnail for {$title_sht}'>";
And be sure that the image URL is in fact what it should be. (Just print it before using it, to see if it is all OK.)
Mar 8 '10 #2
jeddiki
290 Contributor
Hi Atli,

Thanks for your reply.

The way you did it is more logical as it requires only one call.

But for some reason the snapcasa.com site still does not accept
it.

I think their delivery script checks that my script or <img> tag
is coming from a website domain that I have registered with them.

I have registered my domain and IP address with them.

Maybe when I use the file_get_conten ts($url) method, it is anonymous and
therefore only gets back their "Unregister ed Domain" image - not the image that I want.

When I use the <img> tag with their address in it,
it works fine.

Any more ideas on how I can save the image ?

In theory it should possible to save the image after I have got it
and served it to my website - after all it is in my server's memory.

Just to recap - this works:
Expand|Select|Wrap|Line Numbers
  1. <img src=\"http://snapcasa.com/get.aspx?code=9360&size=l&url=$Db_url\" width='300px' height='200px' alt='Thumbnail for $title_sht'>


But this doesn't :

Expand|Select|Wrap|Line Numbers
  1. $url = "http://snapcasa.com/get.aspx?code=9360&size=l&url=$Db_url";
  2. $image_data = file_get_contents($url);
  3. file_put_contents($image_file, $image_data);
  4. echo "<img src=\"$image_file\"  width='300px' height='200px' alt='Please wait while thumbnail loads ...'>";
  5.  

And by "doesn't work" I mean that it does return an image, but not the one requested,
it delivers a standard "Unregister ed Domain" image.


Thanks.



.
Mar 9 '10 #3
Atli
5,058 Recognized Expert Expert
I think their delivery script checks that my script or <img> tag
is coming from a website domain that I have registered with them. [...]
Maybe when I use the file_get_conten ts($url) method, it is anonymous and
therefore only gets back their "Unregister ed Domain" image - not the image that I want.
That should not be the case. If the <img> tag version is meant to work on more than a single compute (which I assume it is?) then checking where the request is coming from and denying access based on that makes no sense. - It's the browser that requests the image, not the server, so that each person visiting your website would be requesting the image from a different, usually domain-less, IP address.

It's far more likely that the URL you use in your script is somehow malformed.
In your last example, before you call the file_get_conten ts() function, have you defined the $Db_url variable? If so, are you sure it is valid? - Try printing the $url, just to make sure it is as you expect it to be.
Mar 9 '10 #4
jeddiki
290 Contributor
Hi Atli,

I have now changed the code to display the
url and then afterwards use the url in the img tag.

Like this:

Expand|Select|Wrap|Line Numbers
  1. $url = "http://snapcasa.com/get.aspx?code=9360&size=l&url=$Db_url";
  2. $image_data = file_get_contents($url);
  3. file_put_contents($image_file, $image_data);
  4. echo "<img src=\"$image_file\"  width='300px' height='200px' alt='Please wait while thumbnail loads ...'>
  5. <br>
  6. <br><br>The Paydotcom Product Code: $Db_prod
  7. <br><br>Image Url: $url
  8. <br><br>
  9. <img src=\"$url\"  width='300px' height='200px' alt='Please wait while thumbnail loads ...'>
  10. <br><br>
  11. <span style = \"font-size:18px; color:darkblue;\"><b>Customer Payments Schedule:<br>$price</b></span>
  12.  
I think it proves that the url is fine:

The result can be seen for yourself:

Test Page

You will see the file_get_conten ts function attempt
in a box with just the ALT showing followed by the immage using the
same url but in the img tag.

I hope you can see a fault with my script ;-)

If not, how else can I save the file ?


Thanks for your help.



.
Mar 9 '10 #5
jeddiki
290 Contributor
Any more suggestions on this one ...


I am still stuck :(


.
Mar 10 '10 #6
philipwayne
50 New Member
Just read the file contents and write them to your own file.

Expand|Select|Wrap|Line Numbers
  1. $fh = fopen( "http://snapcasa.com/get.aspx?code=9360&size=l&url=$Db_url", "rb" );
  2. $fh2 = fopen( "myimage.img", "w" );
  3. while( ( $content = fread( $fh, 1024 ) ) )
  4. {
  5. fwrite( $fh2, $content );
  6. }
  7. fclose( $fh );
  8. fclose( $fh2 );
  9.  
Note: allow_url_fopen must be turned on for the above code to work.
Mar 16 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
626
by: F. Hall | last post by:
If I read a bitmap image from one file and save it to another the save operation is slow unless I draw on the image. In other words, Image inputImage = Image.FromFile( @"c:\temp\source.bmp" ); using ( Graphics g = Graphics.FromImage( inputImage ) ) { g.DrawLine( new Pen(Brushes.White), 0, 0, 1, 1 ); } inputImage.Save( @"c:\temp\sink.bmp", ImageFormat.Bmp );
5
4041
by: George | last post by:
This program need to draw the some triangles into a 512 × 512 buffer (in memory). Or save it to a file. #include "project3.h" Image::Image(int xres, int yres): xres(xres), yres(yres) { image =new Color*; for (int i=0;i<yres;i++)
9
2644
by: Mark Johnson | last post by:
How can you save all or a portion of the Grafics object to a Image/Bitmap ? I am try to save the Images from Cards.dll to a BitMap file. I can read in the Images to the Grafics, but when I try this with a Bitmap the results are Black. Can you somehow Clip the Grafic and Paste it into the Bitmap ? Mark Johnson, Berlin Germany mj10777@mj10777.de
1
4351
by: Sam Jost | last post by:
Bitmap.Save() does crash very often on Saving jpg's. It seems to dislike pictures on a random basis, but when it dislikes a picture there is no way around it. Take for example the picture http://home.foni.net/~sjost/fremd/IMGP5753-2.JPG I load the picture, and save it rotated by 270 degree. Works like charm: public void Rotate270AndSaveTest()
0
4142
by: prakash | last post by:
Dear Friends I am new guy to Visual C++.NET I've program to save website as a image vc++.net . It have a function "SaveSnapshot" to save the webpage as an image On that function ifor saving as a image it uses image.Save method() This image.Save function have two overloaded form's first one is file name
1
4171
by: Hardy Wang | last post by:
Hi, I found a piece of code to add drop shadow to a photo like below, after I save the image, it is actually a BMP file even though I specify a JPG file extension (see http://img140.imageshack.us/my.php?image=resized11wz.jpg). If I force to save in JPG format (see the commented line), then the whole shadow is a messup (see http://img70.imageshack.us/my.php?image=resized29cy.jpg). I am just wandering are there any attributes / formats...
2
2651
by: Ada | last post by:
First of all, I thought this might be a directory security issue but it's not. I was able to upload the file to the directory via HTTP. Here's the situation. I have a JPG file on my server. ..../images/myPIC.jpg I wanted to draw a box or line using GDI+ on top of myPIC.jpg and then save the new image to the server.
1
6826
by: liuliuliu | last post by:
hi -- sorry if this is trivial -- but how do you make a screenshot of a pygame display? i have a surface which is basically the entire visible screen -- how do you write this surface as an image file during specific events in the script execution? image format doesnt matter. thanks! christine
1
3456
by: Stedak | last post by:
I have the following class I use to save Tiff's. The problem I have with it is that the final size of the images are very large. If we scan directly to a file the final tiff may be 600-900 kb.s but with this code it is often 4000-5000 kb.s. What am I missing? public class EmrTiff : IDisposable { private string fileName; private ArrayList imageContainer = null;
0
2045
by: crazyyellowguy | last post by:
hi, This is my first post in this forum and I just wanted to thank you for even taking a look at my post. The class that I am writing the C code for is my first computer class and my knowledge is limited to what was taught in lectures. Right now I am making a GUI code and am having trouble saving the image after it has been altered. As of now, the only way that I know how to save is to save over the original picture, but that doesn't even...
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3532
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.