htm to jpeg setup?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
pctechtv
Posts: 22
Joined: 2016-10-09T19:47:59-07:00
Authentication code: 1151

htm to jpeg setup?

Post by pctechtv »

I am trying to understand the way to get html2ps set up to convert an htm page to jpeg. I have downloaded and installed a Perl package, and I have the html2ps folder unzipped. It seems like the instruction just say, open the html2ps.html file in a browser. Could someone explain more how to set this up, so ImageMagick has what it needs to do this type of conversion. Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: htm to jpeg setup?

Post by fmw42 »

pctechtv
Posts: 22
Joined: 2016-10-09T19:47:59-07:00
Authentication code: 1151

Re: htm to jpeg setup?

Post by pctechtv »

Hi, I got it working. I think... what is produced in the ps file is only text based. I know a little about post script from my printing days and this makes sense. I am only going to see that type of output?... correct? I was misleading myself thinking that I would see an screenshot of the html page. Is there anyway to produce more of a screenshot? Thanks
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: htm to jpeg setup?

Post by Bonzo »

I have not tried this lately but it used to work for me:

Code: Select all

<?php
// Need to modify the crop width to remove a vertical scroll bar if its in the image !
$url = array( 'site1.info', 'site2.com', 'site3.com', 'site4.co.uk', 'site5.info');

foreach( $url as $value ){
	
$site = "http://www.".$value;

$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Navigate("$site");
// Still working?
while ($browser->Busy) {com_message_pump(4000);
}$im = imagegrabwindow($handle, 0);
$browser->Quit();
imagepng($im, "temp.png");
imagedestroy($im);

// Crop browser window, resize and save image
$width = '1180';
$height = '872';
$x_offset = '10';
$y_offset = '157';
$qulity = '100';

exec("convert temp.png -crop {$width}x{$height}+{$x_offset}+{$y_offset} -resize x200 $qulity $value.jpg");
	echo "<img src=\"$value.jpg\">";
}
?>  
The result depends on what the site is like. In my code I do a crop but some sites have side bars and the page may go below the "fold". From memory animations gave some problems as well.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: htm to jpeg setup?

Post by snibgo »

Is there anyway to produce more of a screenshot?
To get a raster image of a web page (local or URL), http://wkhtmltopdf.org/downloads.html seems to do the job without fuss.

You can specify the height you want (to get just the top "screenfull") or no height to get the entire page.

You can make a delegate.xml entry to use it from within IM. This works fine when the web page is local, but I haven't figured how to make it work from the internet. We can just wget the page first, of course.
snibgo's IM pages: im.snibgo.com
pctechtv
Posts: 22
Joined: 2016-10-09T19:47:59-07:00
Authentication code: 1151

Re: htm to jpeg setup?

Post by pctechtv »

Thanks guys really great and considerate. I hope I can make good contributions to this great forum once I learn more about ImageMagick. @Bonzo Thank you, what is good is that PHP is a language I am very proficient with. @snibgo I am checking out it looks really cool. Your advice is super helpful. @fmw42 thank you as well. Thanks
Post Reply