4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Releases & Support) => Topic started by: Rembrandt on August 20, 2012, 04:21:38 PM

Title: [Mod] Different Thumbnail sizes
Post by: Rembrandt on August 20, 2012, 04:21:38 PM
 Hi!

 - one function for all different Thumbnail sizes
 - the new thumbnails can be smaller or larger than the original thumbnails.
 - Side ratio is respected
 
1.)  search in includes/functions.php:
 
 function get_thumbnail_code($media_file_name, $thumb_file_name = "", $image_id, $cat_id, $image_name = "", $mode = "", $show_link = 1, $open_window = 0) {
 
 insert above:

//########### Start [Mod] Different Thumbnail sizes ############################
function get_thumbnail_resizer($media_file_name, $thumb_file_name = "", $image_id, $cat_id, $image_name = "", $mode = "", $show_link = 1, $open_window = 0, $new_width = "", $new_height = "", $contest = 0) {
  global $site_sess, $config, $site_template;
   
  $new_width = $new_width ? $new_width : $config['max_thumb_width'];
  $new_height = $new_height ? $new_height : $config['max_thumb_height'];
  $orig_file = ($new_width>$config['max_thumb_width'] || $new_height>$config['max_thumb_height']) ? "media" : "thumb";
 
  if (!check_media_type($media_file_name)) {
    $new_image = "<img src=\"".ICON_PATH."/404.gif\" border=\"0\" alt=\"\" >";
  }
  else {
    if (!get_file_path($thumb_file_name, "thumb", $cat_id, 0, 0)) {
      $file_src = ICON_PATH."/".get_file_extension($media_file_name).".gif";
      $image_info = @getimagesize($file_src);
       $orig_width = $image_info[0];
       $orig_height = $image_info[1];
       $new_image = "<img src=\"".$file_src."\" style=\"border:0px;width:".$orig_width."px; height:".$orig_height."px;\" alt=\"".format_text($image_name, 2)."\" >";
    }
    else {
      $file_src = get_file_path($media_file_name, $orig_file, $cat_id, 0, 1);
      $orig_file = (check_thumb_type($file_src)) ?  $orig_file : "thumb";

      $file_src = get_file_path($thumb_file_name, $orig_file, $cat_id, 0, 1);
      $image_info = @getimagesize($file_src);
      $orig_width = $image_info[0];
      $orig_height = $image_info[1];

      if($new_width<$orig_width || $new_height<$orig_height){
        $orig_ratio = $orig_width / $orig_height;
        if ($new_width / $new_height > $orig_ratio){
          $new_width = round($new_height * $orig_ratio);
        }
        else{
          $new_height = round($new_width/$orig_ratio);
        }
      }
      else{
        $new_width = $orig_width;
        $new_height = $orig_height;
      }
       $new_image = "<img src=\"".$file_src."\" style=\"border:".$config['image_border']."px solid; width:".$new_width."px; height:".$new_height."px;\" alt=\"".format_text($image_name, 2)."\">";   
    }
  }
  if ($show_link) {
    if ($open_window) {
      $new_image = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""))."\" onclick=\"opendetailwindow()\" target=\"detailwindow\">".$new_image."</a>";         
    }
    else {
      $new_image = "<a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""))."\">".$new_image."</a>";
    }
  }
  return $new_image;
}
//########### End [Mod] Different Thumbnail sizes ############################


2.) search in includes/functions.php:

    "thumbnail" => get_thumbnail_code($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link),

insert below so many rows as you need, example:

    "thumbnail_small" => get_thumbnail_resizer($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link,0, 50,50), // The last two values are "width, height"
    "thumbnail_medium" => get_thumbnail_resizer($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link,0, 110,110), // The last two values are "width, height"
    "thumbnail_large" => get_thumbnail_resizer($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link,0, 200,200), // The last two values are "width, height"
    "thumbnail_big" => get_thumbnail_resizer($image_row['image_media_file'], $image_row['image_thumb_file'], $image_row['image_id'], $image_row['cat_id'], $image_row['image_name'], $mode, $show_link,0, 400,400), // The last two values are "width, height"
    //e.t.c.


mfg Andi
Title: Re: [Mod] Different Thumbnail sizes
Post by: paule on August 20, 2012, 05:17:26 PM
Hi Andi,

Perfekt!!
Du bist der Beste!!!!!

Vielen Dank

paulchen
Title: Re: [Mod] Different Thumbnail sizes
Post by: paule on September 02, 2012, 05:20:35 PM
Hallo Andi,

nur zur Info.
Es funktioniert wieder.
Sorry für die Umstände.
Es war wohl ein Cache Problem bei 2 Rechnern….
Hab ich noch nie gehabt.

noch mal vielen Dank für die Mühe.

paulchen
Title: Re: [Mod] Different Thumbnail sizes
Post by: Rembrandt on September 02, 2012, 05:27:22 PM
NP, Hauptsache es funktioniert wieder...

mfg Andi
Title: Re: [Mod] Different Thumbnail sizes
Post by: niad on September 17, 2012, 06:09:15 PM
Great MOD!
But there is a problem when a member is uploading a zip file and not an image.
In this case the MOD doesn't change the uploaded thumbnail image and the worst, doesn't let the thumb appear (https://dl.dropbox.com/u/86453764/thumb.jpg)

Any solution for this case please  :oops:
Title: Re: [Mod] Different Thumbnail sizes
Post by: Rembrandt on September 17, 2012, 06:47:34 PM
Hi!

Thank you for the hint!

test it please:
search in the code:

if (!get_file_path($media_file_name, $orig_file, $cat_id, 0, 0)) {

and replace:

if (!get_file_path($media_file_name, "thumb", $cat_id, 0, 0)) {


and please give me a Feedback, thx.

mfg Andi
Title: Re: [Mod] Different Thumbnail sizes
Post by: niad on September 17, 2012, 07:37:40 PM
Hi Andi,
After the change you suggested I get this (https://dl.dropbox.com/u/86453764/zip%20thumb.jpg) instead of the real preview...
Of course it is better, but doesn't fix the preview problem...
 
Title: Re: [Mod] Different Thumbnail sizes
Post by: Rembrandt on September 17, 2012, 07:40:44 PM
I have already noticed....
I am looking for a solution....

mfg Andi
Title: Re: [Mod] Different Thumbnail sizes
Post by: niad on September 17, 2012, 07:46:13 PM
wow! Thanks, you are so kind and helpful!
Title: Re: [Mod] Different Thumbnail sizes
Post by: Rembrandt on September 18, 2012, 07:59:20 AM
so.. I have updated step 1.) in my first post.
For me works it, i hope for you too. :)

mfg Andi
Title: Re: [Mod] Different Thumbnail sizes
Post by: niad on September 18, 2012, 12:21:12 PM
It works great! Thank you so much!  :D
Title: Re: [Mod] Different Thumbnail sizes
Post by: Rembrandt on September 18, 2012, 12:59:21 PM
np... :)

mfg Andi
Title: Re: [Mod] Different Thumbnail sizes
Post by: Tiburon on September 19, 2012, 09:05:34 AM
First of all, thank you for this mod. It works fine with 1.7.11 and I love it.

I have only one question regarding the top lists. Normally I call an image preview/thumbnail on my toplist like this:

{image_downloads_thumb_xx}

After installing the mod there is no longer a thumbnail but a link. How do I manage it, that the small thumbnail is shown on toplist? I tried it like this:

{image_downloads_thumb_small_1} or {image_downloads_thumbnail_small_1}

but this doesn´t work. Do you have any idea how it can work, or does it need further changes in the code to show thumbnails on toplists after installing the mod?

vg Tiburon
Title: Re: [Mod] Different Thumbnail sizes
Post by: Rembrandt on September 19, 2012, 05:51:10 PM
post your top.php...
Title: Re: [Mod] Different Thumbnail sizes
Post by: Tiburon on September 20, 2012, 10:11:13 AM
Hi Rembrandt,

thanks for answering. It was my mistake. After upgrading to 1.7.11 I forgot to change the original top.php file with my modified one. :oops: Your mod also works perfectly with a modified toplist. Sorry if I caused any inconvenience.

Tiburon
Title: Re: [Mod] Different Thumbnail sizes
Post by: Tiburon on September 25, 2012, 10:07:21 AM
Hi,

I have a question regarding the mod. I tested a few things and as far as I can see the additional thumbnail sizes are all created from the original file but not from the thumbnail file. Is this correct?

Is there be a possibility to create additional thumbnail sizes from thumnbail file, if this file is big enough e.g. 600x450 px?

Thanks

Tiburon
Title: Re: [Mod] Different Thumbnail sizes
Post by: Rembrandt on September 25, 2012, 11:38:22 AM
in "ACP/General/Upload settings", set the Value higher:
Max. width of thumbnail in pixel
Max. heigth of thumbnail in pixel

for the function these values are relevant , not the real thumbnail size.

mfg Andi
Title: Re: [Mod] Different Thumbnail sizes
Post by: Tiburon on September 25, 2012, 12:01:13 PM
Ah, thank you, I´ll try this.  :)
Title: Re: [Mod] Different Thumbnail sizes
Post by: praveen on November 02, 2017, 08:19:43 PM
In the thumbnail bit template, i changed {thumbnail} to {thumbnail_large} but the thumbnails are still showing the old size :(
Title: Re: [Mod] Different Thumbnail sizes
Post by: mahsabk on April 17, 2018, 01:32:28 PM
thank my thumbnail problem solved :lol: :lol: 8)