Better thumbnails hack Better thumbnails hack
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Better thumbnails hack

Started by Stramm, August 02, 2005, 06:56:36 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Stramm

With that lil modifications it's possible to sharpen the thumbnails. This way they look far better. Also it's possible to crop thumbnails. Means you set an exact width and height and all thumbs have the same dimensions.
The sharpen function works like the Photoshop or Gimp unsharp mask. If preset decent values. All can be turned on and off in admin. If you change thumb dimensions remember that you'll have to use the admin tools to recreate them. To enable cropping set 'Use dimension ( width or height or Max aspect for thumbnail )' to exact and set the width and height.
Sharpening doesn't work with GD1! That hack's for 1.32, 1.33

downloadable already edited files http://forum.coppermine-gallery.net/index.php?topic=21469.0

demo http://stramm.mine.nu

Let's get started

first the necessary SQL. Please use a tool like PHPMyAdmin or similar to update your SQL. Change the prefix cpg_ to whatever you use

insert into cpg_config (name, value) values ('enable_unsharp', '0');
insert into cpg_config (name, value) values ('unsharp_amount', '80');
insert into cpg_config (name, value) values ('unsharp_radius', '0.5');
insert into cpg_config (name, value) values ('unsharp_threshold', '3');
insert into cpg_config (name, value) values ('thumb_height', '120');


open lang/english.php

find
  'th_wd' => 'Width',
below add
  'th_ex' => 'Exact',

find
  array('Max dimension of a thumbnail <a href="#notice2" class="clickable_option">**</a>', 'thumb_width', 0), //cpg1.3.0

replace with
  array('Max dimension (width) of a thumbnail <a href="#notice2" class="clickable_option">**</a>', 'thumb_width', 0), //cpg1.3.0
  array('Height of a thumbnail (if you use exact)', 'thumb_height', 0), //cpg1.3.0


find
  array('Max width or height for uploaded pictures/videos (pixels)', 'max_upl_width_height', 0), //cpg1.3.0
below add
'Thumb Sharpening',
array('Enable Unsharp Mask', 'enable_unsharp', 1),
array('Amount', 'unsharp_amount', 0),
array('Radius', 'unsharp_radius', 0),
array('Threshold', 'unsharp_threshold', 0),



