forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Watermarking & image manipulation => Topic started by: Stramm on August 02, 2005, 06:56:36 pm

Title: Better thumbnails hack
Post by: Stramm 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)
(https://forum.coppermine-gallery.net/proxy.php?request=http%3A%2F%2Fimg.villagephotos.com%2Fp%2F2005-8%2F1058028%2F1_cropped140x140_normal.jpg&hash=8d653ed7a08153a90fc4fc12efcd52298240f606) (https://forum.coppermine-gallery.net/proxy.php?request=http%3A%2F%2Fimg.villagephotos.com%2Fp%2F2005-8%2F1058028%2F1_cropped140x140_sharpened.jpg&hash=5f5cb8f9a288e5681fce239a1804fd2cf3f41ee9) (https://forum.coppermine-gallery.net/proxy.php?request=http%3A%2F%2Fimg.villagephotos.com%2Fp%2F2005-8%2F1058028%2F2_cropped140x140_normal.jpg&hash=0d50cb0961c364a5cbafeb16689c38668238322c) (https://forum.coppermine-gallery.net/proxy.php?request=http%3A%2F%2Fimg.villagephotos.com%2Fp%2F2005-8%2F1058028%2F2_cropped140x140_sharpened.jpg&hash=ee3e5b6cbf6152cbb49d60d1f5a740ef15b8aa29)
Title: Re: Better thumbnails hack
Post by: jonnymalm 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.
Title: Re: Better thumbnails hack
Post by: Stramm 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
Title: Re: Better thumbnails hack
Post by: Sp33d3r 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...
Title: Re: Better thumbnails hack
Post by: Stramm on September 27, 2005, 11:31:44 pm
Thanks... I love positive feedback  ;D
Title: Re: Better thumbnails hack
Post by: Stramm 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
Title: Re: Better thumbnails hack
Post by: zman 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.  ;)
Title: Re: Better thumbnails hack
Post by: Stramm 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
Title: Re: Better thumbnails hack
Post by: zman 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!
Title: Re: Better thumbnails hack
Post by: Stramm 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)
Title: Re: Better thumbnails hack
Post by: zman 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
Title: Re: Better thumbnails hack
Post by: Stramm 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
Title: Re: Better thumbnails hack
Post by: zman 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!
Title: Re: Better thumbnails hack
Post by: Stramm 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
Title: Re: Better thumbnails hack
Post by: zman 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!
Title: Re: Better thumbnails hack
Post by: Lombi 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.
Title: Re: Better thumbnails hack
Post by: Stramm 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...
Title: Re: Better thumbnails hack
Post by: Lombi 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".
Title: Re: Better thumbnails hack
Post by: willstein 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" ?
Title: Re: Better thumbnails hack
Post by: Stramm 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
Title: Re: Better thumbnails hack
Post by: willstein on October 28, 2005, 10:04:01 am
thanks stramm
Title: Re: Better thumbnails hack
Post by: tobyy on November 10, 2005, 02:12:51 am
hi there! great hack!!

i had the problem that the album list view  thumb size was ignored and these thumbs had the same size as inside the gallery.

i checked my code and realized that the code in index.php has to be replaced 4 times, not only once:

find (4 times) in index.php
Code: [Select]
                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size']);
replace with
Code: [Select]
                        $image_size = compute_img_size($picture['pwidth'], $picture['pheight'], $CONFIG['alb_list_thumb_size'], "cat_thumb");

hopefully i'm right :)  maybe you should edit this in the mod-instructions..

cheers
t
Title: Re: Better thumbnails hack
Post by: Stramm on November 10, 2005, 12:09:06 pm
yes, that was a known bug.. read more about it and the complete fix here
http://forum.coppermine-gallery.net/index.php?topic=21469.msg102299#msg102299

I just have forgotten to post the fix here also.. thanks for mentioning
Title: Re: Better thumbnails hack
Post by: owenb on November 16, 2005, 09:33:50 pm
Nice one, Stramm. Got this working to my liking on my site now - www.owenbillcliffe.co.uk

