2008-07-13, 09:42 PM
Is there any way in myBB 1.4 that I can have a user-posted image automatically resized so that it doesn't mess with the layout of the page?
Example:
![[Image: GNOME-GreenLandscape_1600x1200.jpg]](https://camo.mybb.com/5e5a9826e663ba9a7f303b42dc517fdd195df507/687474703a2f2f6674702e676e6f6d652e6f72672f7075622f474e4f4d452f7465616d732f6172742e676e6f6d652e6f72672f6261636b67726f756e64732f474e4f4d452d477265656e4c616e6473636170655f3136303078313230302e6a7067)
Example:
<script type="text/javascript">
<!--
function ResizeThem()
{
var maxheight = 300;
var maxwidth = 300;
var imgs = document.getElementsByTagName("img");
for ( var p = 0; p < imgs.length; p++ )
{
if ( imgs[p].getAttribute("alt") == "" )
{
var w = parseInt( imgs[p].width );
var h = parseInt( imgs[p].height );
if ( w > maxwidth )
{
imgs[p].style.cursor = "pointer";
imgs[p].onclick = function( )
{
var iw = window.open ( this.src, 'ImageViewer','resizable=1' );
iw.focus();
};
h = ( maxwidth / w ) * h;
w = maxwidth;
imgs[p].height = h;
imgs[p].width = w;
}
if ( h > maxheight )
{
imgs[p].style.cursor="pointer";
imgs[p].onclick = function( )
{
var iw = window.open ( this.src, 'ImageViewer','resizable=1' );
iw.focus( );
};
imgs[p].width = ( maxheight / h ) * w;
imgs[p].height = maxheight;
}
}
}
}
// -->
</script>
find <body> replace with <body onload="ResizeThem()">return "<img src=\"{$url}\" border=\"0\" alt=\"{$alt}\"{$css_align} />";
return "<img src=\"{$url}\" onload=\"if(this.width > 800) {this.width=800} if(this.height > 600) {this.height=600}\" border=\"0\" alt=\"{$alt}\"{$css_align} />";