Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > vBulletin 2.x > vBulletin 2.x Full Releases

 
 
Thread Tools
Auto resizing of avatars Details »»
Auto resizing of avatars
Version: 1.00, by Dmitriy Dmitriy is offline
Developer Last Online: Dec 2002 Show Printable Version Email this Page

Version: 2.2.x Rating:
Released: 10-16-2002 Last Update: Never Installs: 24
 
No support by the author.

Those of you with busy boards know that a lot of times users don't have a clue of how to re-size the
pictures they want to use as avatars.

Someone may want to use a cool pic he has on the hard drive, but the picture size is too big and
user gets error message when trying to upload it as avatar. Many users don't know how to re-size the
picture and they will just give up and nevere upload the avatar.

I was ignoring this for too long, but now I came up with the solution:

This hack will re-size the uploaded avatar on the fly, meaning there are no error messages
when the picture is too large, it will be re-sized automatically before it's inserted into the
database



open the member.php file
find thess lines:

if ($imginfo[0]>$avatarmaxdimension or $imginfo[1]>$avatarmaxdimension) {
@unlink($filename);
eval("standarderror(\"".gettemplate("error_avatarb addimensions")."\");");
}


replace with these lines:

if ($imginfo=@getimagesize($filename)) {
if ($imginfo[0]>$avatarmaxdimension or $imginfo[1]>$avatarmaxdimension) {

$image_width = $imginfo[0];
$image_height= $imginfo[1];
if ($image_height > $image_width)
{
$sizefactor = (double) ($avatarmaxdimension / $image_height);
}
else
{
$sizefactor = (double) ($avatarmaxdimension / $image_width) ;
}


$newwidth = (int) ($image_width * $sizefactor);
$newheight = (int) ($image_height * $sizefactor);

$newsize = $newwidth . "x" . $newheight;

$cmd = "/usr/local/bin/mogrify -resize $newsize "."$filename 2>&1";

exec($cmd, $exec_output, $exec_retval);
if($exec_retval > 0)
{
print "ERROR: exec() error: $exec_output[0]";
}
else
{
print "<P align=\"center\"><b>Image was resized from " . $image_width . "x" .
$image_height . " to $newsize</p>";
}

}

That's all.

Now make sure in your control panel to set a really large max file size in the avatar options because
people may now use any size pictures, so the file size may possibly be over 500K
Don't worry, after the avatar is re-sized, the new file size will be really small.

This hack uses the Mogrify utility from ImageMagick, which is free from imagemagick.org

I have this hack installed on www.examnotes.net/forums

You need at least 1 post in order to upload avatar.

Show Your Support

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

Comments
  #12  
Old 10-17-2002, 05:14 PM
Talisman's Avatar
Talisman Talisman is offline
 
Join Date: Aug 2002
Location: USA/West Coast
Posts: 371
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
It should work with any version of 2.2.X but you MUST have the ImageMagick installed on your server with support for GIF and JPG format.
Ok, that's it then. Thanks.
Reply With Quote
  #13  
Old 10-17-2002, 05:22 PM
Dean C's Avatar
Dean C Dean C is offline
 
Join Date: Jan 2002
Location: England
Posts: 9,071
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

awesome idea mate !

- miSt
Reply With Quote
  #14  
Old 10-17-2002, 07:12 PM
Crinos's Avatar
Crinos Crinos is offline
 
Join Date: Oct 2001
Location: Los Angeles, CA
Posts: 151
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

hmmm ... it's a bummer that I need to specify a bigger file size beforehand for this hack to work ... I keep max avatar file sizes at 7Kb, to discourage people from using those animated GIFs that may fulfill the dimension requirements, but are almost 50Kb+ in size...

So, great hack, but I'll pass
Reply With Quote
  #15  
Old 10-23-2002, 05:37 AM
alkatraz alkatraz is offline
 
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 384
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thx!
where do I add the attachment hack tho?
Reply With Quote
  #16  
Old 10-23-2002, 10:38 AM
Chris M's Avatar
Chris M Chris M is offline
 
Join Date: Dec 2001
Location: Northampton, England
Posts: 6,186
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

admin/functions.php

Satan
Reply With Quote
  #17  
Old 10-29-2002, 12:58 AM
Okiewan's Avatar
Okiewan Okiewan is offline
 
Join Date: Dec 2001
Posts: 199
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'd REALLY like to implement the attachment code mentioned above... not sure what code to replace in admin/functions.php ...

This?

PHP Code:
    if ($extension=="gif" or $extension=="jpg" or $extension=="jpeg" or $extension=="jpe" or $extension=="png" or $extension=="swf") { // Picture file
      
if ($imginfo=@getimagesize($attachment)) {
        if ((
$maxattachwidth>and $imginfo[0]>$maxattachwidth) or ($maxattachheight>and $imginfo[1]>$maxattachheight)) {
          eval(
"standarderror(\"".gettemplate("error_attachbaddimensions")."\");");
        }
        if (!
$imginfo[2]) {
           eval(
"standarderror(\"".gettemplate("error_avatarnotimage")."\");");
        }
      } elseif (!
$allowimgsizefailure) {
          eval(
"standarderror(\"".gettemplate("error_avatarnotimage")."\");");
      }
    } 
Reply With Quote
  #18  
Old 12-02-2002, 01:09 PM
Jesus Chio Jesus Chio is offline
 
Join Date: Oct 2002
Location: Near Hell, TX
Posts: 16
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

me too, anyone?
Reply With Quote
  #19  
Old 12-02-2002, 07:29 PM
Sebastian's Avatar
Sebastian Sebastian is offline
 
Join Date: Oct 2002
Location: America
Posts: 488
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Dmitriy: I like the idea for resizing attachment images.. is it possible to make the image click-able, lets say I upload an 1280* picture, have it resize to 640* but when the user clicks it they can see the orginal size.. this would be useful.
Reply With Quote
  #20  
Old 02-13-2003, 01:26 AM
msimplay's Avatar
msimplay msimplay is offline
 
Join Date: Aug 2002
Location: UK
Posts: 1,059
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by Okiewan
I'd REALLY like to implement the attachment code mentioned above... not sure what code to replace in admin/functions.php ...

This?

PHP Code:
    if ($extension=="gif" or $extension=="jpg" or $extension=="jpeg" or $extension=="jpe" or $extension=="png" or $extension=="swf") { // Picture file
      
if ($imginfo=@getimagesize($attachment)) {
        if ((
$maxattachwidth>and $imginfo[0]>$maxattachwidth) or ($maxattachheight>and $imginfo[1]>$maxattachheight)) {
          eval(
"standarderror(\"".gettemplate("error_attachbaddimensions")."\");");
        }
        if (!
$imginfo[2]) {
           eval(
"standarderror(\"".gettemplate("error_avatarnotimage")."\");");
        }
      } elseif (!
$allowimgsizefailure) {
          eval(
"standarderror(\"".gettemplate("error_avatarnotimage")."\");");
      }
    } 
i want to know where to put the code aswell
Reply With Quote
  #21  
Old 03-08-2003, 02:46 AM
LangTuDaTinh LangTuDaTinh is offline
 
Join Date: Dec 2001
Posts: 159
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i have ImageMagick installed

no parse error but each time i upload in image

it will display "ERROR: exec() error:" but do not display which error after that line when it forwarding to my edit option page.

please help
thanks
Reply With Quote
 

Thread Tools

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 02:44 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.05196 seconds
  • Memory Usage 2,320KB
  • 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
  • (2)bbcode_php
  • (2)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
  • (2)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