However! I have put my own watermarks on photos before they are uploaded, and due to the size of the watermark, it is poking into the square thumbnail. It's not devastating, just a bit ugly. I wondered if there was an adjustment I could make to the code that creates the square that will create the square from one side or another on horizontal images, or one end or another on vertical ones, instead of just taking the central square.

That would mean that thumbnails would either contain my entire watermark, or none of it, which is preferable to me than all of them having just a bit.

Do you see what I mean? Is it possible?

Thanks man!
Owen
Title: Re: Better thumbnails hack
Post by: Stramm on November 17, 2005, 08:42:37 am
have a look at picmgmnt.inc.php. In the function resize_image the crop values get calculated (for both ImageMagick[im] and GD[default]) after switch ($CONFIG['thumb_method'])

the value where to crop (center/left/right/top/bottom) is in $xOffset and $yOffset
Title: Re: Better thumbnails hack
Post by: owenb on November 18, 2005, 12:01:26 am
Okeydokey, I had a look at where you pointed me to, and I was scared.

I'm afraid I couldn't even use logic and common sense to deduce what elements were doing what! Not that clever I'm afraid.

Is there a way to just MAKE them crop the horizontal ones (width greater than length) so that the left hand side of the thumb is the left hand side of the picture itself, and everything else crop the thumb from the centre?

Thank you in advance for taking the time to moderate these threads! :)

Owen
Title: Re: Better thumbnails hack
Post by: Stramm on November 19, 2005, 09:39:12 am
what are you using?? ImageMagick or GD2.. I don't want to do extra work ;)

still.. you could use my watermark mod. Then you won't have watermarks on thumbs...
Title: Re: Better thumbnails hack
Post by: owenb on November 19, 2005, 10:33:10 am
I'm using GD2.

And can you point me towards someone who is using your watermarks mod so I can see how it works? :) And is it tricky to add if you ALREADY have the better thumbs mod?

Cheers.
Owen
Title: Re: Better thumbnails hack
Post by: Stramm on November 19, 2005, 10:38:37 am
http://forum.coppermine-gallery.net/index.php?topic=21469.0

read that. And I'm online right now so you should be able to check my sandbox CPG
Title: Re: Better thumbnails hack
Post by: owenb on November 19, 2005, 03:10:15 pm
Wow, that watermark hack looks like a LOT of hacking, and I'm still not sure how I have to alter it if I'm already using your square thumbs hack... which I am! :)
Title: Re: Better thumbnails hack
Post by: Stramm on November 19, 2005, 03:28:23 pm
Best is, if you don't use a lot of other mods, to install my mod pack.
If you don't want to use it.. no problem. Follow the instructions for the watermark mod and just use the picmgmnt.inc.php made for watermark and better thumbs hack (in that thread). I think it's even safe to use the one form the modpack. And that version is always up to date
Title: Re: Better thumbnails hack
Post by: owenb on November 19, 2005, 03:32:03 pm
I've got a fair amount of content hacking on my site, I think. No mods as such but elements chopped out, such as breadcrumbs, and certain graphical elements etc.

With your square thumbs hack already added, will just straight adding the watermark hack work?

I tried to add the whole shebang once before and I think it was too much for my puny brain to handle coz my entire site went t*ts up and I had to reinstall the duplicate I'd made... ;)
Title: Re: Better thumbnails hack
Post by: Stramm on November 19, 2005, 03:43:00 pm
should work.. at least the mods are made to work together like butter, hehehe
as you can see it on my site and in the mod pack thread ;) and maybe in the first post here (the picmgmnt.inc.php files for versions with and without watermark mod)
Title: Re: Better thumbnails hack
Post by: daniel_w on November 27, 2005, 10:40:02 pm
Will this hack be availiable for 1.4? I've had to change all thumbnails after upgrading.. :-(
Title: Re: Better thumbnails hack
Post by: Stramm on November 28, 2005, 08:44:20 am
It's already finished.. needs still some testing though and will be only available within my modpack for 1.4 (I need to be more careful with new projects, maintainig these mods is time consuming)