Jump to content

Saving a dynamically generated image from an HTML file


cmiddlebrook

Recommended Posts

I'm using the cURL library to grab some information from a webpage. On a particular site there is an image on the page that i'd like to save to a file but the trouble is, that image is dynamically generated every time. The code contained in the HTML page is as follows:

 

<img src="http://domain.com/branch/" id="graphic" />

 

(I've changed the real URL). So the URL http://domain.com/branch/ resolved to an actual image file. If I put this in my address bar I get an image file that I can save. So far so good, but I want to grab the image that was contained on the main page that I am looking at - which already has a generated image inside of the img tag. If I go directly to the URL that generates it I get a different image - not the same one.

 

Any ideas?

 

Thanks,

Caroline

Link to comment
Share on other sites

Not sure that's possible in the method you are trying to use, I may be wrong. But it's easier to just recreate the image programmically then to try and pick off a site... now if you want the same dynamic image as is on that page (ie it changes often dynamically) then you'd run a script to recreate it the same as it is being created on that page... or at least have the first page store the instance it used to create it then recreate it using the same instance variables.

Link to comment
Share on other sites

I meant somehow saving the variables that are attached to the generation of the image someplace... could be in hidden fields on the page if you want to read the page. Or if sent direclty to another page send it in an array using sessions to create it on another page... a bit beyond my skills so this is speculation really. But maybe it's a start somehow

Link to comment
Share on other sites

Unfortunately there are no variables. The domains I'm stuck on are ones that use just a plain URL with no variables to generate an image. Presumably it's a PHP (or similar) file that has some randomisation built in so that every time you visit that url, a new image is generated.

Link to comment
Share on other sites

What exactly are you trying to do again... & why? I don't see why you'd need to do something like this

 

EDIT:

I mean if I understand why may be able to figure something else out or someone with the exact know how may answer if we know exactly why and what you are doing with it...

Link to comment
Share on other sites

I'm trying to grab a captcha image so that I can then pass it to the user to solve, which is why I need to get the exact image that is generated first time around. The code simply does a file_get_contents() on the URL that generates the image and then I save the output of that to a file. The actual saving of the image works... but its the wrong image - the problem is that when I access the URL that generates the image, it is different to the one on the host page.

 

Caroline

Link to comment
Share on other sites

Ah I see okay... It's different because at every instance you access the site it creates a new dynamic image so file_get_contents() will not work because the server sees the url access as a new request every time thus giving you the wrong image. You would need to have the info the host page used to create the image then. If you don't have access to that then I don't think it's possible.... But now I would really like to know how to solve this if it is though. Devil? any ideas?

Link to comment
Share on other sites

Yup that's exactly right. I can't see a way of solving it using the method I'm trying now. But I'm wondering if there is another way of saving the image that has been displayed. It's already rendered in the browser so I wonder if there is a way of telling the browser to save the image that is there without re-accessing the URL that generates it - some kind of caching solution perhaps?

 

I guess these captchas are doing their jobs well as they prevent us pesky programmers from solving them lol! :-)

 

Caroline

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.