Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Sign In
Not a member yet? Click here to register.

Autoresize big images

Your layout forum being crashed because of big images attachments? Or by IMG bbcodes links to big images? Or your users using big images in their signatures? Here's solution :)

1) if you're using PF v6.01.x add dropped isImage() function to your maincore.php again - if your PF version <v6.01.x replace existing isImage() function:

CodeDownload  
// Validate bbcode images
function isImage($matches) {
   if (!isNum($matches[1])) {
      $img = $matches[1].str_replace(array("?","&","="),"",$matches[3]).$matches[4];
      if ($size=@getimagesize($img)) {
         if ($size[0]>400) {
            $y_prop = ceil($size[1]/($size[0]/400));
            $res = "<div class='small' style='border:1px solid black;width:400px'><a href='".$img."' target='_blank'><img src='".$img."' style='width:400px;height:".$y_prop."px' alt='".$img."' border='0'></a></div><div class='small' style='background-color:black;color:white;text-align:center;padding-top:4px;padding-bottom:4px;width:400px'>".$size[0]."x".$size[1]." [".str_replace(".", "", strtoupper($matches[4]))."]</div>";
         } else if ($size[1]>300) {
            $x_prop = ceil($size[0]/($size[1]/300));
            $res = "<div class='small' style='border:1px solid black;width:".$x_prop."px'><a href='".$img."' target='_blank'><img src='".$img."' style='width:".$x_prop."px;height:300px' alt='".$img."' border='0'></a></div><div class='small' style='background-color:black;color:white;text-align:center;padding-top:4px;padding-bottom:4px;width:".$x_prop."px'>".$size[0]."x".$size[1]." [".str_replace(".", "", strtoupper($matches[4]))."]</div>";
         } else {
            $res = "<img src='".$img."' style='border:0px;' alt='".$img."'>";
         }
      } else {
         $res = "[img]".$img."[/img]";
      }
   } else {
      $img = $matches[3].str_replace(array("?","&","="),"",$matches[5]).$matches[6];
      if ($size=@getimagesize($img)) {
         if ($size[0]>$matches[1]) {
            if ($size[0]>400) {
               $y_prop = ceil($size[1]/($size[0]/400));               
               $res = "<div class='small' style='border:1px solid black;width:400px'><a href='".$img."' target='_blank'><img src='".$img."' style='width:400px;height:".$y_prop."px' alt='".$img."' border='0'></a></div><div class='small' style='background-color:black;color:white;text-align:center;padding-top:4px;padding-bottom:4px;width:400px'>".$size[0]."x".$size[1]." [".str_replace(".", "", strtoupper($matches[6]))."]</div>";
            } else if ($size[1]>300) {
               $x_prop = ceil($size[0]/($size[1]/300));               
               $res = "<div class='small' style='border:1px solid black;width:".$x_prop."px'><a href='".$img."' target='_blank'><img src='".$img."' style='width:".$x_prop."px;height:300px' alt='".$img."' border='0'></a></div><div class='small' style='background-color:black;color:white;text-align:center;padding-top:4px;padding-bottom:4px;width:".$x_prop."px'>".$size[0]."x".$size[1]." [".str_replace(".", "", strtoupper($matches[6]))."]</div>";
            } else {
               $res = "<div class='small' style='border:1px solid black;width:".$matches[1]."px'><a href='".$img."' target='_blank'><img src='".$img."' style='width:".$matches[1]."px;height:".$matches[2]."px' alt='".$img."' border='0'></a></div><div class='small' style='background-color:black;color:white;text-align:center;padding-top:4px;padding-bottom:4px;width:".$matches[1]."px'>".$size[0]."x".$size[1]." [".str_replace(".", "", strtoupper($matches[6]))."]</div>";
            }
         } else {
            $res = "<img src='".$img."' style='border:0px;' alt='".$img."'>";
         }
      } else {
         $res = "[img width=".$matches[1]." height=".$matches[2]."]".$img."[/img]";
      }
   }
   return $res;
}



2) find in forum/viewthread.php line #172 which should look like that (this is line from PF v6.01.x but in lower versions should look simmilar):

CodeDownload  
echo "<hr>\n".$data['user_name'].$locale['506']."<br><br>\n<img src='".FORUM."attachments/".$data['attach_name']."'>";



and replace it with:

CodeDownload  
$image = "[img]".FORUM."attachments/".$data['attach_name']."[/img]";
echo "<hr>\n".$data['user_name'].$locale['506']."<br><br>\n".parseubb($image);



3) FORGOTTEN POINT: if you're using P v6.01.x find in maincore.php line #360, should look like this:


CodeDownload  
text = preg_replace("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]#sie","'<img src=\'\\1'.str_replace(array('.php','?','&','='),'','\\3').'\\4\' style=\'border:0px\'>'",$text);



and replace with this line:

CodeDownload  
$text = preg_replace_callback("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]#si","isImage",$text);



which is in fact old PF [ img ] parseubb code.

4) after this MOD your forum and other parts of PF will never crash your site layout :) This MOD simple detects image size and if is bigger than 400px width and/or 300px height will add scaled (proportional) WIDH and HEIGHT commands to <img> tags with info about picture (orig width and height and type of image). Example screenshot:

mfusion.2loud.net.pl/images/autoresize_images.jpg
Very good!:)

Will image be linked to original sized image?
Yes :)
Great, I have just the place for it.

But, please review the code for potential exploits...?
As far as I know no exploits found. I used Digis isImage() function for security check.
Before I go ahead with this, just one final question...

Quote

if you're using PF v6.01.x add dropped isImage() function to your maincore.php again - if your PF version <v6.01.x replace existing isImage() function:
Does that mean the isImage function has been removed from the Core? (yes it does, after checking CVS.)

Ok, i'll play on test site first
Hmm, not working. Safe Mode is ON on my test server.

http://odf409.conram.com/forum/viewth...hread_id=1

Lines 170 to 180 of viewthread.php:
CodeDownload  
      if ($data['attach_id']) {
         if (in_array($data['attach_ext'], $imagetypes) && @getimagesize(FORUM."attachments/".$data['attach_name'])) {
            //Wooya Img resizer code insert new code //
            $image = "[img]".FORUM."attachments/".$data['attach_name']."[/img]";
            echo "<hr>\n".$data['user_name'].$locale['506']."<br><br>\n".parseubb($image);
            //old code //
            //echo "<hr>\n".$data['user_name'].$locale['506']."<br><br>\n<img src='".FORUM."attachments/".$data['attach_name']."'>";
         } else {
            echo "<hr>\n".$data['user_name'].$locale['507']."<br>\n<a href='".FUSION_SELF."?forum_id=$forum_id&thread_id=$thread_id&getfile=".$data['post_id']."'>".$data['attach_name']."</a>";
         }
      }

Wow! I forgo about one thing in maincore.php. Look at my first post at point 3) which I forgot. Sorry ;)
Good to find errors, its worse when You dont...:p

That would be line 400 for me, after adding the previous code so everyone else do not get confused, wooyas line numbering is probably ok, but I added code in step 1 above.
CodeDownload  
   $text = preg_replace('#\[flash width=([0-9]*?) height=([0-9]*?)\]([^\s\'\";:\+]*?)(\.swf)\[/flash\]#si', '<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase=\'http://active.macromedia.com/flash6/cabs/swflash.cab#version=6,0,0,0\' id=\'\3\4\' width=\'\1\' height=\'\2\'><param name=movie value=\'\3\4\'><param name=\'quality\' value=\'high\'><param name=\'bgcolor\' value=\'#ffffff\'><embed src=\'\3\4\' quality=\'high\' bgcolor=\'#ffffff\' width=\'\1\' height=\'\2\' type=\'application/x-shockwave-flash\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\'></embed></object>', $text);
   //Wooya text resize image code new code below
   $text = preg_replace_callback("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]#si","isImage",$text);
   //$text = preg_replace("#\[img\]((http|ftp|https|ftps)://)(.*?)(\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG))\[/img\]#sie","'<img src=\'\\1'.str_replace(array('.php','?','&','='),'','\\3').'\\4\' style=\'border:0px\'>'",$text);

This doe not work for me at all.
Hmmm.... As you can see in attached images it works at Polish Support Site... :|
[ img ] link works perfectly. GOOD JOB WOOYA! :D

Should attachment work? Because it doesn't...

Nitpicking a bit...the right border is a bit off compared to the black image description.

Quote

Homy wrote:
[ img ] link works perfectly. GOOD JOB WOOYA! :D

:D

Quote

Should attachment work? Because it doesn't...

Sure, it should work :|

Quote

Nitpicking a bit...the right border is a bit off compared to the black image description.

I know, I need to experiment with DIV tags more ;)

EDIT:
here's working maincore.php and viewthread.php from Polish Support Site. Additional in parseubb() function my autoimage and autolink functions ;)
I added some informational text in Your code line 8 (the first $res):
CodeDownload  
   $res = "<div class='small' style='border:1px solid black;width:400px'><a href='".$img."' target='_blank'><img src='".$img."' style='width:400px;height:".$y_prop."px' alt='".$img."' border='0' title='Click on image for full size in new window'></a></div><div class='small' style='background-color:black;color:white;text-align:center;padding-top:4px;padding-bottom:4px;width:400px'>".$size[0]."x".$size[1]." [".str_replace(".", "", strtoupper($matches[4]))."]</div>";
   

Look at post above :) >>> EDIT
Any other mods in those files?
Are they 6.01.2?
Yes. This is v6.01.2. Only autolink and aoutoimage MOD additional.

Explain:
- autolink - when user forgot to add [ url ] bbcode to link this script try to add own <a> tags to suchlinks
- autoimage - as above but if user forgot to add [ img ] bbcode

No other mods included
the [img] doesnt work for me :p
Did you MODed maincore.php step by step? Try to upload files from attachment.
Great mod!! I hope this autlink feature works because my members seem to forget that [ url ] tag all the time :)
Thread Information
Author
Replies
60 posts
Views
21,444 times
Last Post
Last updated on 12 years ago
You can view all discussion threads in this forum.
You can start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.