DragonflyCMS Projects > ForumsPlus > Auto Image sizing > Community Forums > Phoenix Netology
Forum Index > Community > ForumsPlus

Auto Image sizing


One of my forums has a lot of non-computer savvy people who don't understand the concept of resizing images to suit a forum.

Is it possible to have a function that checks img locations used in a forum post to see if they are over a certain size, and if so, add a size to the html img tags that are created?

That way, we can keep images at no wider than say 640px.

Please enter your server specs in your user profile! 😢


Presumably you just mean those images linked remotely via the [img] tag, since uploaded image size can already be controlled in forum admin attachment settings.

There are various solutions, most of which are client side (javascript), which will resize on the run.

In fact, I believe one such option is outlined on the DF site - just search for image resize.

Eventually I could add such a feature to ForumsPlus and would most likely use a jQuery plug-in which would either use a max width setting in config or auto image fit to the space available.

Donations & Audit for DragonflyCMS

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):


This simple solution only resizes images (including signatures) within forum posts.

It uses the existing forum admin settings for maximum attachment width and height.

Right click and view image to see original size 840px restricted to 500px.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):


There's several options to fix it ;D

as Phoenix said the most common will be a javascript solution, but also you can try the css option, wich will be compatible with almost every modern browser (no IE6, and maybe NOT ie7).

add to you css (themes/THEME/style/style.css);

div.postbody img {max-height:640px;max-height:400px;}
images should be resized.

Phoenix, i've got a nice effect on my forum, wich is using lightbox to see the full size images:

www.greenday2k.net/For...13063.html

check the first post.

[img]http://greenday2k.net/serverspecs.php[img]

Please enter your server specs in your user profile! 😢


Regrettably, a css solution using max-width and max-height can produce distorted images.

Due to the continuing significant useage of IE 5+, the following css/js max-width solution is more appropriate:
div.postbody img {
max-width: 500px;
width: expression(document.body.clientWidth > 500 ? "500px" : "auto");
}

Donations & Audit for DragonflyCMS

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):

Last edited by Phoenix on Mon Nov 28, 2011 12:57 pm; edited 2 times in total


Thanks for the replies fellas.
I guess I could look at using javascript.

I was thinking more along the lines of the BBCode to html conversion doing it.

So in the image tag, we could have [img=800x600]http://link.to.image.com[/img]

Then when the real img tag is produced, we have:
<img width=800 height=600 src=http://link.to.image.com>

For now I'll check out javascript and see if that will do the job.

Please enter your server specs in your user profile! 😢


Phoenix what is the name of the module, you have used as your image example above?

Do you know where I can find a copy of it?

Cheers

Please enter your server specs in your user profile! 😢


hmm, lost it when upgrading the site - that's why the image I provided isn't actually reduced.

I'll have to go look for it.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):


Regrettably I had edited a ForumsPlus file and that has dozens of changes in it.

However, I seem to recall the change was simple. Open viewtopic.php and find these lines at the top
if (!defined('CPG_NUKE')) { exit; }
require_once('modules/'.$module_name.'/nukebb.php');
require_once('includes/nbbcode.php');
Then add this immediately after:
$attach_config['img_max_width_remote'] = 1;
if ($attach_config['img_max_width_remote']) {
$modheader .= '<script src="includes/javascript/jquery.js" type="text/javascript"></script>';
# code courtesy of Eric Juden
$modheader .= '<script>
$(document).ready(function() {
$(\'.postbody img\').load(function() {
$(\'.postbody img\').each(function() {
var maxWidth = '.$attach_config['img_max_width'].'; // Max width for the image
var maxHeight = '.$attach_config['img_max_height'].'; // Max height for the image
var ratio = 0; // Used for aspect ratio
var width = $(this).width(); // Current image width
var height = $(this).height(); // Current image height

// Check if the current width is larger than the max
if(width > maxWidth){
ratio = maxWidth / width; // get ratio for scaling image
$(this).css("width", maxWidth); // Set new width
$(this).css("height", height * ratio); // Scale height based on ratio
height = height * ratio; // Reset height to match scaled image
width = width * ratio; // Reset width to match scaled image
}

// Check if current height is larger than max
if(height > maxHeight){
ratio = maxHeight / height; // get ratio for scaling image
$(this).css("height", maxHeight); // Set new height
$(this).css("width", width * ratio); // Scale width based on ratio
width = width * ratio; // Reset width to match scaled image
}
});
});
});
</script>
';
}
Of course, you also need jquery.js in the includes/javascript/ folder.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):

Last edited by Phoenix on Mon Nov 28, 2011 12:56 pm; edited 2 times in total


Any luck remembering the name of the module, you have used as your image example above?

Please enter your server specs in your user profile! 😢


Oh, you meant the actual module in the image Laughing

nukebiz.com/DragonflyAds/

nukebiz.com/Downloads/...ils/id=70/

Donations & Audit for DragonflyCMS

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):


Yeah sorry another mis-interpretation. I hope to get the right message across to you one day! May save us both some time. LOL

Please enter your server specs in your user profile! 😢

All times are Australia/Adelaide
This forum is locked: you cannot post, reply to, or edit topics. Forum Index > Community > ForumsPlus
Page 1 of 1


Jump to: