This Mod displays thumbs of images similar to the choosen one on the details page. Similarity is recognized by text-comparison of image keywords (or image description, if one likes better). From the whole set of similar picture a randomized subset is selected to be displayed. You can configure this number of displayed thumbs.
NoteThis Mod uses metadata of the images to find similar pics. It just takes e.g. the keywords of the image displayed on the details page and performes a text-comparison via php function "similar_text()". That means, if your metadata does not properly describe your images in a consist and structural way, the result will not be satisfyingly.
You must fit some variables of this mod to your gallerys image data. The best way to to this is still to vary variables value and look at the results.
For example:
similar_text() calculates similarity of two strings by setting a defined variable at 0 to 100, where 0 means no and 100 complete similarity.
Therefor in this Mod "$percent_limit = 80; " is the value that devides similar images from non-similar. Descending the value results more similar images and vice versa.
In this Mod I use only a part of 50 letters of the compared metadata. This is because in my database the first keywords contains the most relevant information. So if one image has 20 keywords and a real similar image only 5, text-comparison will result a low similarity. If I use only the first keywords for comparison, comparison will fit much better.
Vary the number of letters in the substr()-function or remove this function to use the whole metadata.
AcknowledgmentThis Mod is based on Mod Random pictures by V@tno
http://www.4homepages.de/forum/index.php?topic=4259.msg17513#msg17513 Files affected[change] details.php
[change] lang/english/main.php
[change] lang/yourlanguage/main.php
[change] templates/default/details.html
open details.php, locate
//-----------------------------------------------------
//--- Show Image --------------------------------------
//-----------------------------------------------------insert before//------------------------------------
//------- MOD Similar Images
//------------------------------------
$image_keywords = substr($image_row['image_keywords'], 0, 50); //keywords of actual image
$image_description = $image_row['image_description']; //description of actual image
$image_id_self = $image_row['image_id']; //id of actual image
$i_ids = 0;
$i_ids_max = 4; //max number of thumbs displayed
$image_ids = "";
$percent_limit = 80; //limit of similarity; vary to fit to your database!
$percent_minimum = 40; //minimum of similarity; vary to fit to your database!
//-- select all images and identify similar images
//-- write a string $image_ids with the set of id's, comma seperated
//-- if there are no similar images, descend $percent_limit and try once more
$sql = "SELECT image_id, image_name, image_description, image_keywords, image_active
FROM ".IMAGES_TABLE."
WHERE image_active = 1";
$result_allimages = $site_db->query($sql);
while (($i_ids == 0) && ($percent_limit > $percent_minimum)) {
while ($image_row_allimages = $site_db->fetch_array($result_allimages)){
similar_text ( $image_keywords, substr($image_row_allimages['image_keywords'], 0, 50), $percent );
// similar_text ( $image_description, substr($image_row_allimages['image_description'], 0, 50), $percent );
if (($percent > $percent_limit) && ($image_row_allimages['image_id'] != $image_id_self)) {
$i_ids = $i_ids + 1;
$image_ids .= $image_row_allimages['image_id'] . ", ";
}
}
$percent_limit = $percent_limit - 5;
}
//-- remove the last comma in $image_ids
if (strlen($image_ids) > 0) {
$image_ids = substr($image_ids, 0, strlen($image_ids)-2);
}
//-- set $i_ids to its maximum, for correct mysql statement below
if ($i_ids > 4) $i_ids = $i_ids_max;
//-- build table with thumbs of similar images (only if there are some, of course)
if ($i_ids == 0) {
$similar_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
$similar_images .= "</td></tr></table>";
}
else {
//---- select similar images, there id's are in the set $image_ids now
//---- randomized and limited
$sql = "SELECT *
FROM ".IMAGES_TABLE."
WHERE image_id IN (" . $image_ids . ")
ORDER BY RAND()
LIMIT ".$i_ids;
$result_similarimages = $site_db->query($sql);
$num_rows_similarimages = $site_db->get_numrows($result_similarimages);
//---- build table and table-cells
if (!$num_rows_similarimages) {
$similar_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
$similar_images .= "</td></tr></table>";
}
else {
$similar_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
$count = 0;
$bgcounter = 0;
while ($image_row_similarimages = $site_db->fetch_array($result_similarimages)){
if ($count == 0) {
$row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
$similar_images .= "<tr class=\"imagerow".$row_bg_number."\">\n";
}
$similar_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";
show_image($image_row_similarimages);
$similar_images .= $site_template->parse_template("thumbnail_bit");
$similar_images .= "\n</td>\n";
$count++;
if ($count == $config['image_cells']) {
$similar_images .= "</tr>\n";
$count = 0;
}
}
if ($count > 0) {
$leftover = ($config['image_cells'] - $count);
if ($leftover >= 1) {
for ($f = 0; $f < $leftover; $f++) {
$similar_images .= "<td width=\"".$imgtable_width."\">\n \n</td>\n";
}
$similar_images .= "</tr>\n";
}
}
$similar_images .= "</table>\n";
}
}
//-- register template-keys
$site_template->register_vars(array(
"similar_images" => $similar_images,
"lang_similar_images" => $lang['lang_similar_images']
));
unset($similar_images);
//------- End similar images---------
//------------------------------------open lang/english/main.phpinsert at the bottom (
before ?>)
//-----------------------------------------------------
//--- MOD similar pictures dp
//-----------------------------------------------------
$lang['lang_similar_images'] = "similar images";open lang/yourlanguage/main.phpinsert at the bottom (
before ?>)
//-----------------------------------------------------
//--- MOD similar pictures dp
//-----------------------------------------------------
$lang['lang_similar_images'] = "translation of "similar images"";open templates/default/details.htmlplace {lang_similar_images} and {similar_images} were ever you want to display the table of thumbs with similar images