vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.0 Full Releases (https://vborg.vbsupport.ru/forumdisplay.php?f=33)
-   -   Watermark images (on the fly) (https://vborg.vbsupport.ru/showthread.php?t=68112)

Robbban 08-18-2004 06:59 AM

It's been released :)

Wential 08-26-2004 08:03 AM

Nice! Now if I can just get the logo to watermark on the SouthEast corner instead of SouthWest...........

PAINTBALLM 10-21-2004 02:04 AM

on the fly cuts off an inch or so of my image.. and on ly shows the top 25% of the watermark logo

PAINTBALLM 10-21-2004 02:08 AM

going to try on upload hack but it looks like it is a little unsucessful as of right now too.

mhobelsb 10-23-2004 10:04 AM

hello... hack is working great.
I would like to write the Username of the Poster in the Image but if i use "$bbuserinfo['username']" the username of the user looking at the file is writen there. *G* (so if there is copyright at.... username it prints always the user who is watching it. not very handy. *G). Does anyone know how to get the username who really postet the image?

PAINTBALLM 10-25-2004 01:45 AM

it would be related to attachment ID (thinks)

leeman 11-13-2004 09:10 PM

Quote:

Originally Posted by kingady
i tried it but it doesnt reallty fit, it goes abit under the pic


Same here ...

I see only like 25% of the top of the watermark image...

Any suggestions someone ???? Palees (SP?)

Bandolero 11-19-2004 07:09 AM

I tried this hack, but the image is being cut-off at different places.

What I have been able to test is that by changing the last line of the hack I get different results: (regardless of the watermark being added or not)

imagejpeg($im, fetch_attachment_path($posterid, $attachmentid), 100);
cuts the image a lot but it displays fast.

imagejpeg($im, fetch_attachment_path($posterid, $attachmentid), 90);
cuts the image less but it begins to get slow

imagejpeg($im, fetch_attachment_path($posterid, $attachmentid), 80);
shows the entire image but so slow that it never finishes the page

It looks like the hack changes the jpeg and saves it leaving something out of wack.

Does anyone has any idea why this is?

steadicamop 02-03-2005 06:48 AM

It seems to work ok, until you get to the watermark image on the overlay, then it just stops, only half the watermark loads, when I refresh I get a load of random characters, I have to refresh again but it still doesn't work right ... I'm on VBB 5.0.5

triste 02-07-2005 06:10 AM

because the content-length header doesn't match the output. so the picture gets cut off while you increase the quality.

steadicamop 02-07-2005 11:13 AM

This is a peice of code that needs be altered as it shows above? I'm not too clued up on PHP but understand the basic stuff.

Thanx

Aidan 02-07-2005 08:49 PM

I made a few modifications to the code, as it's not really suitable for later versions of vBulletin 3.0.x. I made some alterations to support 3.0.6, as I'm trying to migrate a bunch of hacks across as part of an upgrade.

First of all, there's some code that spits out the content-length to tell the browser how large the file is. With current hack, the code spits out one content-length, and then an image with a different length. Some browsers get confused with this.

So, firstly, back up file you're going to edit!! This has been tested on a single forum, so it might well BREAK your forum if you try it.

Then, find the line that states (near the bottom)
Code:

header('Content-Length: ' . $attachmentinfo['filesize']);
and remove it. We'll replace it in another position later.

Once again, find the lines that state

Code:

        echo $attachmentinfo['filedata'];
And change them to be like the following
Code:

if ($extension == 'jpg' && !$thumb) {
        $filename = "path/to/the/file/vB3/watermark.png"; // use a PNG-24 to preserve transparency!

        $im = imagecreatefromstring($attachmentinfo['filedata']);
        imagealphablending($im, true);

        $watermark = imagecreatefrompng($filename);

        $y = imagesy($im) - imagesy($watermark); // select the bottom left (y of im less y of watermark)
        // if you want top left, you could use $y=0; instead
       
        $w = imagesx($watermark);
        $h = imagesy($watermark);
       
        imagecopy($im, $watermark, 0, $y, 0, 0, $w, $h);

        imagejpeg($im, "", 80);

        imagedestroy($watermark); // clean up after ourselves!
        imagedestroy($im);
        } else {

        header('Content-Length: ' . $attachmentinfo['filesize']);
        echo $attachmentinfo['filedata'];
}

Now, for some reason, I've got one or two images it doesn't seem to work right on. I have no idea why, and I'm hoping someone else might be able to give a hint or two? Also what would be good would be the ability to generate the appropriate content-length header, but again, I've no clue how to do that.

Hopefully Robbban will be able to incorporate some of these changes into an "offical" version - after all, it is his code!

triste 02-08-2005 06:53 AM

filesize the $attachpath, but it wouldn't work if your using the database for saving the attachments.

or this,

ob_start();
imagejpeg($im, "", 95);
header('Content-Length: ' . ob_get_length());
ob_end_flush();

i tried finding a function to find the size of an image resource, but didn't find one.

Aidan 02-08-2005 08:49 AM

I'm not sure that the code you suggest will work, although I haven't tried it. The problem is that the imagejpeg function appears to send the image to the browser.

We can't take the size of the file on the disk/database, as we've made modifications to the image, and hence it's size is different. This code is doing it on the fly, rather than storing it with the watermark in it.

noppid 02-08-2005 11:00 AM

Quote:

Originally Posted by triste
filesize the $attachpath, but it wouldn't work if your using the database for saving the attachments.

or this,

ob_start();
imagejpeg($im, "", 95);
header('Content-Length: ' . ob_get_length());
ob_end_flush();

i tried finding a function to find the size of an image resource, but didn't find one.


Use sizeof() to get a string length.
http://us4.php.net/manual/en/function.sizeof.php

noppid 02-08-2005 11:04 AM

Quote:

Originally Posted by Aidan
I'm not sure that the code you suggest will work, although I haven't tried it. The problem is that the imagejpeg function appears to send the image to the browser.

We can't take the size of the file on the disk/database, as we've made modifications to the image, and hence it's size is different. This code is doing it on the fly, rather than storing it with the watermark in it.

You are correct, imagejpeg does send to the browser, however OB() is output buffer and stuffs it in a var for you to echo it, so you can then work with it or use the example above.

There are alot of articles on image manipulation. All frown on the use of image manipulation on the fly. The bench marks on vBGarage doing image resize on the fly would have made you cringe. We have since changed it. Just a note.

triste 02-08-2005 04:38 PM

oh, right, can't use filesize. ob works for me. to think about it, the final output depends on imagejpeg, so there's no other way to get the size (i think). unless you make a temp file...

anyway, it does hurt performance on sites with large collection of images. but the fact that this hack works, an admin option could probably be added to switch on the fly/on upload/ or simply off for watermarking.

noppid 02-08-2005 06:13 PM

Quote:

Originally Posted by triste
oh, right, can't use filesize. ob works for me. to think about it, the final output depends on imagejpeg, so there's no other way to get the size (i think). unless you make a temp file...

PHP Code:


// get dimensions of image before popping it off.
$size_y imagesy($thumb['data']);
$size_x imagesx($thumb['data']);

// capture new image for streaming
ob_start();
imagejpeg($thumb['data'],'',75);                
$thumbdata ob_get_contents();
ob_end_clean();

// clean up GD
imagedestroy ($thumb['data']); 

//get filelength
$image_file_length strlen($thumbdata); 


Try that.

Aidan 02-09-2005 05:00 PM

Fantastic stuff - I'm learning here, which is good. I agree, the watermarking is heavy on the processor. Personally, I'd like to keep able to watermark images as they're uploaded. However, that still leaves me with plenty of images already in the system that need watermarking.

steadicamop 02-17-2005 08:34 PM

I've got it working on mine, pretty quickly too, and much better, the full picture loads, I don't know whats different either!

Just one thing, the watermark ends up in the bottom left hand corner, how do I move it to show in the bottom right hand corner? I have a Gallery installed and the watermarks show on the bottom right ... I just want it to look all the same.

Thanx!

<edit>
For whatever reason, on larger images it works fine, on smaller ones, it doesn't load correctly, I've only just discovered this, anyone have any ideas?
</edit>

triste 02-21-2005 07:18 PM

Code:

    $imx = imagesx($im);
    $imy = imagesy($im);
    $w = imagesx($watermark);
    $h = imagesy($watermark);
    $y = $imy - $h;
    $x = $imx - $w;

    imagecopy($im, $watermark, $x, $y, 0, 0, $w, $h);


from here, i think you get the concept. you use the the size of the watermark, and then subtract/add accordingly from the min/max size of the image being watermarked. (from left, x is 0, from right, x is imagesx())

Made correction on $h=...

noppid 02-21-2005 07:57 PM

Quote:

Originally Posted by triste
Code:

    $imx = imagesx($im);
    $imy = imagesy($im);
    $w = imagesx($watermark);
    $y = imagesy($watermark);
    $y = $imy - $h;
    $x = $imx - $w;

    imagecopy($im, $watermark, $x, $y, 0, 0, $w, $h);


from here, i think you get the concept. you use the the size of the watermark, and then subtract/add accordingly from the min/max size of the image being watermarked. (from left, x is 0, from right, x is imagesx())


Check your work. $y is being stepped on or set once uselessly.

steadicamop 03-03-2005 06:41 PM

How do you get the watermark on the right? I read the above, but can't make head nor tail of it! Sorry to sound stupid, just confused....

Thanks, the revised code works like a charm!

<edit>
Sorry for my stupidity, I used the above code and it works perfectly!
</edit>

v8news 03-06-2005 05:37 AM

I have sent Robbban a PM can you please get back to me ASAP.

Robbban 04-12-2005 10:59 AM

Checked and works for 3.0.7!

Osiris2k 05-29-2005 09:00 PM

Quote:

Originally Posted by Robbban
Checked and works for 3.0.7!

isnt working for me :( 3.0.7

I did exactly what it said but it didnt do anything...and I have the right path to the watermark

nvm its working for attachements but not for vbgarage?

mustang_lex 06-14-2005 07:45 PM

Does anyone have this hack working successfully for 3.0.7? I like to implement on my site

aalspach 08-02-2005 12:05 AM

After you have installed the hack, add an image attachment.... and submit new thread.... then click on thumbnail in thread for the first time.... does it take a while to upload images on your site? it does on my site.

Denno 08-04-2005 10:06 AM

Works just fine here 3.0.7.

Not sure if it loads harder or not.

Denno 08-04-2005 10:27 AM

Hmm take that back..it dont watermark the pictures all the time...
Just cut them.

b00k 08-08-2005 01:07 AM

as everyone else has stated. it does work in 3.0.7 large images, cuts off smaller ones and reduces load speed. *uninstalls*

Nice try tho, better than i could do.

steadicamop 10-11-2005 06:58 AM

Is anyone aware if this will work on 3.5 - I used this on 3.0.7 and it worked well, just haven't seen it floating around for 3.5 ..... I'm unsure whether to try it in the code or not.

Thanks!

Jason

RZ500 10-12-2005 03:21 PM

Quote:

Originally Posted by steadicamop
Is anyone aware if this will work on 3.5 - I used this on 3.0.7 and it worked well, just haven't seen it floating around for 3.5 ..... I'm unsure whether to try it in the code or not.

Thanks!

Jason

Same here, help for 3.5 please

tyfoon 10-13-2005 08:23 AM

it works in 3.5 ( but its in the code and not in a plugin because there is no hook for is)

RZ500 10-13-2005 01:47 PM

Quote:

Originally Posted by tyfoon
it works in 3.5 ( but its in the code and not in a plugin because there is no hook for is)

Thanks I'm going to try it.

steadicamop 10-13-2005 01:56 PM

Quote:

Originally Posted by tyfoon
it works in 3.5 ( but its in the code and not in a plugin because there is no hook for is)

I tried it in the code, but it didn't work, made no difference, can you post which piece of code needs removing/changing please?

Thanks

Jason

honguyen 10-23-2005 08:27 PM

Hi, i wonder if this work for the V.3.0.8 ? thanks alot, nice mod i have been looking 4 :)

Smiry Kin's 12-19-2005 12:21 PM

something like this for 3.5.2 would be great

croportal 12-24-2005 09:08 AM

anoyne know how to implement to 3.5.0

thanks

mustang_lex 12-29-2005 07:42 PM

Does it add the watermark to signature images as well?


All times are GMT. The time now is 09:29 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01458 seconds
  • Memory Usage 1,830KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_code_printable
  • (1)bbcode_php_printable
  • (9)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete