I'm building a complex content-management system for delivering selected content to Palm handheld devices, and I've run into a problem which may not be possible with given tools, so I'm soliciting some ideas..

What I've done so far, is capture about 885 different URLs of content that users have been using, and stored the url, name, etc. in a database. Nothing magical there. When the user wants to select some content to convert for their Palm, they pick from a list of sites in the database, and are shown a "preview" of what it might look like when it gets onto their handheld in our application.

The problem with the approach I'm using, currently an iframe as shown in the first code snippet below, is that our list of "previews" is subject to whatever HTML the remote site we're pointing to for the iframe decides they want to use, including any broken HTML, maliscious HTML or javascript, meta-refresh tags, popups, and other noise.

# The URL itself is queried from the database above here, # but that isn't important for this particular explanation # # The URL itself is stored in $url_uri from bind_col() while ($sth->fetch) { my $substr_url_uri; $substr_url_uri = length ($url_uri) > 60 ? substr($url_uri,0,60) . "..." : $url_uri; print br(), "\n"x3, start_div({-class=>'urlbox'}), span({-class=>'urlinfo'}, b("$url_name"), br(), br(), "Current category:", start_span({-class=>'catname'}), $category_name, end_span(), br()x2, start_span({-class=>'catlist'}), "Move to new category:", br(), popup_menu("category", \@categories), end_span(), ), end_div(), start_div({-class=>'urlprev'}), start_iframe({-src => "$url_uri", -width => '170', -height => '170', -scrolling => 'no', -marginwidth => '1', -marginheight => '1', -frameborder => '0',}), end_iframe, end_div(), } $sth->finish;

Obviously this presents a problem when we have a really nice looking interface for the previews, similar to those in this screenshot.

What I'm wondering, is if it is possible to take a screenshot of the content on the remote site, in the same 160x160 window, and present that screenshot to the user in the preview, instead of an iframe pointing directly at the live, remote (raw) content? I know I can fetch the content with LWP::UserAgent, using the following (working) snippet:

sub fetch_url { my $url_uri = shift; my $ua = LWP::UserAgent->new; $ua->agent('Mozilla/3.0'); my $url = "$url_uri"; my $request = HTTP::Request->new(GET => $url); my $response = $ua->request($request); # Content itself is in $response->content; here. return $response->content; }

Using an image, however, presents us with a few good advantages:

I can also use LWP::Simple's getstore() function or fetch the content and store it in a local file directly using the snippet above, such as:

open(CONTENT, ">content.$$") or die $! print CONTENT $response->content; close CONTENT;
I'd rather stay away from that for a few reasons:

So the question is, does there exist a way to do this programatically?

Is it possible to print the content stored in $response->content; above and create an image out of the contents?

Can I jam the content into some sort of postscript filter, and then print that to an image?

Is there some merlyn column on exactly this topic somewhere on stonehenge?

Has anyone done anything remotely similar to this?


In reply to Automated Screenshot Grabbing via LWP? by hacker

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.