MyBB Community Forums

Full Version: attached images don't get resized
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
Whenever I (or a user) uses the [img][/img] with an image from the net (not one that's located in my forum, but a link to an image on another site), the image is shown in full size. Can this be changed. I would like the picture to be shown as a thumbnail and clicking on it will show it in full size.
I'm using MyBB version 1.4.4 that I just installed from scratch (very late at the new year's night). I have the Notebook theme (changed to work in a RTL env.) with no changes to the templates that deals with images. Plugins that I use:
Akismet,
Contact Form,
Download Manager,
Easy Refer,
EMS,
Overview,
Posts Required To View Forums,
Prefix-Plugin (not used, for now, but activated),
Subforums in columns,
Side Boxes!

So, as you can see, none of this plugins does anything with images.
I know about the "Image Resizer & Optimizer with GD" plugin, but it uses a link under the image. I would prefer that the user would be able to click on the image itself.


Ori...
It'll need some sort of code modification or plugin, so I'll move this to the relevant forum.
Isn't this something that MyBB does automatically? There's some settings in the AdminCP about pictures.

Ori...
That's attachments, not images with [img] tags which is what you explained.
OK. good to know. I, actually, have a partial solution for this: popbox, but the problem is that if I change the [img][/img] using this, every image uses it (even small ones, that I don't want to change - like my signature).

Ori...
If you want to use the popbox with all [img][/img] tags just replace mycode_parse_img function which is available on inc/class_parser.php with following:

function mycode_parse_img($url, $dimensions=array(), $align='')
    {
        global $lang;
        $url = trim($url);
        $url = str_replace("\n", "", $url);
        $url = str_replace("\r", "", $url);
        $size = @getimagesize("$url");
        $imgheight = $size[1];
        $imgwidth = $size[0];
        if($align == "right")
        {
            $css_align = " style=\"float: right;\"";
        }
        else if($align == "left")
        {
            $css_align = " style=\"float: left;\"";
        }
        $alt = htmlspecialchars_uni(basename($url));
        if(my_strlen($alt) > 55)
        {
            $alt = my_substr($alt, 0, 40)."...".my_substr($alt, -10);
        }
        $alt = $lang->sprintf($lang->posted_image, $alt);
        if($dimensions[0] > 0 && $dimensions[1] > 0)
        {
            return "<img src=\"{$url}\" width=\"{$dimensions[0]}\" height=\"{$dimensions[1]}\" border=\"0\" alt=\"{$alt}\"{$css_align} />";
        }
        elseif($imgheight > 300 || $imgwidth > 300)
        {
            return "<img id=\"{$url}\" src=\"{$url}\" pbshowcaption=\"true\" pbcaption=\"{$alt}\" style=\"width: 300px;\" class=\"PopBoxImageSmall\" onclick=\"Pop(this,50,'PopBoxImageLarge');\" name=\"Pop Box Effect\" alt=\"{$alt}\"/>";
        }
        else
        {
            return "<img src=\"{$url}\" border=\"0\" alt=\"{$alt}\"{$css_align} />";            
        }
    }

This new function will replace all [img][/img] tags bigger than 300x300 dimensions.
Thanks you, thank you and again, thank you ...
This work beautifully. I even left (for now) the Mycode for some tests and the code you gave works better and faster.

Ori...
You're welcomeWink