MyBB Community Forums

Full Version: Image auto resize
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How can I make a image auto resize? I think It need a mycode, It look like this image.
[Image: i169675_Image00178.jpg]
I think it'll need a plugin, like this one: http://mods.mybboard.net/archive/view/image-resizer

But as you're using createmybb you can't upload plugins.
Thanks For Your Reply
(2009-01-15, 07:48 PM)MattR Wrote: [ -> ]I think it'll need a plugin, like this one: http://mods.mybboard.net/archive/view/image-resizer
Says Updated to version 1.2 of mybb

Anyone using it on 1.4.4?
A simple look in the Mods section is all it needs: http://mods.mybboard.net/view/image-resizer-&-optimizer
But it not working. When I upload this plugings my acp>plugins are show blank.
Then ask the author for help, maybe there's an error with it.
Hello, allow me to say thank you for all the effort that goes into the development & support of MyBB. It's a nice piece of machinery to use.

Below is the rest of my post in response to what we've encountered.
(2009-01-28, 11:28 PM)davephx Wrote: [ -> ]
(2009-01-15, 07:48 PM)MattR Wrote: [ -> ]I think it'll need a plugin, like this one: http://mods.mybboard.net/archive/view/image-resizer

Says Updated to version 1.2 of mybb

Anyone using it on 1.4.4?
Here is the error message we got with v1.4.4 (1404)

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1146 - Table 'thetechh_TheForum.mybb_mybb_settinggroups' doesn't exist
Query:
INSERT INTO mybb_mybb_settinggroups (gid,name,title,description,disporder,isdefault) VALUES ('NULL','imageresizer','Image resizer','Settings for Cipher\'s \'Image resizer\' plugin.','20','no')

Would someone be so kind as to please assist with the translation?
(2009-01-29, 08:37 AM)Mattalan Wrote: [ -> ]A simple look in the Mods section is all it needs: http://mods.mybboard.net/view/image-resizer-&-optimizer
Tried this one too just for giggles & it blanks out "all" the plugins. Not real sure what that's all about.
(2009-01-30, 08:47 AM)Mattalan Wrote: [ -> ]Then ask the author for help, maybe there's an error with it.
Image resizer (plugin)
Author: Cipher
Submitted: 1st July 2006
Last Updated: 24th September 2006

The update info makes for a lack of confidence in attempting to contact the author for help by the e-mail link provided on the plugin page. There are four Ciphers on the member list. Might one of them be the author?

