Smart Image Resize SP1.4 Beta 7 This mod uses javascript to resize avatars and pictures inserted using the [img] tag if they exceed a maximum size, while maintaining the original aspect ratio of the image. Install Instructions: 1..Apply the mod as usual (Consult the BoardMod FAQ if you are unsure how to do this). 2..If you would like to restrict the size of attached images, install the "File Attachments" patch file. 3..Upload the modified files to your server. 4..Go to the "Forum Preferences and Settings" and set the values for the maximum image sizes. Notes: 1..The maximum allowed image width and height are set in the forum preferences and settings admin area. 2..There are seperate settings for: images in messages and images in signatures. 3..The [img] tag can now contain width=???, height=???, align=??? and alt=??? attributes in any order or combination. 4..The align attribute can take the standard align values of the tag (left, right, top, texttop, middle, absmiddle, baseline, bottom, absbottom). 5..If you specify the width or height, the image will be resized to that width or height while maintaining the aspect ratio of the original image. 6..If you specify both the width and height, the image will be resized to the size specified, adopting the specified aspect ratio. 7..If the image exceeds the maximum allowed size, it will be resized to the maximum allowed size while maintaining it's original aspect ratio or the specified aspect ratio. 8..If the users browser does not support javascript, the normal (unresized) image will be displayed. 9..Now includes the [img] tag bugfix by Michael Prager, and images are restricted to files with a .gif, .jpg, .png or .bmp extension. BHRA Webmaster http://www.bhra.org.uk #################################################################################### template.html #################################################################################### english.lng $txt{'476'} = "Userpic Width (0 = disable limit)"; $txt{'477'} = "Userpic Height (0 = disable limit)"; $txt{'476a'} = "Maximum Userpic Size (0 = disable limit)"; $txt{'476b'} = "Maximum Image Size (0 = disable limit)"; $txt{'476c'} = "Maximum Signature Image Size (0 = disable limit)"; $txt{'477a'} = "Width:"; $txt{'477b'} = "Height:"; #################################################################################### Sources/AdminEdit.pl $txt{'476'} $txt{'477'} $txt{'476b'} $txt{'477a'}     $txt{'477b'} $txt{'476c'} $txt{'477a'}     $txt{'477b'} $txt{'476a'} $txt{'477a'}     $txt{'477b'} if ($FORM{'userpic_width'} =~ /^\d+$/) { $userpic_width = $FORM{'userpic_width'}; } else { $userpic_width = 65; } if ($FORM{'MAXIMGWIDTH'} =~ /\d+/) { $MAXIMGWIDTH = $FORM{'MAXIMGWIDTH'}; } else { $MAXIMGWIDTH = 0; } if ($FORM{'MAXIMGHEIGHT'} =~ /\d+/) { $MAXIMGHEIGHT = $FORM{'MAXIMGHEIGHT'}; } else { $MAXIMGHEIGHT = 0; } if ($FORM{'MAXSIGWIDTH'} =~ /\d+/) { $MAXSIGWIDTH = $FORM{'MAXSIGWIDTH'}; } else { $MAXSIGWIDTH = 0; } if ($FORM{'MAXSIGHEIGHT'} =~ /\d+/) { $MAXSIGHEIGHT = $FORM{'MAXSIGHEIGHT'}; } else { $MAXSIGHEIGHT = 0; } \$userpic_width = $userpic_width; # Set pixel size to which the selfselected userpics are resized, 0 disables this limit \$MAXIMGWIDTH = $MAXIMGWIDTH; # Set maximum pixel width for images, 0 disables this limit \$MAXIMGHEIGHT = $MAXIMGHEIGHT; # Set maximum pixel height for images, 0 disables this limit \$MAXSIGWIDTH = $MAXSIGWIDTH; # Set maximum pixel width for images in the signature, 0 disables this limit \$MAXSIGHEIGHT = $MAXSIGHEIGHT; # Set maximum pixel height for images in the signature, 0 disables this limit #################################################################################### Sources/PrintPage.pl $char_160 = chr(160); $threadpost =~ s~\[img\][\s*\t*\n*( )*($char_160)*]*(http\:\/\/)*(.+?)[\s*\t*\n*( )*($char_160)*]*\[/img\]~http://$2~isg; $threadpost =~ s~\[img width=(\d+) height=(\d+)\][\s*\t*\n*( )*($char_160)*]*(http\:\/\/)*(.+?)[\s*\t*\n*( )*($char_160)*]*\[/img\]~http://$4~isg; $char_160 = chr(160); $threadpost =~ s~\[img(.*?)\](?:\s|\t|\n| |$char_160)*(?:http(s)?\:\/\/)*(.+?)(?:\s|\t|\n| |$char_160)*\[/img\]~http$2://$3~isg; #################################################################################### Sources/YaBBC.pl $MAXIMGWIDTH = 400; $MAXIMGHEIGHT = 500; sub restrictimage { my($w,$h,$s) = @_; $w = $w <= $MAXIMGWIDTH ? $w : $MAXIMGWIDTH; $h = $h <= $MAXIMGHEIGHT ? $h : $MAXIMGHEIGHT; return qq~~; } $MAXIMGWIDTH = $MAXIMGWIDTH || 0; $MAXIMGHEIGHT = $MAXIMGHEIGHT || 0; sub restrictimage { my($tmpstuff,$s) = @_; if ($s !~ m/^http(s)?\:\/\/.*\.(gif|jpg|jpeg|png|bmp)$/i) {return qq~$s~;} my ($dummy, $key, $value, $a, $b, $c); undef %parameter; foreach $dummy (split(/\s+/, $tmpstuff)) { ($key, $value) = split(/=/,$dummy); &FromHTML($value); $parameter{$key} = $value; } $parameter{'width'} =~ s~\D~~g; $parameter{'height'} =~ s~\D~~g; $parameter{'align'} =~ s~\W~~g; &ToHTML($parameter{'alt'}); $parameter{'alt'} =~ s~_~ ~g; if ($parameter{'align'} eq "") {$a = "";} else {$a = qq~ align="$parameter{'align'}"~;} if ($parameter{'width'} eq "") {$b = "";$parameter{'width'} = "0";} else {$b = qq~ width="$parameter{'width'}"~;} if ($parameter{'height'} eq "") {$c = "";$parameter{'height'} = "0";} else {$c = qq~ height="$parameter{'height'}"~;} return qq~$parameter{'alt'}~; } $char_160 = chr(160); $message =~ s~\[img\](?:\s|\t|\n|$hardspace|$char_160)*(http\:\/\/)*(.+?)(?:\s|\t|\n|$hardspa ce|$char_160)*\[/img\]~check_image("http://$2")~eisg; $message =~ s~\[img width=(\d+) height=(\d+)\](?:\s|\t|\n|$hardspace|$char_160)*(http\:\/\/)*(.+?)(?:\s|\t|\n|$hardspace|$char_160)*\[/img\]~restrictimage($1,$2,'http://'.$4)~eisg; $char_160 = chr(160); $message =~ s~\[img(.*?)\](?:\s|\t|\n| |$char_160)*(?:http(s)?\:\/\/)*(.+?)(?:\s|\t|\n| |$char_160)*\[/img\]~restrictimage($1, 'http'.$2.'://'.$3)~eisg; #################################################################################### ### The following step resizes the user's signature ### #################################################################################### Sources/Load.pl if($enable_ubbc) { if(!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } &DoUBBC; } if($enable_ubbc) { $tmp_max_width = $MAXIMGWIDTH; $tmp_max_height = $MAXIMGHEIGHT; # store maximum image size $MAXIMGWIDTH = $MAXSIGWIDTH; $MAXIMGHEIGHT = $MAXSIGHEIGHT; # set limits to maximum signature size if(!$yyYaBBCloaded) { require "$sourcedir/YaBBC.pl"; } &DoUBBC; $MAXIMGWIDTH = $tmp_max_width; $MAXIMGHEIGHT = $tmp_max_height; # restore maximum image size } #################################################################################### ### The following steps resize the user's avatar ### #################################################################################### Sources/Load.pl $userprofile{$user}->[13] = $userprofile{$user}->[13] =~ m~\A[\s\n]*http://~i ? qq~


~ : qq~

~;
$userprofile{$user}->[13] = $userprofile{$user}->[13] =~ m~\A[\s\n]*http://~i ? qq~


~ : qq~

~;
#################################################################################### Sources/Profile.pl $pic .= qq~~; $pic .= qq~~;