Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1] 2   Go Down

Author Topic: Better thumbnails hack  (Read 50562 times)

0 Members and 1 Guest are viewing this topic.

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Better thumbnails hack
« on: August 02, 2005, 06:56:36 pm »

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

Code: [Select]
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
Code: [Select]
  'th_wd' => 'Width',below add
Code: [Select]
  'th_ex' => 'Exact',
find
Code: [Select]
  array('Max dimension of a thumbnail <a href="#notice2" class="clickable_option">**</a>', 'thumb_width', 0), //cpg1.3.0
replace with
Code: [Select]
  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
Code: [Select]
  array('Max width or height for uploaded pictures/videos (pixels)', 'max_upl_width_height', 0), //cpg1.3.0below add
Code: [Select]
'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)
Code: [Select]
            if (resize_image($image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'])) {replace with
Code: [Select]
            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
Code: [Select]
            if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false")) {
replace with
Code: [Select]
            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
Code: [Select]
            if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false")) {
and replace with
Code: [Select]
    if (resize_image($work_image, $thumb, $CONFIG['thumb_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use'], "false", 1)) {
   
in functions.inc.php find
Code: [Select]
function compute_img_size($width, $height, $max)replace with
Code: [Select]
function compute_img_size($width, $height, $max, $normal="")
find
Code: [Select]
        if($thumb_use=='ht') {
          $image_size['geom'] = ' height="'.$image_size['height'].'"';
        } elseif($thumb_use=='wd') {
          $image_size['geom'] = 'width="'.$image_size['width'].'"';
below add
Code: [Select]
        } 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

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

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

in config.php find
Code: [Select]
    $wd_selected = ($value == 'wd') ? 'selected' : '';below add
Code: [Select]
    $ex_selected = ($value == 'ex') ? 'selected' : '';
find
Code: [Select]
                                <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
Code: [Select]
                                <option value="ex" $ex_selected>{$lang_config_php['th_ex']}</option>


in index.php
Code: [Select]
                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
with
Code: [Select]
                        $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)
(http://img.villagephotos.com/p/2005-8/1058028/1_cropped140x140_normal.jpg) (http://img.villagephotos.com/p/2005-8/1058028/1_cropped140x140_sharpened.jpg) (http://img.villagephotos.com/p/2005-8/1058028/2_cropped140x140_normal.jpg) (http://img.villagephotos.com/p/2005-8/1058028/2_cropped140x140_sharpened.jpg)
« Last Edit: October 01, 2005, 08:01:19 pm by Stramm »
Logged

jonnymalm

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Re: Better thumbnails hack
« Reply #1 on: August 08, 2005, 04:23:38 am »

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

Keep up the good work.
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #2 on: August 16, 2005, 06:00:48 pm »

Forgotten something....
in slideshow.inc.php find
Code: [Select]
    }elseif($CONFIG['thumb_use']=='any' && max($picture['pwidth'], $picture['pheight']) > $CONFIG['picture_width']){
      $condition = true;
and below add
Code: [Select]
    }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

  • Coppermine newbie
  • Offline Offline
  • Posts: 2
Re: Better thumbnails hack
« Reply #3 on: September 27, 2005, 10:53:47 pm »

Very nice hack dude! Way to go  ;D

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

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #4 on: September 27, 2005, 11:31:44 pm »

Thanks... I love positive feedback  ;D

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #5 on: October 01, 2005, 07:59:18 pm »

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

replace in functions.inc.php function compute_img_size
with

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


with
Code: [Select]
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)

Code: [Select]
                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
with
Code: [Select]
                        $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
« Last Edit: October 05, 2005, 04:08:13 pm by Stramm »
Logged

zman

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Better thumbnails hack
« Reply #6 on: October 10, 2005, 02:55:46 pm »

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.  ;)
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #7 on: October 10, 2005, 04:13:23 pm »

here it's explained better than I ever could
http://www.php-editors.com/articles/sql_phpmyadmin.php

zman

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Better thumbnails hack
« Reply #8 on: October 12, 2005, 09:19:44 am »

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!
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #9 on: October 12, 2005, 12:33:37 pm »

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

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Better thumbnails hack
« Reply #10 on: October 12, 2005, 02:27:32 pm »

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
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #11 on: October 12, 2005, 02:42:27 pm »

if it's the picmgmnt.inc.php you've downloaded from this thread (without watermark support) then just find in that file
Code: [Select]
            if (!resize_image($image, $normal, $CONFIG['picture_width'], $CONFIG['thumb_method'], $CONFIG['thumb_use']))and replace with
Code: [Select]
            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

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Better thumbnails hack
« Reply #12 on: October 12, 2005, 02:58:53 pm »

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!
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #13 on: October 12, 2005, 03:13:36 pm »

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

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Better thumbnails hack
« Reply #14 on: October 12, 2005, 03:40:19 pm »

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!
Logged

Lombi

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 25
  • Never lick a gift horse in the mouth.
    • Surreal Art Prints
Re: Better thumbnails hack
« Reply #15 on: October 14, 2005, 02:24:04 pm »

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.
Logged
While you are looking at some surreal art prints or just some surrealistic art you might get yourself some windows xp boot screens.

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #16 on: October 14, 2005, 02:28:23 pm »

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

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 25
  • Never lick a gift horse in the mouth.
    • Surreal Art Prints
Re: Better thumbnails hack
« Reply #17 on: October 14, 2005, 06:07:46 pm »

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".
Logged
While you are looking at some surreal art prints or just some surrealistic art you might get yourself some windows xp boot screens.

willstein

  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 120
    • mansei
Re: Better thumbnails hack
« Reply #18 on: October 23, 2005, 06:44:53 am »

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" ?
« Last Edit: October 23, 2005, 07:12:53 am by lavashark.com »
Logged

Stramm

  • Dev Team member
  • Coppermine addict
  • ****
  • Country: 00
  • Offline Offline
  • Gender: Male
  • Posts: 6006
    • Bettis Wollwelt
Re: Better thumbnails hack
« Reply #19 on: October 23, 2005, 12:01:42 pm »

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
Pages: [1] 2   Go Up
 

Page created in 0.028 seconds with 20 queries.