Any further assistance would be greatly appreciated. Our forum url is in my profile as well. Thank you for reading this far.
I'm sorry for this long piece of code.
You will need to edit imageresizer.php and replace the full document with the following code (make sure you give the right prefix, otherwise uninstalling will be impossible.

<?php
// Make sure the following variable is given//
////////////////////////////////////////////////

$prefix = "mybb_";
/////////////////////////////////////////////////
/**
 * Plugin name: Image resizer
 * Author:		Cipher
 * Version:		1.0
 */

$plugins->add_hook("parse_message", "imageresizer_message");
$plugins->add_hook("pre_output_page", "imageresizer_page");

function imageresizer_info()
{
	return array(
		"name"		=> "Image resizer",
		"description"	=> "Resizes an images if the width is larger than a maximum width given through the settings panel.",
		"website"		=> "mailto:[email protected]",
		"author"		=> "Cipher",
		"authorsite"	=> "mailto:[email protected]",
		"version"		=> "1.1",
	);
}

function imageresizer_activate()
{
	global $mybb, $db;
	
	// Add settings
	$settings_group = array(
		"gid"			=> "NULL",
		"name"		=> "imageresizer",
		"title" 		=> "Image resizer",
		"description"	=> "Settings for Cipher\'s \'Image resizer\' plugin.",
		"disporder"		=> "20",
		"isdefault"		=> "no",
	);
	$db->insert_query("settinggroups", $settings_group);
	$gid = $db->insert_id();
	
	$setting = array(
		"sid"			=> "NULL",
		"name"		=> "image_resizer_active",
		"title"		=> "Active",
		"description"	=> "This gives you the possability to deactivate the plugin without loosing the settings.",
		"optionscode"	=> "yesno",
		"value"		=> "no",
		"disporder"		=> "1",
		"gid"			=> intval($gid)
	);
	$db->insert_query("settings", $setting);
	
	$setting = array(
		"sid"			=> "NULL",
		"name"		=> "image_resizer_maxwidth",
		"title"		=> "Maximum width",
		"description"	=> "What is the maximum width of images in posts/pb\'s.",
		"optionscode"	=> "text",
		"value"		=> "500",
		"disporder"		=> "2",
		"gid"			=> intval($gid),
	);
	$db->insert_query("settings", $setting);
	
	$setting = array(
		"sid"			=> "NULL",
		"name"		=> "image_resizer_resizewidth",
		"title"		=> "Resize width",
		"description"	=> "To what width should images that exceed the maximum width be resized.",
		"optionscode"	=> "text",
		"value"		=> "500",
		"disporder"		=> "3",
		"gid"			=> intval($gid),
	);
	$db->insert_query("settings", $setting);
	
	$setting = array(
		"sid"			=> "NULL",
		"name"			=> "image_resizer_borderstyle",
		"title"			=> "Border style",
		"description"	=> "What should the border of the image be when resized.",
		"optionscode"	=> "text",
		"value"			=> "2px dashed red",
		"disporder"		=> "4",
		"gid"			=> intval($gid),
	);
	$db->insert_query("settings", $setting);
	
	$setting = array(
		"sid"			=> "NULL",
		"name"			=> "image_resizer_showwarning",
		"title"			=> "Show warning",
		"description"	=> "Should the users be warned to resize the image by a message under the image.",
		"optionscode"	=> "yesno",
		"value"			=> "yes",
		"disporder"		=> "5",
		"gid"			=> intval($gid),
	);
	$db->insert_query("settings", $setting);
	
	$setting = array(
		"sid"			=> "NULL",
		"name"			=> "image_resizer_warning",
		"title"			=> "Warning",
		"description"	=> "What should be the text of the warning.",
		"optionscode"	=> "text",
		"value"			=> "This image is too large.",
		"disporder"		=> "6",
		"gid"			=> intval($gid),	
	);
	$db->insert_query("settings", $setting);
	
	$setting = array(
		"sid"			=> "NULL",
		"name"			=> "image_resizer_warningcolor",
		"title"			=> "Warning text color",
		"description"	=> "What should be the text color of the warning.",
		"optionscode"	=> "text",
		"value"			=> "white",
		"disporder"		=> "7",
		"gid"			=> intval($gid),
	);
	$db->insert_query("settings", $setting);
	
	$setting = array(
		"sid"			=> "NULL",
		"name"			=> "image_resizer_warningbackground",
		"title"			=> "Warning background",
		"description"	=> "What should be backgroundcolor of the warning.",
		"optionscode"	=> "text",
		"value"			=> "red",
		"disporder"		=> "8",
		"gid"			=> intval($gid),
	);
	$db->insert_query("settings", $setting);
}

function imageresizer_deactivate()
{
	global $db;
	
	//DELETE ALL SETTINGS
	$db->query("DELETE FROM ".$prefix."settings WHERE name IN('image_resizer_active','image_resizer_maxwidth','image_resizer_resizewidth','image_resizer_borderstyle','image_resizer_showwarning','image_resizer_warning','image_resizer_warningcolor','image_resizer_warningbackground')");
	$db->query("DELETE FROM ".$prefix."settinggroups WHERE name='Image resizer'");
}

function imageresizer_message($message)
{
	global $mybb;
	if ($mybb->settings['image_resizer_active'] == "yes")
	{
		$pattern = '#<img(.*?)/>#';
		$replace = '<img class="postimage"$1/>';
		$message = preg_replace($pattern, "$replace", $message);
	}
	return $message;
}

function imageresizer_page($page)
{
	global $mybb;
	// var_dump($mybb);
	if ($mybb->settings['image_resizer_active'] == "yes")
	{
		$page = str_replace('</head>', imageresizer_javascript().'</head>', $page);
		$page = preg_replace('#<body(.*?)>#', '<body onload="resize_images()"$1>', $page);
	}
	
	return $page;
}

function imageresizer_javascript()
{
	global $mybb;
	
	$maxwidth = $mybb->settings['image_resizer_maxwidth'];
	$resizewidth = $mybb->settings['image_resizer_resizewidth'];
	$borderstyle = $mybb->settings['image_resizer_borderstyle'];
	$warning = $mybb->settings['image_resizer_warning']; 
	$warningcolor = $mybb->settings['image_resizer_warningcolor']; 
	$warningbackground = $mybb->settings['image_resizer_warningbackground'];
	
	$javascript = 
'<script language="javascript" type="text/javascript"><!-- 
	function resize_images() 
  	{ 
    	for (i = 0; i < document.images.length; i++) 
    	{ 
    		if (document.images[i].className == "postimage")
    		{
	     	 	while ( !document.images[i].complete ) 
	      		{ 
	         		break;
	      		} 
	      		
	      		var resized = false;
	      		var oldwidth = 0;
	      		if ( document.images[i].width > '.$maxwidth.' ) 
	      		{ 
	      			oldwidth = document.images[i].width;
	      			oldheight = document.images[i].height;
	        		document.images[i].width = '.$resizewidth.'; 
	      			resized = true;
	      		} 
	      		if ( document.images[i].style.width != "" ) 
	      		{ 
	      			var stylewidth = document.images[i].style.width;
	      			if (stylewidth.slice(stylewidth.length-2, stylewidth.length) == "px")
	      			{
	      				stylewidth = stylewidth.slice(0, stylewidth.length-2);
	      			}
	      			if ( stylewidth > '.$maxwidth.' )
	 				{     
	        			document.images[i].style.width = "'.$resizewidth.'px"; 
	        			var styleheight = document.images[i].style.height;
		      			if (styleheight.slice(styleheight.length-2, styleheight.length) == "px")
		      			{
		      				styleheight = styleheight.slice(0, styleheight.length-2);
		      			}
		      			document.images[i].style.height = '.$resizewidth.' / stylewidth * styleheight + "px";
	      				resized = true; 
	 				}
	      		} 
	      		if (resized) 
	      		{';
	if ($borderstyle != "") {
		$javascript .= '
	    			document.images[i].style.borderTop = "'.$borderstyle.'";
	    			document.images[i].style.borderLeft = "'.$borderstyle.'";
	    			document.images[i].style.borderRight = "'.$borderstyle.'";';
	}
	if ($mybb->settings['image_resizer_showwarning'] == "yes") {
		$javascript .= '
	      			var parent = document.images[i].parentNode;
	      			var warning = document.createElement("div");
					warning.innerHTML = "<div>'.$warning.'</div>";';
		if ($warningcolor != "") {
			$javascript .= '
	    			warning.style.color = "'.$warningcolor.'";';
		}
		if ($warningbackground != "") {
			$javascript .= '
	    			warning.style.background = "'.$warningbackground.'";';
		}
		if ($borderstyle != "") {
			$javascript .= '
	    			warning.style.borderBottom = "'.$borderstyle.'";
	    			warning.style.borderLeft = "'.$borderstyle.'";
	    			warning.style.borderRight = "'.$borderstyle.'";';
		}
		$javascript .= '
	    			warning.style.width = "'.$resizewidth.'px";
					parent.insertBefore(warning, document.images[i].nextSibling);';
	}
	else {	
		if ($borderstyle != "") {
			$javascript .= '
	    			document.images[i].style.borderBottom = "'.$borderStyle.'";';
		}
	}
	$javascript .= '
					if (document.images[i].parentNode.tagName.toLowerCase() != \'a\') {
						document.images[i].onclick = openImage;
					}
		      	}
    		}
    	} 
  	} 
  	function openImage() {
  		var winwidth = (this.naturalWidth < screen.availWidth ? this.naturalWidth : screen.availWidth);
		var winheight = (this.naturalHeight < screen.availHeight ? this.naturalHeight : screen.availHeight);
		window.open(this.src);
  	} 
//--></script>';

	return $javascript;
}
?>
erm? Is this a release or something..?
Pages: 1 2