Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 3.0 > vBulletin 3.0 Full Releases
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Watermark images (on the fly) Details »»
Watermark images (on the fly)
Version: 1.00, by Robbban Robbban is offline
Developer Last Online: Oct 2005 Show Printable Version Email this Page

Version: 3.0.3 Rating:
Released: 08-07-2004 Last Update: Never Installs: 42
 
No support by the author.

This is something i made because I couldn't find any hack working for 3.0.7. Just took a couple of minutes.


Works with 3.0.7!

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #52  
Old 02-07-2005, 11:13 AM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #53  
Old 02-07-2005, 08:49 PM
Aidan Aidan is offline
 
Join Date: Feb 2005
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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!
Reply With Quote
  #54  
Old 02-08-2005, 06:53 AM
triste triste is offline
 
Join Date: Jan 2005
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #55  
Old 02-08-2005, 08:49 AM
Aidan Aidan is offline
 
Join Date: Feb 2005
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #56  
Old 02-08-2005, 11:00 AM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #57  
Old 02-08-2005, 11:04 AM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #58  
Old 02-08-2005, 04:38 PM
triste triste is offline
 
Join Date: Jan 2005
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #59  
Old 02-08-2005, 06:13 PM
noppid noppid is offline
 
Join Date: Mar 2003
Location: Florida
Posts: 1,875
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #60  
Old 02-09-2005, 05:00 PM
Aidan Aidan is offline
 
Join Date: Feb 2005
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #61  
Old 02-17-2005, 08:34 PM
steadicamop's Avatar
steadicamop steadicamop is offline
 
Join Date: Jul 2004
Location: Lancashire, UK
Posts: 379
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:40 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05651 seconds
  • Memory Usage 2,311KB
  • Queries Executed 25 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (3)bbcode_code
  • (1)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (11)post_thanks_box
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete