-3

Can anybody tell me, how can I get image for a particular site by its url only? As that is done on the google search page. I have searched web but I didn't get any satisfactory ans.

Soumalya Banerjee
  • 1,966
  • 3
  • 22
  • 28
  • 2
    I think this question is similar, just regarding php though: http://stackoverflow.com/questions/757675/website-screenshots-using-php – The Coding Monk Nov 03 '11 at 11:49
  • Please be more specific as to what you would like to accomplice, – NitWit Nov 03 '11 at 11:49
  • Do you want screenshot of page or a direct image ? – Riz Nov 03 '11 at 11:51
  • Are you trying to copy an image from a URL? Or take a screenshot of the URL and return an image? You need to be more clear what you are looking for. – Nick Nov 03 '11 at 11:55

5 Answers5

1

I'm Not Experience Developer so i just try This Code can fetch only first image

<?php
$url = 'http://stackoverflow.com/questions/7994340/how-can-i-get-image-from-url-in-php-or-jquery-or-in-both';
$data = file_get_contents($url);

if(strpos($data,"<img"))
{
    $imgpart1 = explode('<img src=',$data);
    $imgpart2 = explode('"',$imgpart1[1]);
    echo "<img src=".$imgpart2[1]." />";
}
?>
Mohit Bumb
  • 2,466
  • 5
  • 33
  • 52
0

You will use to simplehtmldom. It is very useful to you. you can get the data and images.

j0k
  • 22,600
  • 28
  • 79
  • 90
  • Dear,Ravindren. You shouldn't just give a link to another site as an answer, since the site may go out of date in the future. Instead, click the "edit" link on this answer and include the essential parts of the solution from that page here. [See this please](http://meta.stackexchange.com/q/8259) – osyan Oct 11 '12 at 12:03
0

Get the page with file_get_contents($url) then you can parse the content and download the images and store it at your server:

$url = 'http://example.com/image.php';
$img = '/my/folder/flower.gif';
file_put_contents($img, file_get_contents($url));

See this related Question.

Update: To get the image you could use SimpleXMLElement:

$obj = new SimpleXMLElement($htmlCode);
$url = $obj->body->img->src;
Community
  • 1
  • 1
PiTheNumber
  • 22,828
  • 17
  • 107
  • 180
  • Buddy, u did not get my problem, as may be I couldn't be clear while asking. I am looking for a code, where I can get a screenshot of a webpage, by its url. Anyways, thank u buddy... – Soumalya Banerjee Nov 15 '11 at 10:12
0

I would suggest that you make an http request to the page then you make a regular expression on the response to get the src attribute vale of img tag.

Samir Adel
  • 2,691
  • 2
  • 15
  • 16
  • I want a screenshot of particular webpage by its url. And Thanks to @Jack Duluoz as he gave me a link, containing similar posts. I got my answer. Thank u guys.... – Soumalya Banerjee Nov 15 '11 at 10:10
0

If you mean that you want to download a JPG/PNG/etc image from a URL then this PHP will do it:

file_put_contents('image',file_get_contents('http://www.benjiegillam.com/files/img/eye-150.jpg'));

If you mean that you want to take a screenshot of a remote web page then have a look at PhantomJS - see a previous answer of mine here: get webpage print screen, php/unix

Community
  • 1
  • 1
Benjie
  • 7,701
  • 5
  • 29
  • 44