• [MOD] similar images 4 0 5 1
Currently:  

Author Topic: [MOD] similar images  (Read 58593 times)

0 Members and 1 Guest are viewing this topic.

Offline dp

  • Newbie
  • *
  • Posts: 37
    • View Profile
[MOD] similar images
« on: January 19, 2010, 03:59:32 PM »
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.

Note
This 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.

Acknowledgment
This 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'], 050); //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_keywordssubstr($image_row_allimages['image_keywords'], 050), $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_ids0strlen($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++ % == 0) ? 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&nbsp;\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.php
insert at the bottom (before ?>)
//-----------------------------------------------------
//--- MOD similar pictures dp
//-----------------------------------------------------
$lang['lang_similar_images'] = "similar images";


open lang/yourlanguage/main.php
insert at the bottom (before ?>)
//-----------------------------------------------------
//--- MOD similar pictures dp
//-----------------------------------------------------
$lang['lang_similar_images'] = "translation of "similar images"";


open templates/default/details.html
place {lang_similar_images} and {similar_images} were ever you want to display the table of thumbs with similar images


Rembrandt

  • Guest
Re: [MOD] similar images
« Reply #1 on: January 19, 2010, 05:42:57 PM »
Hi!

Thank you for sharing this mod.

mfg Andi



« Last Edit: January 20, 2010, 05:55:41 AM by Rembrandt »

Offline Sun Zaza

  • Sr. Member
  • ****
  • Posts: 399
    • View Profile
Re: [MOD] similar images
« Reply #2 on: February 18, 2010, 03:07:50 AM »
Finally a related images for 4images. I did not test yet, but I am very happy with it.
Thank you very much dp :D
Cruxy

Offline coloresonline

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: [MOD] similar images
« Reply #3 on: February 19, 2010, 12:21:46 AM »
Thanks for sharing it. It works perfectly,.  adjusting the values to real related pictures.
Thanks.

Offline GaYan

  • Sr. Member
  • ****
  • Posts: 301
  • ♫ | G2 | ♫
    • View Profile
    • Ziramagic
Re: [MOD] similar images
« Reply #4 on: February 20, 2010, 05:46:52 AM »
Thanks man..its a great mod :) Works Coooooooooooooooooooooooooooooooooooooooooooooooooooooooool  :mrgreen:
I'm Back :)

Offline PSDProtocol

  • Pre-Newbie
  • Posts: 1
    • View Profile
Re: [MOD] similar images
« Reply #5 on: May 05, 2010, 01:10:44 PM »
Works great.  Although the generated images are all saying they are from (Guest) and not the submitter.  How do I fix this or remove that info panel to show just the thumb.

Offline CanonInk

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: [MOD] similar images
« Reply #6 on: May 05, 2010, 02:36:32 PM »
Many thanks !!!

Offline dp

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: [MOD] similar images
« Reply #7 on: May 05, 2010, 04:42:24 PM »
Works great.  Although the generated images are all saying they are from (Guest) and not the submitter.  How do I fix this or remove that info panel to show just the thumb.

The Mod uses the template-file "thumbnail_bit.html" to display the thumbs and their metadata. In this file there is a templatekey {user_name_link} which is registered by the function "show_image()" in include/functions.php. Sorry, but I got no idea, why this template_key has the wrong value.

You can simply take out the templatekey {user_name_link} from thumbnail_bit.html, but this will affect all thumbs in your gallery! A simple solution would be, to copy your thumbnail_bit.html to e.g. thumbnail_bit_similarimages.html and parse this template.

After copying thumbnail_bit.html to thumbnail_bit_similarimages.html find in details.php
Code: [Select]
    $similar_images .= $site_template->parse_template("thumbnail_bit");and change it to
Code: [Select]
    $similar_images .= $site_template->parse_template("thumbnail_bit_similarimages");
Now you got two different templates to display your thumbs and you are free to design them seperately.
Hope this helps!

Offline exceLLency

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: [MOD] similar images
« Reply #8 on: May 07, 2011, 12:04:54 AM »
Thanks for sharing it. It works perfectly

Offline juewei

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: [MOD] similar images
« Reply #9 on: May 09, 2011, 09:11:03 AM »
habe mir das jetzt mal angesehen und auch eingebaut. Leider ohne Erflolg.
Da wir keine keywords  (Schlüsselwörter) zulassen.
Ist es auch möglich anhand der Bildberschreibung?

