Question about variable size watermarks Question about variable size watermarks
 

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

Main Menu

Question about variable size watermarks

Started by erostew, October 27, 2007, 10:04:29 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

erostew

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.

Stramm

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)

erostew

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.

Stramm

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

erostew

I managed to partly get what I wanted.

I changed
if ($wm_normal > $destWidth ) {
$wm_resize = (int)(($destWidth / $wm_normal) * 100);

into
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

erostew

Ok I think I have it solved now! Just had to declare a new variable and use it in the size calc.

I replaced
//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
//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

erostew

Quote from: 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)
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

Stramm

#7
if you use GD2, find in picmgmnt.inc.php
if ($wm_normal > $destWidth ) {
$wm_resize = $destWidth / $wm_normal;

and replace with
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

erostew

Quote from: Stramm on October 29, 2007, 10:06:20 AM
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.

Stramm

I've corrected the above and tested it. Worked for me (GD2).

erostew

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



Stramm

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

if ($wm_normal > max($destWidth, $destHeight) ) {
$wm_resize = max($destWidth, $destHeight) / $wm_normal;

erostew

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:
if ($wm_normal > max($destWidth, $destHeight) ) {
$wm_resize = max($destWidth, $destHeight) / $wm_normal;

works exactly the same as my much longer code:
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:
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:
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!