Using WebSwoon thumbnails in a PHP script - Mini-Tutorial
Here is a little tutorial to help you if you want to add thumbnails on your web site, in order to display web site previews on a listing web page for example.
1) Get the web sites list
The first step is to get a list of the web sites needing thumbnails. In WebSwoon
you can edit the web sites list to be captured by hand, but you can also import it
from a text file. If your web sites data are saved in a database, you just have to export
the list of the urls to a text file and import it in WebSwoon. For example make a
"SELECT website_url FROM websites" and save the results in mylist.txt. Import this
mylist.txt file in Webswoon overwriting the current web sites.You can also directly copy the SQL results and paste them directly in the "websites_list.txt" file which is in the program installation folder (should be "c:\program files\webswoon" by default). You must have one url on each line.
2) Make the captures
You can then launch WebSwoon normally and start the captures. All websites thumbnails
will be saved in the specified folder in configuration window (should be
c:\program files\webswoon\captures by default) and existing thumbnails will be overwritten
according to the selected program options.3) Upload the captures to your web site
When all the websites captures are finished, you have to upload them on your web
site in order to be able to use them on your web pages. Use any FTP client and upload
all thumbnails from the capture folder (should be c:\program files\webswoon\captures
by default) to a dedicated folder on your web site ("captures" for example).4) Display the captures with your PHP script
Now if you need to display the thumbnail beside a web site description for example,
you can use a PHP script like this one. Note that you will need to convert some characters
in the original URL in order to get the thumbnail file name saved by WebSwoon.
(...)
// fix bad characters like webswoon
function getfilename($url) {
$badchars = array('\\', '/', ':', '?', '~', '&', '=', '<', '>', ',', '#', '%2C');
return(str_replace($badchars, '_', $url));
}
// display web sites with thumbnails
$query = "SELECT website_title, website_desc, website_url FROM websites ORDER BY website_title ASC";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$path = getfilename($row['website_url']);
print ("<img src=\"captures/" . $path . ".jpg\" align=\"left\">");
print ("<a href=\"" . $row['website_url'] . "\">" . $row['website_title'] . "</a><br>\n" . $row['website_desc'] . "<br clear=\"all\">\n");
}
(...)
5) That's it !
Of course this is a minimalist example, but it should help you to start
using thumbnails generated by WebSwoon.Please take the time to read the program documentation to get more information about all WebSwoon capabilities.