heron
heron

Reputation: 3661

Get image source from given URL with javascript or PHP

What I want to do is following:

  1. User takes screenshot with the application like jing. ok!
  2. Pastes link that Jing returned back. ok!
  3. Server processes the link that user entered, and extracts images source url. But, I have no idea how server will get "clean" image source URL. For example, this is the link that Jing returned after sharing screenshot http://screencast.com/t/zxBzNNkcg but real url of image looks like http://content.screencast.com/users/TT13/folders/Jing/media/c25ec5c6-bc6a-413c-a50b-ada95fac4ed2/2012-07-25_0221.png
  4. Server returns back image source URL. no idea!

Is there any possible way to get image url with Javascript or PHP?

Upvotes: 0

Views: 1623

Answers (4)

Eric Dorsey
Eric Dorsey

Reputation: 391

Javascript answer:

Will the output image always have the same class, embeddedObject?

If so, how about something like:

myVar = document.getElementsByClassName('embeddedObject');
myVar[0].getAttribute("src");

The myVar[0] reference of course assumes that there is only ever one image on the page with the embeddedObject class, otherwise you'd need to sort, or know which index to reference each time.

Also, this sadly doesn't seem to be supported in IE8 (which browser do you need to support?): http://caniuse.com/getelementsbyclassname

Upvotes: 0

silent_coder14
silent_coder14

Reputation: 583

you could use Simple PHP DOM Parser to retrieve the image from the url without considering the url for as long as it contains and image inside, like so:

foreach($html->find('div[class=div-that-contain-the image]') as $div) {         
        foreach($div->find('img') as $img){     
            echo "<img src='" . $img->src . "'/>";          
        }

    }

That is my solution.

Upvotes: 1

Styles
Styles

Reputation: 524

Yes. If you right click on the image and go Copy Image Location, you'll see it's http://content.screencast.com/users/TT13/folders/Jing/media/c25ec5c6-bc6a-413c-a50b-ada95fac4ed2/2012-07-25_0221.png

If you were to do it programmatically, you would use cURL and simplehtmldom.sourceforge.net to parse the outputed HTML for the actual link.

Upvotes: 0

Michael Robinson
Michael Robinson

Reputation: 29498

You can retrieve the page containing the image using a DOM library like Query Path.

Using that you can extract the URL to the image.

So in your step 3:

  • Get source of shared screenshot page (maybe use file_get_contents)
  • Extract screenshot's image src, using Query Path.
  • Return image src URL to user

Upvotes: 0

Related Questions