vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 3.6 Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=194)
-   -   Add-On Releases - Attached Image Watermarking PLUS Guest Viewing of Thumbnails (https://vborg.vbsupport.ru/showthread.php?t=141883)

ConqSoft 03-11-2007 10:00 PM

Attached Image Watermarking PLUS Guest Viewing of Thumbnails
 
I had been looking for these two options for quite a while, and was finally able to hire Brian (of vBadvanced) to write them for me. Since a lot of people have been looking for this, I have decided (with Brian's permission) to release this as a free, unsupported, modification.

This modification will allow you to specify a watermark image that will be overlayed over any attached JPG or PNG file on your site in real time, as the image is displayed. NO PERMANENT CHANGES ARE MADE TO ANY OF YOUR ATTACHMENTS. You can also exclude specific forums and usergroups from seeing the watermark.

As an added bonus, he included the ability to allow guests to see attached image thumbnails, while still requiring them to register to see the full size attachments. (Make sure you have your Unregistered / Not Logged In usergroup set to NOT have access to download attachments.)

PLEASE CLICK INSTALL so that maybe Jelsoft will include these as built-in features in a future version.

Notes/Troubleshooting:
  • Your server needs to have GD2 installed.
  • Attachments must be stored in the file system. Database storage of file attachments will not work.
  • Make sure you use the full PHYSICAL path to your watermark image.
  • Make sure you have a low number in the width/height setting. (I use 200, since my watermark image is 150 pixels wide.)
  • If you have previously viewed the attached image, your browser may cache it, so you will need to clear your browser cache or force a hard refresh (CTRL-F5) while viewing the image to get the new watermarked version.


Well, on to the modification:

=============================================
STEP 1:
Since the resulting file contains too much vBulletin code, I am unable to include it with this modification. So, the first step is to copy vBulletin's attachment.php to a file named attachment_watermark.php. Then, edit attachment_watermark.php, making the following changes.

=============================================
STEP 2:
You need to delete a LOT of lines from the top of the file. Find this line...
Code:

$idname = $vbphrase['attachment'];
...and delete everything ABOVE it other than the <?php line at the top of the file.

Your attachment_watermark.php file should begin with this code when you've completed this step:
Code:

<?php
$idname = $vbphrase['attachment'];


=============================================
STEP 3:
Find this line of code:
Code:

if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['cangetattachment']) OR (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND ($attachmentinfo['postuserid'] != $vbulletin->userinfo['userid'] OR $vbulletin->userinfo['userid'] == 0)))
REPLACE with this code:
Code:

if (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canview']) OR !($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewthreads']) OR (!($forumperms & $vbulletin->bf_ugp_forumpermissions['cangetattachment']) AND !$vbulletin->GPC['thumb'])  OR (!($forumperms & $vbulletin->bf_ugp_forumpermissions['canviewothers']) AND ($attachmentinfo['postuserid'] != $vbulletin->userinfo['userid'] OR $vbulletin->userinfo['userid'] == 0)))

=============================================
STEP 4:
Find these lines of code:
Code:

        else
        {
                $attachpath = fetch_attachment_path($attachmentinfo['userid'], $attachmentinfo['attachmentid']);

Add this code BELOW the lines referenced above:
Code:

// #########################################
// ##### Start modified section for watermarks
// #########################################

$vbulletin->options['attach_water_exforums'] = explode(',', $vbulletin->options['attach_water_exforums']);
$vbulletin->options['attach_water_exgroups'] = explode(',', $vbulletin->options['attach_water_exgroups']);


if ($vbulletin->options['attach_water_filelocation']
        AND in_array($extension, array('jpg', 'jpeg', 'png'))
        AND !in_array($attachmentinfo['forumid'], $vbulletin->options['attach_water_exforums'])
        AND !array_intersect(fetch_membergroupids_array($vbulletin->userinfo), $vbulletin->options['attach_water_exgroups'])
)
{
        $attachsize = getimagesize($attachpath);

        if ($attachsize[0] >= $vbulletin->options['attach_water_minsize'] AND $attachsize[1] >= $vbulletin->options['attach_water_minsize'])
        {
                $waterimage =& $vbulletin->options['attach_water_filelocation'];
                $watersize = getimagesize($waterimage);

                $waterext = strtolower(substr($waterimage, strrpos($waterimage, '.') + 1));

                // Coordinates (height)
                switch ($vbulletin->options['attach_water_coordinates'][0])
                {
                        case 'n':
                                $waterpos['height'] = 0 + $vbulletin->options['attach_water_padding'];
                        break;
                        case 'm':
                                $waterpos['height'] = round(($attachsize[1] - $watersize[1]) / 2);
                        break;
                        case 's':
                                $waterpos['height'] = round(($attachsize[1] - $watersize[1])) - $vbulletin->options['attach_water_padding'];
                        break;
                }

                // Coordinates (width)
                switch ($vbulletin->options['attach_water_coordinates'][1])
                {
                        case 'w':
                                $waterpos['width'] = 0 + $vbulletin->options['attach_water_padding'];
                        break;
                        case 'c':
                                $waterpos['width'] = round(($attachsize[0] - $watersize[0]) / 2);
                        break;
                        case 'e':
                                $waterpos['width'] = round(($attachsize[0] - $watersize[0])) - $vbulletin->options['attach_water_padding'];
                        break;
                }

                // Watermark ext
                switch ($waterext)
                {
                        case 'jpg':
                        case 'jpeg':
                                $watermark = imagecreatefromjpeg($waterimage);
                        break;

                        case 'png':
                                $watermark = imagecreatefrompng($waterimage);
                        break;
                }

                // Attachment ext
                switch ($extension)
                {
                        case 'jpg':
                        case 'jpeg':
                                $attachimage = imagecreatefromjpeg($attachpath);
                        break;

                        case 'png':
                                $attachimage = imagecreatefrompng($attachpath);
                        break;
                }

                imagealphablending($attachimage, true);

                $watermark_width = imagesx($watermark);
                $watermark_height = imagesy($watermark);

                imagecopy($attachimage, $watermark, $waterpos['width'], $waterpos['height'], 0, 0, $watersize[0], $watersize[1]);
                define('WATERMARKED', true);
        }
}
// #########################################
// ##### End modified section for watermarks
// #########################################


=============================================
STEP 5:
Find this line of code:
Code:

header('Content-Length: ' . (($lastbyte + 1) - $startbyte));
REPLACE with this code:
Code:

// #########################################
// ##### Start modified section for watermarks
// ##### Changed to prevent filesize header on watermarked images
// #########################################
if (!defined('WATERMARKED'))
{
        header('Content-Length: ' . (($lastbyte + 1) - $startbyte));
}
// #########################################
// ##### End modified section for watermarks
// #########################################


=============================================
STEP 6:
Find this line of code:
Code:

($hook = vBulletinHook::fetch_hook('attachment_display')) ? eval($hook) : false;
REPLACE with this code:
Code:

// #########################################
// ##### Start modified section for watermarks
// #########################################
if (!$vbulletin->GPC['thumb'] AND defined('WATERMARKED'))
{
        imagejpeg($attachimage);
        imagedestroy($attachimage);
        imagedestroy($watermark);
}
// #########################################
// ##### End modified section for watermarks

=============================================
STEP 7:
Find this line of code:
Code:

($hook = vBulletinHook::fetch_hook('attachment_complete')) ? eval($hook) : false;
REPLACE with this code:
Code:

exit;

=============================================
STEP 8:
Save and upload attachment_watermark.php to your forum root directory.


=============================================
STEP 9:
Install the product-attach_watermark.xml Product via the vBulletin AdminCP Product Manager.


=============================================
STEP 10:
Configure the options at AdminCP -> vBulletin Options -> Attachment Watermarks. All fields should be self-explanatory.

nexialys 03-12-2007 08:34 PM

kinda cool, i think i will tweak on it.. ;)

Kanustep 03-12-2007 08:41 PM

Sound interesting, thank you ConqSoft.

FleaBag 03-12-2007 08:44 PM

A fantastic tool to drive registration on 2 fronts. Very kind of you to release it, thanks.

PKRWUD 03-12-2007 09:02 PM

I installed it, but it's not showing up. Does the watermark itself have to be a .jpg or .png file? I used a .gif file.

*edit*

I tried it with a .png file, and still no luck.

ConqSoft 03-12-2007 09:10 PM

A transparent .PNG is the best thing to use for the watermark.

Gryphon 03-12-2007 09:11 PM

jpg or png for watermark. However, I can't get it to work either.

ConqSoft 03-12-2007 09:14 PM

Your server needs GD2 installed also. (Edited above.)

It's possible that I made a mistake with the modification instructions. Since I just have the fully modified file, I had to build the change instructions from that. I'll look over it and see if I missed anything. It would be much easier to just include the file, but it may violate site policy since it contains a lot of original vBulletin code.

ConqSoft 03-12-2007 09:20 PM

Ok, I found two errors. Please re-do steps 5 and 6.

Ntfu2 03-12-2007 09:32 PM

Conq if this works, and you ever want to have kids, i'll have them for you :D

ConqSoft 03-12-2007 09:43 PM

Quote:

Originally Posted by Ntfu2 (Post 1201995)
Conq if this works, and you ever want to have kids, i'll have them for you :D

Let me know. Still need to make sure I don't have any other mistakes in the file editing instructions above. It's working fine on 3 of my sites, and one other site.

Gryphon 03-12-2007 09:52 PM

Still haven't been able to get it working, have edited completely twice.

GD 2.0.28

Step 5 contains an extra brace at the end of the find string, not that it matters much.

ConqSoft 03-12-2007 09:54 PM

Are you using the full PHYSICAL path to the watermark file, and do you have the width/height setting set to something low enough to affect your images, and are your attachments stored in the file system?

Also, if you have viewed the attachment previously, it may be cached. Make sure you clear your browser cache.

Gryphon 03-12-2007 10:01 PM

Ah, I didn't realize they had to be stored as files. I thought I had seen a specification on the request to use the database.

I am sure all is correct, I have written my own watermarking previously, however it is a project outside of vBulletin and uses ImageMagick.

ConqSoft 03-12-2007 10:01 PM

Quote:

Originally Posted by Blackjack (Post 1202014)
Step 5 contains an extra brace at the end of the find string, not that it matters much.

Fixed, thanks. It would make a difference, if you replaced the brace too. ;)

ConqSoft 03-12-2007 10:02 PM

Quote:

Originally Posted by Blackjack (Post 1202024)
Ah, I didn't realize they had to be stored as files. I thought I had seen a specification on the request to use the database.

I am sure all is correct, I have written my own watermarking previously, however it is outside of vBulletin and uses ImageMagick.

Well, I haven't tested it with attachments in the database, because I don't have any sites that use that method. I much prefer to store them in the file system. So, that could be the issue.

ConqSoft 03-12-2007 10:15 PM

If anyone gets this working, please reply so that I know the instructions are correct. Thanks.

ZomgStuff 03-12-2007 10:32 PM

Wow, thanks!

PKRWUD 03-12-2007 11:53 PM

I redid the necessary steps, and double checked everything, and it's all done as required, and still no luck, however my attachments are not stored as files. I'm guessing that must be the problem I'm having.

Lionel 03-13-2007 01:56 AM

I just downloaded and am praying that it works with database attachments. Anyway, that was very nice of you to share this much needed feature.

Lionel 03-13-2007 03:16 AM

Unfortunately, it did not work for me with attachments in database.

funkmeister 03-13-2007 04:49 AM

Quote:

Originally Posted by ConqSoft (Post 1202032)
If anyone gets this working, please reply so that I know the instructions are correct. Thanks.

Hi - it worked first time for me - many thanks, as I have been looking for this feature for a very long time - much appreciate the effort of all involved.

ninjamaster 03-13-2007 07:47 AM

thanks for this it looks good :)

milsirhc 03-13-2007 09:46 AM

many thanks for this mod! been looking for it a long time!

before i start implementing it, does this work with the highslide attachment mod?

Jelmertjee 03-13-2007 11:09 AM

thanks very much, although some users seem to have trouble with getting this to work I had no problems at all.
(i'm using filesystem attachments, which is better anyway..)

MrNase 03-13-2007 12:26 PM

Should the original attachment.php stay or can we delete it?

ConqSoft 03-13-2007 12:55 PM

It needs to stay also. This is just a new file that uses a lot of code from attachment.php because they're weren't enough hooks to do everything he needed to do.

Lionel 03-13-2007 01:23 PM

So far it's seems to be only 2 of us with problems. Has someone managed to use with attachments in database?

ConqSoft 03-13-2007 01:30 PM

Quote:

Originally Posted by Lionel (Post 1202513)
So far it's seems to be only 2 of us with problems. Has someone managed to use with attachments in database?

No, it does not work with attachments in the database. This has been confirmed, and I updated the modification instructions at the top.

Bulent Tekcan 03-13-2007 09:43 PM

Is this plugin works with .gif extension ?

Thanks

ConqSoft 03-13-2007 09:46 PM

Quote:

Originally Posted by Bulent Tekcan (Post 1202844)
Is this plugin works with .gif extension ?

Thanks

Not currently, though it should be pretty easy to add that to the IF statement, CASE statement, and use the PHP imagecreatefromgif() function I would think.

Bulent Tekcan 03-13-2007 10:50 PM

Quote:

Originally Posted by ConqSoft (Post 1202850)
Not currently, though it should be pretty easy to add that to the IF statement, CASE statement, and use the PHP imagecreatefromgif() function I would think.


I'm already add .gif extension,and works fine on my test boards.I'll hard test on my test forum 2-3 days then apply production forum.

Thanks

project-Buckfas 03-14-2007 11:46 AM

Thanks ConqSoft

I've wanted this for a whlle now!

Karabaja 03-14-2007 04:12 PM

Thanks for sharing this. I'll give it a go as soon as I get a chance.

sensimilla 03-14-2007 08:18 PM

sorry its ok...

Thanks for the nice hack!

goblues 03-14-2007 09:03 PM

Right on! I have been following your request for this. Thanks for sharing!

Kahuna900 03-14-2007 09:26 PM

Thanks Keith,

Instructions were perfect and everyting is working great on all my forums.

benjaminkramer 03-15-2007 05:09 PM

Thanks for your Plugin.

I want that a guest can view the thumbnails but not the full full size oft it.
But it does not work.

My stettings:
Guests to View Thumbnails yes
Unregistered / Not Logged In usergroup set to NOT have access to download attachments

ConqSoft 03-15-2007 05:41 PM

Did you follow all the steps? The attachment_watermark.php file is still required for the Guest Thumbnail feature also. Though, you can just leave the watermark fields empty if you don't want to use that part.

benjaminkramer 03-15-2007 05:45 PM

yes I did
here is my attachment_watermark.php


All times are GMT. The time now is 06:02 PM.

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.01940 seconds
  • Memory Usage 1,851KB
  • 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
  • (12)bbcode_code_printable
  • (7)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