forum.coppermine-gallery.net

Support => cpg1.4.x Support => Older/other versions => cpg1.4 modpack by Stramm => Topic started by: erostew on October 27, 2007, 10:04:29 am

Title: Question about variable size watermarks
Post by: erostew on October 27, 2007, 10:04:29 am
Just installed the modpack. Great work!

I tried the variable size for the watermarks and it works well but there is one glitch. It appears that when calculating the size it only takes into account the width of the image. I am using full size of 1280 and intermediate of 550. There are significant variations in size between portrait and landscape photos in both. The large landscape is normal size and in intermediate it's readable. But in portrait the intermediate is almost unreadable. That means I have to use an unacceptably large mark in fullsize landscape to be able to read the intermediate portrait mark.

So the question is: Am I doing something wrong? Or is this just a limitation of the marking script? If it is a limitation of the script I guess I can always disable scaling and stop watermarking the intermediates.

Regards.
Title: Re: Question about variable size watermarks
Post by: Stramm on October 27, 2007, 10:20:57 am
The calculation is based on the actual width of the intermediate image. Portrait eg. with a width of 350px gets attached a smaller watermark than a landscape pic with a width of 600px.

I do not consider this a glitch or a limitation but the way to make it usable.
Example: reduced width of the watermark on a 600px width image is 400px. On portrait with 350px width parts will be choped off. So the script reduces the wm further and it fits again.

If that behaviour isn't to your likings you always can modify the calculation (picmgmnt.inc.php)
Title: Re: Question about variable size watermarks
Post by: erostew on October 27, 2007, 06:31:20 pm
You misunderstand a bit. I LIKE that intermediate and full-size have different sized watermarks. The thing I consider to be a glitch is that portrait and landscape photos get different sized watermarks. It just doesn't look good to me. Would be nice if it was possible to use the longest dimension for calculating the size. I.E. 1024x768 and 768x1024 would get same size mark. I suppose you can say it's not a glitch, just a feature I wished worked differently.  ;)

I'll look at picmgmnt.inc.php but I suspect it's beyond my abilities.
Title: Re: Question about variable size watermarks
Post by: Stramm on October 27, 2007, 06:55:26 pm
I haven't misunderstood you... it's coded the way it is with purpose. As I already said, you easily can change that in picmgmnt.inc.php
Title: Re: Question about variable size watermarks
Post by: erostew on October 27, 2007, 09:38:23 pm
I managed to partly get what I wanted.

I changed
Code: [Select]
if ($wm_normal > $destWidth ) {
$wm_resize = (int)(($destWidth / $wm_normal) * 100);
into
Code: [Select]
if ($wm_normal > $destWidth && $wm_normal > $destHeight ) {
$wm_resize = $destWidth / $wm_normal;

That makes sure that if the fullsize pic has at least 1 dimension equal to wm_normal then the watermark is not scaled. Portrait and landscape get the same size watermark. However if I ever upload a pic that is 1279 pixels on the longest side the mark would scaled according to width again. And of course the mark for the intermediate pic is always scaled according to width.

I'm trying to get it so it will use width or height to calculate the size, whichever is larger, but haven't had any luck yet.

Regards
Title: Re: Question about variable size watermarks
Post by: erostew on October 27, 2007, 10:56:26 pm
Ok I think I have it solved now! Just had to declare a new variable and use it in the size calc.

I replaced
Code: [Select]
//shrink watermark on intermediate images -> If I had known that this is that §%&# with the transparency preserve... grrr
$wm_normal = (int)$CONFIG['reduce_watermark'];
if ($wm_normal > $destWidth ) {
$wm_resize = $destWidth / $wm_normal;
//load the original, huge sized logo (the one we want to size down)
with
Code: [Select]
//shrink watermark on intermediate images -> If I had known that this is that §%&# with the transparency preserve... grrr
/* Hacked by Erostew to use longest dimension */
$wm_normal = (int)$CONFIG['reduce_watermark'];
if ($destWidth >= $destHeight) { // Declare new variable $destLongest based on longest dimension
$destLongest = $destWidth;
} else {
$destLongest = $destHeight;
}
if ($wm_normal > $destWidth && $wm_normal > $destHeight ) { // changed to check both dimensions against $wm_normal to prevent unnecessary resize when only $destwidth is used
$wm_resize = $destLongest / $wm_normal; // New variable $destLongest is used to calculate size
/* End hack by Erostew */
//load the original, huge sized logo (the one we want to size down)

So the result is that both intermediate pics and full sized pics of any size get the same size watermark for both portrait and landscape. I actually surprised myself by getting this to work.  ;D
Title: Re: Question about variable size watermarks
Post by: erostew on October 27, 2007, 11:09:17 pm
The calculation is based on the actual width of the intermediate image. Portrait eg. with a width of 350px gets attached a smaller watermark than a landscape pic with a width of 600px.

I do not consider this a glitch or a limitation but the way to make it usable.
Example: reduced width of the watermark on a 600px width image is 400px. On portrait with 350px width parts will be choped off. So the script reduces the wm further and it fits again.

If that behaviour isn't to your likings you always can modify the calculation (picmgmnt.inc.php)
I'm not too sure that many people will use such a large watermark that that is needed. I use a 250x100 watermark on my fullsize 1280 pics because I don't want to start obscuring large parts of the pic. Of course everybody is different. I suppose it could be made a config option to use the same size for portrait and landscape if you wanted to do it in your mod.

But of course I am happy with how I got it to work for myself so I don't suggest that you should follow my preferences. Thanks for making this mod in the first place!

Regards
Title: Re: Question about variable size watermarks
Post by: Stramm on October 29, 2007, 10:06:20 am
if you use GD2, find in picmgmnt.inc.php
Code: [Select]
if ($wm_normal > $destWidth ) {
$wm_resize = $destWidth / $wm_normal;
and replace with
Code: [Select]
if ($wm_normal > $destWidth ) {
$wm_resize = $CONFIG['picture_width'] / $wm_normal;

haven't tested this but should work. If you however use ImageMagick, then you'll have to look for similar code in the ImageMagick part of the code and modify accordingly
Title: Re: Question about variable size watermarks
Post by: erostew on October 29, 2007, 08:46:12 pm
haven't tested this but should work. If you however use ImageMagick, then you'll have to look for similar code in the ImageMagick part of the code and modify accordingly
Tested that and it does work partly. The watermark is the same size on portrait and intermediate size pics. But it is scaled to fit the intermediate pics and it is reduced to that size for the full pics also. So intermediate and full pics, in portrait or landscape, all have the same reduced size watermark.
Title: Re: Question about variable size watermarks
Post by: Stramm on October 30, 2007, 11:49:27 am
I've corrected the above and tested it. Worked for me (GD2).
Title: Re: Question about variable size watermarks
Post by: erostew on October 30, 2007, 05:26:18 pm
I tried with your corrections and it worked the opposite of the first code you posted. Now the watermark is the same size for portrait and landscape, full-size and intermediate. But the mark is scaled to the full-size pics dimensions. I'm also using GD2.

I guess it's because my hacked together code uses the calculated dimensions of the new image and the code you posted uses a static variable. It would work fine if you don't use intermediate size pics I'm sure.

Regards
 

Title: Re: Question about variable size watermarks
Post by: Stramm on October 30, 2007, 05:49:33 pm
I'm not really sure anymore what you want to achieve. My code reduces the size of the watermark for both, portrait and landscape to the same size (calculation base is the config setting of the intermediate image)

Fullsize has the original watermark dimension (at least I hope so, tested only with landscape).
I haven't considered your code at all.

If you want to calculate the wm size on the width or height of the image depending which of the both is bigger... then this may be what you're looking for

Code: [Select]
if ($wm_normal > max($destWidth, $destHeight) ) {
$wm_resize = max($destWidth, $destHeight) / $wm_normal;
Title: Re: Question about variable size watermarks
Post by: erostew on October 30, 2007, 06:55:41 pm
I guess I should have said you could mark this closed/solved but I thought it was clear that the code I hacked was working to my satisfaction. I wanted to have the watermark scaled to fit the intermediate pic, or any uploaded full-size that is smaller than the max dimensions set for the gallery. Which is done just fine by the code already in your ModPack picmgmnt.inc.php. But I wanted a simple change so that the watermark was the same size for portrait and landscape. The code I wrote achieved that and works just fine.

However the code you just posted:
Code: [Select]
if ($wm_normal > max($destWidth, $destHeight) ) {
$wm_resize = max($destWidth, $destHeight) / $wm_normal;
works exactly the same as my much longer code:
Code: [Select]
if ($destWidth >= $destHeight) {
$destLongest = $destWidth;
} else {
$destLongest = $destHeight;
}
if ($wm_normal > $destWidth && $wm_normal > $destHeight ) {
$wm_resize = $destLongest / $wm_normal;
So you did teach me something new. I hadn't seen the "max" statement used before. Most of my limited knowledge of PHP comes from working with database apps. Simply adding and displaying data. Not much manipulation of data.

The nice thing about PHP is that there is usually more than one way to acieve the desired result. The challenge is sometimes to do it the best way!

I should say that I made a mistake when testing:
Code: [Select]
if ($wm_normal > $destWidth ) {
$wm_resize = $CONFIG['picture_width'] / $wm_normal;
When I commented out my code to test it I also commented a line that I shouldn't have.  :-[ That code actually worked the same as:
Code: [Select]
if ($wm_normal > $CONFIG['picture_width'] ) {
$wm_resize = $CONFIG['picture_width'] / $wm_normal;
Large and small, portrait and landscape all had the same size mark and the mark was scaled to fit the small pic.

Anyway... sorry to make you waste your time trying to help me when I had already done what I wanted. BUT thanks for the lesson in PHP! Your solution is much more elegant than my own.

Salute!