Author Topic: 2 different thumb sizes  (Read 6201 times)

0 Members and 1 Guest are viewing this topic.

Offline fabulous

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • http://www.foto-fish.de
2 different thumb sizes
« on: March 27, 2003, 01:19:00 AM »
Hi there,
i love 4imgages and i love especially love this forum and V@no :roll: :D

i just read http://www.4homepages.de/forum/viewtopic.php?t=4060 and i love it. i applied it to my start page and it works perfect.

now, I would also like to mod the size of a few thumbs my top gallery and the small random thumb in gallery listing. all in all i need 3 different thumbnail sizes on my page, ratio should allways be used (so if it is horizontal i do not want to a 200*200 thumb but a 200*100 e.g).

    first i need my regular 200*200 thumb (maximum), this one is used when i'm in a category, on the start page and as random pic.
    second, i need a 100*100 max thumb, which should be used in the top gallery, showing the top 50 fotos by hits and also on the start page next to the last commented fotos. this part is already working.
    third, i would need a 50*50 max thumb, this one i would like to use also on the start page instead of the 50*37 fix size thumb in category listing in the top part of the start page.[/list:u]

    now my problem: i tried to modify the code V@no gave in the already mentioned thread. i tried to modify my top.php where the important code looks as follows:
Code: [Select]
// Hits
$sql = "SELECT i.image_id, i.user_id, i.cat_id, i.image_name, i.image_hits, c.cat_name".get_user_table_field(", u.", "user_name").", i.image_thumb_file
        FROM ".IMAGES_TABLE." i, ".CATEGORIES_TABLE." c
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND i.cat_id = c.cat_id
        $cat_match_sql
        ORDER BY i.image_hits DESC, i.image_name ASC
        LIMIT 50";
$result = $site_db->query($sql);
$top_list = array();
$i = 1;
while ($row = $site_db->fetch_array($result)) {
  $top_list[$i] = $row;
  $i++;
}
$site_db->free_result();

for ($i = 1; $i <= 50; $i++) {
  if (isset($top_list[$i])) {
    $register_array['image_hits_'.$i] = (check_permission("auth_viewimage", $top_list[$i]['cat_id'])) ? "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$top_list[$i]['image_id'])."\">".htmlspecialchars($top_list[$i]['image_name'])."</a>" : htmlspecialchars($top_list[$i]['image_name']);
    $register_array['image_hits_openwindow_'.$i] = (check_permission("auth_viewimage", $top_list[$i]['cat_id'])) ? "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$top_list[$i]['image_id'])."\" onclick=\"opendetailwindow()\" target=\"detailwindow\">".htmlspecialchars($top_list[$i]['image_name'])."</a>" : htmlspecialchars($top_list[$i]['image_name']);
    if (isset($top_list[$i][$user_table_fields['user_name']]) && $top_list[$i]['user_id'] != GUEST) {
      $user_profile_link = (!empty($url_show_profile)) ? preg_replace("/{user_id}/", $top_list[$i]['user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$top_list[$i]['user_id'];
      $register_array['image_hits_user_'.$i] = "<a href=\"".$site_sess->url($user_profile_link)."\">".htmlspecialchars($top_list[$i][$user_table_fields['user_name']])."</a>";
    }
    else {
      $register_array['image_hits_user_'.$i] = $lang['userlevel_guest'];
    }
    $register_array['image_hits_cat_'.$i] = "<a href=\"".$site_sess->url(ROOT_PATH."categories.php?".URL_CAT_ID."=".$top_list[$i]['cat_id'])."\">".htmlspecialchars($top_list[$i]['cat_name'])."</a>";
    $register_array['image_hits_number_'.$i] = "<b>".$top_list[$i]['image_hits']."</b>";
    $register_array['image_hits_thumb_'.$i] = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$top_list[$i]['image_id'])."\"><img src=\"data/thumbnails/".$top_list[$i]['cat_id']."/".$top_list[$i]['image_thumb_file']."\" border=\"0\" alt=\"\" />";
  }
  else {
    $register_array['image_hits_'.$i] = "--";
    $register_array['image_hits_user_'.$i] = "--";
    $register_array['image_hits_cat_'.$i] = "--";
    $register_array['image_hits_number_'.$i] = "--";
    $register_array['image_hits_thumb_'.$i] = "--";
  }
}

i tried to add something like this:
Code: [Select]
if (!get_file_path($image_row['image_thumb_file'], "thumb", $image_row['cat_id'], 0, 0)) {
        $thumb_file = ICON_PATH."/".get_file_extension($image_row['image_media_file']).".gif";
      }else {
        $thumb_file = get_file_path($image_row['image_thumb_file'], "thumb", $image_row['cat_id'], 0, 1);
      }
      $thumb_info = @getimagesize($thumb_file);
      $width = $thumb_info[0];
      $height = $thumb_info[1];
      $dimension = 100;
      $ratio = $width / $height;
      if ($ratio > 1) {
        $new_width = $dimension;
        $new_height = floor(($dimension/$width) * $height);
      }else {
        $new_width = floor(($dimension/$height) * $width);
        $new_height = $dimension;
      }
      $site_template->register_vars(array(
        "comment_image_thumb" => (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id)) ? "<img src=\"".$thumb_file."\" width=\"".$new_width."\" height=\"".$new_height."\" onClick=\"alert('".$lang['members_only']."');\" border=\"".$config['image_border']."\">" : "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$comment_row[$i]['image_id'].((!empty($mode)) ? "&amp;mode=".$mode : ""))."\"><img src=\"".$thumb_file."\" width=\"".$new_width."\" height=\"".$new_height."\" border=\"".$config['image_border']."\"></a>",

i tried a bit, but i do not understand php, so i do not know what part i have to change. i would apreciate a lot if someone has a look on this issue :)
you can see the already working thums on http://www.foto-fish.de
only to be clear: the most important for me is to scale the thumbs in top.php to about half the size (100 pixel maximum height/width) instead of the now used 200 pixel size. thx in advance.

fab

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: 2 different thumb sizes
« Reply #1 on: March 27, 2003, 02:01:54 AM »
Quote from: fabulous
Hi there,
i love 4imgages and i love especially love this forum and V@no :roll: :D

huh? 8O

if u are refering to "Alternative TOP images"
 then u are very close to what u need ;)
