View Full Version : Thumbnail images (only in special cases)

12-08-2003, 07:18 AM
If you are using PhpDig on a site that you have complete control over (e.g. your own site), and if you have or if you can make a thumbnail image for many pages that are indexed, then you might be interested in search results that also show these thumbnail images.

Are you? If so, please tell me in a reply to this thread. I have a little piece of code to get search results with thumbnails on the side and I'll share it if someone is interested.

12-08-2003, 09:08 AM
I am curious to see you thumbnail code. Is it a 'picture' of a text file that you are talking about? I am interrested in how GD works, and I would like to see what you have done.

12-08-2003, 07:23 PM
same here

12-10-2003, 01:05 AM
Bear with me, the code change to show thumbnail images requires a little bit of explanation.

Say you're using PhpDig to index "http://ownsite/". The pages contain links like "http://ownsite/dir/some.html". PhpDig finds these links and indexes the corresponding pages.
You also have thumbnail images that represent your HTML pages in some way, for example "some_t.jpg" for "some.html"; you store these thumbnail images in the same directory as the page, so our sample thumbnail is reachable via url "http://ownsite/dir/some_t.jpg".

Note that I am not addressing the issue of how to produce "some_t.jpg". I am assuming that it exists. Also, the code below assumes the thumbnail to be in the same directory as the HTML page, but this requirement can be relaxed.

If a search finds the HTML page, you want to display the thumbnail.
You must indicate in the search template where you want the thumbnail to appear, e.g. by inserting some directive like "<phpdig:thumbnail/>". I am assuming that you have looked at templates and that you understand how they work.
On second thoughts, it is nice that people can click on the thumbnail to get to the page. So the thumbnail <IMG> must be included in an <A> element.
It so happens that we already have a phpdig template directive to insert a clickable image; if the link must be to the found page, it is of the form: "<phpdig:complete_path src='xxx'/>".
Only we cannot put a fixed source, as the source depends on the page that is found. We'll come back to the template directive later.

Meanwhile, I'll tell you about the code for the template formatting. That is where you'll have to do a PHP code change.
Open libs/function_phpdig_form.php, locate function phpdigParseTags. There is a line:
$replacement = '<a href="'.$t_strings[$regs[1]].'"'.$target.'><img src="'.$regs[3].'" border="0" align="bottom" alt="" /></a>';
Insert the following code just before that line:
if (substr($regs[3], 0, 8) == "nothumb/")
if (ereg("[a-zA-Z0-9.?&=_-]+thumb=", $t_strings[$regs[1]]))
$regs[3] = ereg_replace("[a-zA-Z0-9.?&=_-]+thumb=", "", $t_strings[$regs[1]]);
$regs[3] = substr($regs[3], 8);

The most important piece here is the regular expression "[a-zA-Z0-9.?&=_-]+thumb=". It looks in the URL of the found page, e.g. "http://ownsite/dir/some.html" and expects to find "thumb=" somewhere in that URL.
Now here is the trick that I have used to make this code do what I want it to do: in my "http://ownsite/", the URLs pointing to other pages are not just ordinary URLs but URLs with an extra little tail.
For example, you'll find hyperlinks like "<a href='http://ownsite/dir/some.html?thumb=some_t.jpg'>Next page</a>".
For clicking from page to page, the "?thumb=xxx" tail is ignored. But when PhpDig comes along, it stores the complete URL, including the "?thumb=xxx" tail, in its database.
So, when later a search finds this page, "<phpdig:complete_path/>" will include the tail and the regular expression will find it. The "ereg_replace" then just manufactures an URL for the thumbnail image.

One final addition is about the template directive "<phpdig:complete_path src='xxx'/>". It must clearly express that it is used here for thumbnails, not for something else. So for example, we could have " src='thumbnail' " as a special placeholder. (Remember, the thumbnail URL is dynamic, we cannot plug a static one here.)
There will be pages that have no thumbnail, i.e. some page URLs in my site will still be like "http://ownsite/dir/some.html" with no "?thumb=xxx" tail. As I now have a template that is longing for inserting a clickable image, I have to provide a "by default" image.
This "by default" image will be in my PhpDig directory, not in the indexed site. Say we use "tpl_img/cprgo.gif" as default image.
The template directive therefore is not only a special placeholder, but at the same time tells PhpDig which image to use for found pages that have no corresponding thumbnail image. Here is the template directive that I use:
<phpdig:complete_path src="nothumb/tpl_img/cprgo.gif"/>
The "nothumb/" part tells the above code that this is the special placeholder. Any relative path can be provided after the "nothumb/" part, to point to the default thumbnail image.

There, I've said it! I hope you're still with me...

The thumbnail trick works, I've tried it out. In the site that I want to index, many pages have a corresponding thumbnail.
The above code is still somewhat rigid, it wants the thumbnail image to be alongside the HTML page. This serves my need perfectly.
If you want the thumbnails to be somewhere else, no doubt you'll see a way to implement it by adapting the above code somewhat.

12-10-2003, 07:39 AM
Nice idea. I will have to try that sometime. Thanks for the reply. Do you have a simple way that you use to produce thumbnails for html pages?

12-10-2003, 11:19 PM
Not an automatic one...

Browse to the page, Alt/PrintScreen, open your favorite image tool (mine is IrfanView), paste, crop, resize, save as JPEG:

The site that I want to index mainly contains digital photos, so I use thumbnails of the photos, not of the web pages...

12-11-2003, 06:19 AM
Some of what I would like to index would be for a general document store, and I thought that thumbnails of the front page of an open office, html, or txt page would be neat, but I need to find someway to perform that action with out a printscreen. (I think KDE has something like that now that I think about it.)

What exactualy do you index if you are indexing images? Do you have some type of meta data that gets indexed, or is it just the file name that gets indexed?

12-11-2003, 10:48 PM
When it's just a directory with images, we add IEEE 1484 type metadata in an XML file.

For teaching purposes, images are often put in PPT presentations, and I am developing a (client-side) script to extract metadata from a PPT file to store it in an XML file.

02-13-2004, 01:10 AM
If you are interested in seeing a small example of a website containing mainly images, send me an e-mail mentioning the institution that you are working for and its website.

PhpDig 1.8.0 has been customized in that website to show thumbnails with the search results. The search window contains a tree structure with keywords that have been used to describe the images.

We are also developing tools that facilitate the description of images and presentation slides by keywords etc. These developments are funded by the Flemish Government (Belgium). The website is "hosted" by the eLearning platform Claroline.

05-25-2004, 01:08 PM

Personnaly, I use the AscreeN technologie for PhpDig.
http://moteur.pointdecroix.org/ascreen.php (In french)

See also http://www.apocalx.com/ascreen/

09-09-2004, 01:13 AM
The little website with images has been updated to PhpDig 1.8.3 and eLearning platform Dokeos 1.5.4, and has been completely reworked behind the scenes.

You can have a look on cordoba.ugent.be/dokeos/VELODLA/
Click on 'Zoeken met PhpDig'.

Cordoba is my desktop PC and it is usually up and running monday 9 am thru thursday 5 pm (Brussels time), not on friday, saturday and sunday.

With 'Zoeken via metadata' the search is slower, PhpDig is not used then.

For more info, e-mail me.