in util.php find (if you're using my watermark hack skip this)
            if (resize_image($image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])) {
replace with
            if (resize_image($image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], 1)) {

if you're using my watermark hack then find in util.php instead
            if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false")) {

replace with
            if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) {


if you're using the better admin tools hack for my watermark mod then find in updatethumbs.php
            if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false")) {

and replace with
    if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) {

   
in functions.inc.php find
function compute_img_size($width, $height, $max)
replace with
function compute_img_size($width, $height, $max, $normal="")

find
        if($thumb_use=='ht') {
          $image_size['geom'] = ' height="'.$image_size['height'].'"';
        } elseif($thumb_use=='wd') {
          $image_size['geom'] = 'width="'.$image_size['width'].'"';

below add
        } elseif($thumb_use=='ex') {
if ($normal=="normal"){
$image_size['geom'] = 'width="'.$image_size['width'].'" height="'.$image_size['height'].'"';
}
elseif ($normal=="cat_thumb"){
          $image_size['geom'] = 'width="'.$max.'" height="'.$max.'"';
}
else {
          $image_size['geom'] = 'width="'.$CONFIG['thumb_width'].'" height="'.$CONFIG['thumb_height'].'"';
}


in displayimage.php find

    $image_size = compute_img_size($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'], $CONFIG['picture_width']);

replace with
    $image_size = compute_img_size($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'], $CONFIG['picture_width'], "normal");


    }elseif($CONFIG['thumb_use']=='any' && max($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight']) > $CONFIG['picture_width']){
      $condition = true;

below add
    }elseif($CONFIG['thumb_use']=='ex' && max($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight']) > $CONFIG['picture_width']){
      $condition = true;


in config.php find
    $wd_selected = ($value == 'wd') ? 'selected' : '';
below add
    $ex_selected = ($value == 'ex') ? 'selected' : '';

find

                                <option value="any" $any_selected>{$lang_config_php['th_any']}</option>
                                <option value="ht" $ht_selected>{$lang_config_php['th_ht']}</option>
                                <option value="wd" $wd_selected>{$lang_config_php['th_wd']}</option>

below add
                                <option value="ex" $ex_selected>{$lang_config_php['th_ex']}</option>



in index.php
                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);

with
                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], "cat_thumb");



Now just replace your picmgmnt.inc.php with the attached one. Have fun... oh.. and I don't mind to get feedback ;)

Watermark users please use the watermark_picmgmnt.inc.php

examples: orig pics are 640x480... all cropped to 140x140. First without unsharpen mask, the other sharpened (100, 0.5, 3)
(https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg.villagephotos.com%2Fp%2F2005-8%2F1058028%2F1_cropped140x140_normal.jpg&hash=8d653ed7a08153a90fc4fc12efcd52298240f606) (https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg.villagephotos.com%2Fp%2F2005-8%2F1058028%2F1_cropped140x140_sharpened.jpg&hash=5f5cb8f9a288e5681fce239a1804fd2cf3f41ee9) (https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg.villagephotos.com%2Fp%2F2005-8%2F1058028%2F2_cropped140x140_normal.jpg&hash=0d50cb0961c364a5cbafeb16689c38668238322c) (https://coppermine-gallery.com/forum/proxy.php?request=http%3A%2F%2Fimg.villagephotos.com%2Fp%2F2005-8%2F1058028%2F2_cropped140x140_sharpened.jpg&hash=ee3e5b6cbf6152cbb49d60d1f5a740ef15b8aa29)

jonnymalm

Great hack, I actually started my own hack to make square thumbnails but yours was much better.

Keep up the good work.

Stramm

Forgotten something....
in slideshow.inc.php find
    }elseif($CONFIG['thumb_use']=='any' && max($picture['pwidth'], $picture['pheight']) > $CONFIG['picture_width']){
      $condition = true;

and below add
    }elseif($CONFIG['thumb_use']=='ex' && max($picture['pwidth'], $picture['pheight']) > $CONFIG['picture_width']){
      $condition = true;


otherwise your slideshow will only pick fullsized pics and no normal (resized) ones

Sp33d3r

Very nice hack dude! Way to go  ;D

I applied this one on v1.3.5, it works just fine...

Stramm

Thanks... I love positive feedback  ;D

Stramm

#5
bug_fix.... if you applied this mod before Oct/01/2005

replace in functions.inc.php function compute_img_size
with


else {
          $image_size['geom'] = 'width="'.$CONFIG['thumb_width'].'" height="'.$CONFIG['thumb_height'].'"';
}



with

elseif ($normal=="cat_thumb"){
          $image_size['geom'] = 'width="'.$max.'" height="'.$max.'"';
}
else {
          $image_size['geom'] = 'width="'.$CONFIG['thumb_width'].'" height="'.$CONFIG['thumb_height'].'"';
}



in index.php in the function get_subcat_data and in function list_cat_albums($cat = 0) (there are 4 of these, only change the 2 in the mentioned functions)

                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);

with
                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], "cat_thumb");


with that Config -> Album list view -> Size of thumbnails in pixels works again

zman

Hi Stramm,

It is really a great hack and pretty impressive the result you posted. The sharper thumbs are my biggest problem in CPG.
Since I'm a rookie, can you please explain a bit more the first part, i.e. how to modify the sql?

As you wrote:
"first the necessary SQL. Please use a tool like PHPMyAdmin or similar to update your SQL."

How can I update the SQL in PHPMyAdmin? I opened the PHPMyAdmin, it fine. It is also fine to modify the cpg tags accordingly. But the rest is darkness...  ???

Can you please describe this procedure a bit more detailed? Thank you and sorry for the rookie question.  ;)

Stramm


zman

Hi Stramm!  :)  ;D
Thank you for the hint, it worked well. I have created my cpg, it is very good! Your hack should be the part of the new cpg versions, it is so essential.

2 questions, if you don't mind: it seems for me that the sharpening is not applied for the intermediate (i.e. middle-sized) pictures, but only for the small thumbs. Did I do something wrong? How can the sharpening be extended for the intermediate pics as well?

Thank you very much again!

Stramm

what version are you using? The one with or without watermark.. or have you installed the mod pack

and yes, it's only sharpening thums and minithumbs (in case of you're using the modpack). It's the better thumbs mod ;)
sharpening images leads to bigger filesize. Also, if you use already sharpened image it may ruin the pics.
That's different for thumbs cause resizing usually blurs the thumbs

But if you tell me what version you use I tell you how to enable sharpening for normal and fullsized images (if you watermark or resize the fullsized)

zman

Hi Stramm,

I'm using 1.3.5. (just downloaded it yesterday). No watermark mod used at all, I installed only the thumb sharpening parts of the mods and finally replaced the picmgmnt.inc.php with the attached one. (I hope that my primitive description is sufficient to understand... ;)
I don't like to sharpen the originals (they are sharpened already and saved as good quality (90%) jpg), but I'd like to sharpen the intermediary pics, since they are resized from the originals, therefore they are softer.
Thank you for your great help and support! ;D

Stramm

if it's the picmgmnt.inc.php you've downloaded from this thread (without watermark support) then just find in that file
            if (!resize_image($image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use']))
and replace with
            if (!resize_image($image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], 1))

that'll take care of the normal images. Of course thumb sharpening needs to be enabled in config

zman

Thank you Stramm! I'll try it soon! :) :) :)

One more (and hopefully last) issue: if I set a bigger thumb size for the album list view than the thumbsize set in the Files and thumbnails settings, I got an ughly thumb in the album list. It seems that all thumb resized to the smaller size (=files and thumb setting) and they are magnified for the album view.

Here is a picture attached how it looks. It is a normal behavior? Is it caused by the thumb hack or something else?

Thanks!

Stramm

with or without the 'better thumbs mod' you'll have such a thumb. Why.... cause the thumb for albums is the same as the one you created for your images. If you 'zoom' into a bitmap picture (and nothing else is the html resize you're doing here) you'll get this effect

pretty normal behaviour

zman

This is with your thumb hack. I thought that the system generates different thumbs for the album view. If not, than I need to use identical sized thumbs. By the way, it would look nice if we can differentiate the album view from the random gallery by bigger thumbs.

Ok, thank you for the answer. I understand now. Thanks again!

Lombi

Very interesting hack, hope this gets implemented in the next regular release. I had one problem however ... when I changed the setting to exact and redid the thumbs all the thumbnails were now the size of intermediate pictures (huge). The sizes were stretched by html, the images were properly resized to the exact size.

Any ideas on why this would happen? Thanks.
While you are looking at some surreal art prints or just some surrealistic art you might get yourself some windows xp boot screens.

Stramm

if this happens most of the times the changes in functions.inc.php didn't get applied properly. Have you tried the mod pack? If not maybe you'll have a look at it...

Lombi

I have a heavily modified board myself so I cannot apply it (plus I only fancy this hack), I'll go over all the changes again and see if there are any characters i missed. Thanks.

Currently I have "bypassed" this issue by changing the setting to exact, resizing all the thumbnails and then changing it back to "width".
While you are looking at some surreal art prints or just some surrealistic art you might get yourself some windows xp boot screens.

willstein

#18
Being that I ALWAYS make a mistake when I install mods  :-X

Is there anyway I can verify that I installed the MOD correctly? (besides visually comparing two screenshots  ;))

-Will


edit: Visually there definitely is a difference.
See attached screenshot.
(sorry for the large filesize, it's basically needed to compare)

PS=> Is there any documentation on "Amount" "Radius" and "Threshold" ?

Stramm

strange... I have alreday replied but the answer isn't here.. hmm. OK, then again ;)

Looks to me like if it's working smooth. At least you can see it when comparing the trees. To be 100% sure set thumb method to 'exact' and width/ height to eg. 120 each. This'll make square thumbs. So just uplaod a test image and if you'll have a (not distorted) square thumb all's working perfect. All other thumbs will look crappy. Either switch back to what you had before or you'll have to run the admin tools to recreate the thumbs with the new settings.

The unsharp mask... read this. Impossible for me to explain it any better
http://www.photocritic.org/articles/usm.php
http://www.paintedstork.com/digiblog/unsharp_mask.html