from the fist code u posted change
Code: [Select]
   $register_array['image_hits_thumb_'.$i] = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$top_list[$i]['image_id'])."\"><img src=\"data/thumbnails/".$top_list[$i]['cat_id']."/".$top_list[$i]['image_thumb_file']."\" border=\"0\" alt=\"\" />";
replace with:
Code: [Select]
     $thumb_info = @getimagesize("data/thumbnails/".$top_list[$i]['cat_id']."/".$top_list[$i]['image_thumb_file']);
      $width = $thumb_info[0];
      $height = $thumb_info[1];
      $dimension = 48;
      $ratio = $width / $height;
      if ($ratio > 1) {
        $new_width = $dimension;
        $new_height = floor(($dimension/$width) * $height);
      }else {
        $new_width = floor(($dimension/$height) * $width);
        $new_height = $dimension;
      }
    $register_array['image_hits_thumb_'.$i] = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$top_list[$i]['image_id'])."\"><img src=\"data/thumbnails/".$top_list[$i]['cat_id']."/".$top_list[$i]['image_thumb_file']."\" border=\"0\" width=\"".$new_width."\" height=\"".$new_height."\" alt=\"\" />";
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline fabulous

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • http://www.foto-fish.de
2 different thumb sizes
« Reply #2 on: March 27, 2003, 02:43:28 AM »
yeah, i changed my toplist whith the tutorial u mentioned. ;)

i changed the code as you said, but now the following error happens:
Code: [Select]
Warning: Division by zero in /home/kunden/u10211/odd-fish.de/fotos/top.php on line 196

Warning: Division by zero in /home/kunden/u10211/odd-fish.de/fotos/top.php on line 201

when i changed the code bevor i got exactly the same error.
if i look into top.php there is is line 196:
Code: [Select]
 $ratio = $width / $height;and in line 201:
Code: [Select]
$new_width = floor(($dimension/$height) * $width);
so i think the 4images does not know what thumb to take and read the dimensions, especially $height.. any idea ?
you can see the problem here: http://www.foto-fish.de/top.php

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
2 different thumb sizes
« Reply #3 on: March 27, 2003, 03:54:31 AM »
ah, sry about that... :oops:
I can not check the code, since I have modifyed version of top.php...
but anyway, I forgot add path to the file in
Code: [Select]
     $thumb_info = @getimagesize($top_list[$i]['image_thumb_file']);
just replace it with:
Code: [Select]
     $thumb_info = @getimagesize("data/thumbnails/".$top_list[$i]['cat_id']."/".$top_list[$i]['image_thumb_file']);

P.S. I updated my post above.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline fabulous

  • Newbie
  • *
  • Posts: 15
    • View Profile
    • http://www.foto-fish.de
2 different thumb sizes
« Reply #4 on: March 27, 2003, 10:31:42 AM »
cool, now it works :) thx a lot for that.
the only problem i have now, is, that i still get the error for my media file, where no thumb is present.  i can remember that there was a solution in the top list mod thread V@no mentioned .. should i apply that one ?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
2 different thumb sizes
« Reply #5 on: March 27, 2003, 12:22:37 PM »
Quote from: fabulous
i can remember that there was a solution in the top list mod thread V@no mentioned .. should i apply that one ?

yes, I think on 3th or 4th page of that MOD, I posted sollution for that problem ;)
if u apply the fix, then u'll need do slight changes in "todays" fix ;)
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: 2 different thumb sizes
« Reply #6 on: December 25, 2005, 10:30:50 PM »
A weakness has been discovered from the $user_profile_link string.

In your includes/sessions.php file,

find :

Quote

$user_profile_link = (!empty($url_show_profile)) ? preg_replace("/{user_id}/", $top_list[$i]['user_id'], $url_show_profile) : ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$top_list[$i]['user_id'];


replace with :

Code: [Select]

$user_profile_link = (!empty($url_show_profile)) ? str_replace("{user_id}", $top_list[$i]['user_id'], $url_show_profile) : $site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$top_list[$i]['user_id']);


Merry Christmas.