Offline dp

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: [MOD] similar images
« Reply #10 on: May 09, 2011, 11:28:40 AM »
habe mir das jetzt mal angesehen und auch eingebaut. Leider ohne Erflolg.
Da wir keine keywords  (Schlüsselwörter) zulassen.
Ist es auch möglich anhand der Bildberschreibung?

Nichts einfacher als das! Ist nämlich im Mod schon vorbereitend angelegt ...

ersetze
              similar_text $image_keywordssubstr($image_row_allimages['image_keywords'], 050), $percent );
//              similar_text ( $image_description, substr($image_row_allimages['image_description'], 0, 50), $percent );


durch
//              similar_text ( $image_keywords, substr($image_row_allimages['image_keywords'], 0, 50), $percent );
              
similar_text $image_descriptionsubstr($image_row_allimages['image_description'], 050), $percent );


Offline juewei

  • Full Member
  • ***
  • Posts: 162
    • View Profile
Re: [MOD] similar images
« Reply #11 on: May 09, 2011, 11:36:33 AM »
hast du dich da vertan?
du hast geschrieben, dass ich das eine mit dem anderen ersetzen soll, nur ist ja beides das Gleiche, was du da geschrieben hast, oder?  :wink:

sorry war noch nicht ganz wach!!!!

jezt geht es, Danke

Offline bergblume

  • Sr. Member
  • ****
  • Posts: 463
  • on to the top!
    • View Profile
Re: [MOD] similar images
« Reply #12 on: May 13, 2011, 10:55:03 AM »
coole sache... kleine frage bzgl. erweiterung.. ich habe meine bilder geo-getagged... kann ich mir auch die nächstgelegenen Bilder (laut GPS koordinaten) in einem definierten Umkreis anzeigen lassen? (oder zumindest es so definieren, dass automatisch die fünf nächstgelegenen angezeigt werden?

Offline dp

  • Newbie
  • *
  • Posts: 37
    • View Profile
Re: [MOD] similar images
« Reply #13 on: May 13, 2011, 03:53:20 PM »
coole sache... kleine frage bzgl. erweiterung.. ich habe meine bilder geo-getagged... kann ich mir auch die nächstgelegenen Bilder (laut GPS koordinaten) in einem definierten Umkreis anzeigen lassen? (oder zumindest es so definieren, dass automatisch die fünf nächstgelegenen angezeigt werden?

Das würde ich so machen:
- Abfrage der Felder mit den Koordinaten und ggf. Aufteilung in Länge und Breite
- Schleife, in der diese Koordinaten schrittweise vergrößert/verkleinert werden, und Vergleich mit den Koordniaten der übrigen Datensätze
- Schleife solange durchlaufen bis mindestens 5 weitere Datensätze identifiziert wurden
- Ausgabe der Bilder

Im wesentlichen kann der Aufbau meines Mods dabei so belassen werden.

Nun frag mich aber bitte nicht, ob ich das mal eben programmieren kann  :wink: - dazu habe ich momentan absolut keine Zeit. Wenn du es aber selbst umsetzen solltest, poste doch dein Ergebnis hier im Forum, ggf. auch als eigenes Mod.

UPDATE
Geht natürlich viel einfacher, vorausgesetzt, die Koordinaten für Länge und Breite befinden sich in getrennten Feldern. Dann braucht man die Tabelle nur nacheinander nach Längen- und Breiten-Koordinate sortieren und die jeweils nächsten Werte in beiden Richtungen identifizieren.
« Last Edit: May 14, 2011, 09:18:25 AM by dp »

Offline khansahib

  • Full Member
  • ***
  • Posts: 100
    • View Profile
Re: [MOD] similar images
« Reply #14 on: June 07, 2011, 12:38:09 PM »
Thanks for such a nice MOD.  8)

one request, can we control the number of rows and columns, not from ACP bcoz that changes the whole gallery i want to change number of rows and column for the similar images only..
In my case i've 4 rows with no columns in categories page, but in details page i want to show the similar images in 2 rows and 3 columns.
thanks.
« Last Edit: June 07, 2011, 07:34:02 PM by khansahib »