Jump to content


Preview webpage in php


16 replies to this topic

#1 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 20 November 2006 - 06:19 AM

Would it be in any way possible to use PHP's image create function to generate a gif or jpeg that is in some way a printscreen of how a webpage will look when you open it (including images)?

Example, A website where users can add their website URL. When it's added, you can see a small preview of the website...

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 20 November 2006 - 01:48 PM

Nope, PHP is not capable of parsing HTML. I don't know how people come up with those little screen shots of others websites, i can only assume they use a more advanced language.

#3 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 20 November 2006 - 05:22 PM

Ya, I have an extention for Firefox called 'ScreenGrab!' that automatically scrolls the page, takes multiple screenshots, and combines them as one image, and saves it. I'm not sure what language it is, I'm guessing some JavaScript, but that could be a start.
Though, of course it would need some way of parsing the page in the first-place... I can't think of any web-based language that could do such a thing. You would have to use VB or C++ or whatever browsers are coded from, and find some way of having it generate an image, save it to the server/database, then have PHP able to grab the image.

I never even thought of how complex such a thing would be until now... I somehow assumed it was much simplier. :wacko:

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 21 November 2006 - 02:27 PM

Since it's an extension in FF, it would most likely not be JS. I'm almost positive it would have to be a browser like program that has an sgml parser (to parse the html/css/what ever, i think that's what they are), then it would do a screen capture and go down hill from there.

#5 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 21 November 2006 - 05:10 PM

Ah well,
it was worth a try :P

#6 Chaos King

    Senior Programmer

  • P2L Staff
  • PipPipPip
  • 676 posts
  • Gender:Male
  • Location:Florida

Posted 23 November 2006 - 08:20 AM

LOL!

This is how it is done. Atleast with my knowledge of trying and research.

The ImageMagick library has a screenshot function which will take a screenshot of the server's current screen. What you do is you is install X-Server which is a linux gui and then and then install Gnome or KDE to install the firefox browser. Thats as far as I got, I had to stop because my box's display card wasn't supported by my OS. So there is a lot of things to put into consideration. =/

#7 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 23 November 2006 - 08:29 AM

View PostChaos King, on Nov 23 2006, 02:20 PM, said:

LOL!

This is how it is done. Atleast with my knowledge of trying and research.

The ImageMagick library has a screenshot function which will take a screenshot of the server's current screen. What you do is you is install X-Server which is a linux gui and then and then install Gnome or KDE to install the firefox browser. Thats as far as I got, I had to stop because my box's display card wasn't supported by my OS. So there is a lot of things to put into consideration. =/

Cool that would work nicely, just that i'm on a shared host ^_^
I'm sure Java can parse HTML and maybe even basic CSS but adding the images to the screenshot is going to be the problem I think.

I'll keep looking

#8 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 23 November 2006 - 07:51 PM

That's basically what i was thinking. I just haven't done ANY research into that stuff, so i couldn't come up with any thing that could so much as "technically" work.

#9 Joshimitsu

    Young Padawan

  • Members
  • Pip
  • 13 posts

Posted 25 November 2006 - 05:04 AM

I remember helping my friend do this a while ago. Its a special dll that you install onto a windows server. Then, the windows server uses the ie browser to take screenshots and cache them. I will try to find that dll

#10 PhpFreak

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Interests:Coding

Posted 26 November 2006 - 11:16 AM

I have something similar to what you want but the images don't work for a lot of websites.
I don't think its compatible with CSS eathier.
It's php but it doesn't take a screen shot, it simply grabs the source code and returns it.
If you want, ill post it.

Edited by PhpFreak, 26 November 2006 - 11:17 AM.


#11 dotbart

    Young Padawan

  • Members
  • Pip
  • 141 posts
  • Gender:Male
  • Location:Diepenbeek
  • Interests:Webdesign, Webdeveloppement, DJ, ...

Posted 26 November 2006 - 12:05 PM

View PostPhpFreak, on Nov 26 2006, 05:16 PM, said:

I have something similar to what you want but the images don't work for a lot of websites.
I don't think its compatible with CSS eathier.
It's php but it doesn't take a screen shot, it simply grabs the source code and returns it.
If you want, ill post it.

Does it parse the code aswell (give it in visual form) or is it just the plain source code?

Post t anyway, it's all good :)

Thanks mate

#12 PhpFreak

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Interests:Coding

Posted 26 November 2006 - 01:19 PM

Just plain source code.

when entering the url=http://www.yourdomain.com
You must include http://www. in it or else it will just return a blank webpage for most websites.

<?
function geturl($url){
$source = file_get_contents($url);
return $source;
}
if($_GET['url']){
echo geturl($_GET['url']);
}
else{
echo "Please enter a url, example:<br/>
http://www.thisdomain.com/thisfile.php?url=http://www.msn.com<br/>
Please note: This will only work if you have included http://www. in 

the url.";
}
?>

Edited by PhpFreak, 26 November 2006 - 01:20 PM.


#13 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 26 November 2006 - 01:29 PM

If you were to read what he was asking for you'd plainly see that is not what he is looking for. :)

I still don't have any ideas other than somehow having a server-side script access the page via a browser, then call the screenshot function somehow. So in terms, it would be more like a bot actually.

#14 PhpFreak

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Interests:Coding

Posted 26 November 2006 - 02:05 PM

I know thats not what hes looking for, but similar in a way.
I also explained what it does and gave him a choice to see the code or not, which he accepted.
If it is no use to him then he can scrap it, Theres no harm on giving it a try.

#15 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 26 November 2006 - 02:48 PM

No offense, but what you gave is an extended version of the function file_get_contents

anyway, can't curl do something like this?

#16 PhpFreak

    Young Padawan

  • Members
  • Pip
  • 26 posts
  • Interests:Coding

Posted 26 November 2006 - 03:19 PM

Yeah it is. Its pretty much the closest thing to what he wants that i know of.
Anyone care to correct me?

#17 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 November 2006 - 03:26 PM

I believe Demonslay already corrected you, and on that note, if nobody can actually provide something more concrete than theoretcial ideas (i.e. that dll Josh was talking about), then i believe no further discussion is needed unless dotbart wants something else.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users