Offsite hosted Image resizing in e107 forums (Resolved)

e107 CMS » Forums » e107 v1.x Support » Core Code Support << Previous thread | Next thread >>
Go to page  1 2 3 4 5 ... 9 10 11
Harmond
Nov 16 2006, 08:08PM
Registered Member #32389
Joined: Nov 16 2006, 08:06PM
Posts: 3
1st - Thank you coding dudes.

2nd - Thank you search function.

<3
Go to top
xtrm
Nov 19 2006, 07:59AM
Registered Member #32383
Joined: Nov 16 2006, 11:24AM
Posts: 2
something like this works, but i dont know the exact sintax for php from html, so if u can help me a bit help me whats wrong with this (however this works):

if (!$postID) {
	return "<a href='".$code_text."' target='popup' [sanitised]onClick=[/sanitised]'window.open(this.href, this.target, 'width=100%,height=100%'); return false;' /><img border='0' src='".$code_text."' {$parmStr} /><a />";
} else {
	if(strstr($postID,'class:')) {
		$uc = substr($postID,6);
	}
	if ($pref['image_post']) {
		if($uc == '') {
			if (!function_exists('e107_userGetuserclass')) {
				require_once(e_HANDLER.'user_func.php');
			}
			$uc = e107_userGetuserclass($postID);
		}
		if (check_class($pref['image_post_class'],$uc)) {
			return "<a href='".$code_text."' target='popup' [sanitised]onClick=[/sanitised]'window.open(this.href, this.target, 'width=100%,height=100%'); return false;'  /><img src='".$code_text."' {$parmStr} /><a />";
		}
		else
		{
			return ($pref['image_post_disabled_method'] ? "[ image disabled ]" : "Image: $code_text");
		}
	}
	else
	{
		if ($pref['image_post_disabled_method']) {
			return '[ image disabled ]';
		} else {
			return "Image: $code_text";
		}
	}
}

Go to top
xtrm
Nov 19 2006, 08:25AM
Registered Member #32383
Joined: Nov 16 2006, 11:24AM
Posts: 2
modify img.bb, the last part where begins with:
if (!$postID) {
no errors and works in firefox and ie6: (dunno if its a good way though)
if (!$postID) {
	return "<a href='".$code_text."' target='popup' /><img border='0' src='".$code_text."' {$parmStr} /><a />";
} else {
	if(strstr($postID,'class:')) {
		$uc = substr($postID,6);
	}
	if ($pref['image_post']) {
		if($uc == '') {
			if (!function_exists('e107_userGetuserclass')) {
				require_once(e_HANDLER.'user_func.php');
			}
			$uc = e107_userGetuserclass($postID);
		}
		if (check_class($pref['image_post_class'],$uc)) {
			return "<a href='".$code_text."' target='popup'  /><img src='".$code_text."' {$parmStr} /><a />";
		}
		else
		{
			return ($pref['image_post_disabled_method'] ? "[ image disabled ]" : "Image: $code_text");
		}
	}
	else
	{
		if ($pref['image_post_disabled_method']) {
			return '[ image disabled ]';
		} else {
			return "Image: $code_text";
		}
	}
}


[ Edited Nov 19 2006, 08:26AM ]
Go to top
Mirrana
Nov 21 2006, 09:17AM
Registered Member #32476
Joined: Nov 21 2006, 08:47AM
Posts: 5
This really should be implemented in the next release of e107, with an option to change the width setting in the images control panel... really awesome fix, thanks guys
Go to top
C6Dave
Nov 21 2006, 11:38AM
  • e107 Site administrator
  • e107 Support Team Leader
Registered Member #9506
Joined: Jul 31 2004, 12:57AM
Location: North East UK
Posts: 12341
It has been forwarded to the dev team to check out as they were concerned it might slow render times down - but I haven't noticed any issues
Go to top
Website
steved
Nov 21 2006, 12:41PM
  • e107 Main site administrator
  • e107 Core developer
Registered Member #16181
Joined: Mar 28 2005, 01:18PM
Posts: 8942
The problem is that the code has to get the image size from the remote server - so no problem if its a really fast link, but a slow response will impair render times, while a non-responding server (which could be caused by an incorrectly entered url) can really slow things up - a timeout of 10 to 30 seconds waiting for a response isn't uncommon. To avoid this you'd need to cache the image on the local server, which starts to get complicated.
Go to top
Harmond
Nov 29 2006, 07:12PM
Registered Member #32389
Joined: Nov 16 2006, 08:06PM
Posts: 3
Would it be possible to do something like this for offsite hosted avatars?
Go to top
marj
Nov 30 2006, 12:21AM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6163
go to admin > images > Validate avatar size and access
this is a tool to correct wrong sized avatars (upload & off site)
there's no need to check the size all the time then, saving against a possible delay issue steved pointed just above
Go to top
Harmond
Nov 30 2006, 02:36PM
Registered Member #32389
Joined: Nov 16 2006, 08:06PM
Posts: 3
Thanks for the reply, but I don't see an option for that in the images menu. I checked the preferences, public upload, and forum menus and didn't see it there either. I'm using 0.7.5.

These are the only options I see in the Images menu:

Enable image posting
Display images, this will apply sitewide (comments, chatbox etc)

Image posting class
Restrict users who can post images (if enabled above)

Disabled image method
What to do with posted images if image posting is disabled Show image URLShow nothing

Resize method
Method used to resize images, either GD1/2 library, or ImageMagick gd1gd2ImageMagick

Path to ImageMagick (if selected)
Full path to ImageMagick Convert utility

Enable Sleight
Fixes transparent PNG-24's with alpha transparency in IE 5 / 6 (Applies Sitewide)
Show uploaded avatars


(Sorry for thread derail.)
Go to top
marj
Nov 30 2006, 03:01PM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6163
sorry Harmond, this feature is available since 0.7.6.
Go to top
VR6Pete
Dec 04 2006, 06:23AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1245
very nicely done!

I'll implement this on my site ASAP, as it's annoying the amount of people who link in rather large images on my forums which destorys my theme...



Pete
Go to top
Website
C6Dave
Dec 04 2006, 08:42AM
  • e107 Site administrator
  • e107 Support Team Leader
Registered Member #9506
Joined: Jul 31 2004, 12:57AM
Location: North East UK
Posts: 12341
Thats why I wanted it Pete - it's also good for onsite images as you can have large ones which auto reduce but when clicked go full size

I use it in articles as well - theres a good example here [-link-] just click an image
Go to top
Website
VR6Pete
Dec 05 2006, 05:38AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1245
handy to know that 2dopy

Makes it easier for other users to contribue as they may not know how to resize images and stuff...

I'm going to have a play with this tonight (didnt get chance to do it last night, as I lost the keys to me VR! and the breakdown dudes couldnt break into it lol!)

Would very much like to see this sort of feature implemented into future versions of the CMS... I've seen various other forum systems use something similar where it renders an image and you click to enlarge it.. just makes it easier on the admins allround as opposed to pissing about resizing people's images hehe.

pete
Go to top
Website
VR6Pete
Dec 12 2006, 04:53PM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1245
Found a bug!

[-link-]
Go to top
Website
marj
Dec 12 2006, 05:14PM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6163
VR6Pete wrote ...
Found a bug!
[-link-]
that's the trouble of this hack, and surely why it stay a hack.
to get the size of the image php have to find it. if this img is no longer available (deleted, remote server done, or slow, or too many img...) the script stay on this particular line.

as steved said:
steved wrote ...

The problem is that the code has to get the image size from the remote server - so no problem if its a really fast link, but a slow response will impair render times, while a non-responding server (which could be caused by an incorrectly entered url) can really slow things up - a timeout of 10 to 30 seconds waiting for a response isn't uncommon. To avoid this you'd need to cache the image on the local server, which starts to get complicated.
another trick could be to store(cache) img path, x and y somewhere if new.
I'm not sure it's the aim of a bbcode anyway
Go to top
VR6Pete
Dec 18 2006, 05:39AM
Registered Member #2353
Joined: Jul 28 2003, 11:21AM
Location: Stoke-on-Trent
Posts: 1245
Then how come other CMS's and forum software can resize external images without timing out?
Go to top
Website
marj
Dec 18 2006, 05:50AM
marj
Registered Member #1159
Joined: Mar 16 2003, 08:00AM
Posts: 6163
probably the same way that this one does, and by caching x, y scale somewhere to avoid disappointment
Go to top
scrambler
Feb 23 2007, 05:15PM
Registered Member #28937
Joined: Jul 14 2006, 08:36AM
Posts: 263
Seems like this code is not working since I updated to .7.8 does there need to be any changes? I like this function because it at least keeps big off site signatures from getting carried away. THe only change to my site has been to update my .htaccess to preclude hotlinking graphics.
.htacess is as follows
Options +FollowSymlinks
AuthUserFile /home/content/x/x/x/xxxx/html
AuthGroupFile /dev/null
AuthName "xxxxxx"
AuthType Basic
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?harrypotterworld\.us/ [nc]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?diagonalleycentral\.net/ [nc]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?boards.harrypotter.warnerbros\.com/ [nc]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?e107\.org/ [nc]
RewriteRule .*\.(gif|jpg|jpeg|swf|png)$ http//harrypotterworld.us/leech.bmp [R,NC]


xed out the personal info. I'm hosted at godaddy and it was pretty hard figureing out how to get th htacess file to work but it does now. I wanted to post it here to see if you saw anything that might cause the resize code to not funtion.
[ Edited Feb 23 2007, 07:46PM ]
Go to top
C6Dave
Feb 24 2007, 12:06AM
  • e107 Site administrator
  • e107 Support Team Leader
Registered Member #9506
Joined: Jul 31 2004, 12:57AM
Location: North East UK
Posts: 12341
scrambler wrote ...

Seems like this code is not working since I updated to .7.8 does there need to be any changes? I like this function because it at least keeps big off site signatures from getting carried away. THe only change to my site has been to update my .htaccess to preclude hotlinking graphics.

Upgrading to v0.7.8 will have overwritten e107_files/bbcode/img.bb which will have removed the hack

The latest version of that file with the hacked img.bb file should be:
global $pref;
if (preg_match("#\.php\?.*#",$code_text)){return "";}
global $IMAGES_DIRECTORY, $FILES_DIRECTORY, $e107;
$search = array('"', '{E_IMAGE}', '{E_FILE}');
$replace = array(''', $e107->base_path.$IMAGES_DIRECTORY, $e107->base_path.$FILES_DIRECTORY);
$code_text = str_replace($search, $replace, $code_text);
unset($imgParms);
$imgParms['class']="bbcode";
$imgParms['alt']='';
$imgParms['style']="vertical-align:middle; border:0";

$code_text = $tp -> toAttribute($code_text);

if($parm) {
$parm = preg_replace('#onerror *=#i','',$parm);
$parm = str_replace("amp;", "&", $parm);
parse_str($parm,$tmp);
foreach($tmp as $p => $v) {
$imgParms[$p]=$v;
}
}
$parmStr="";
foreach($imgParms as $k => $v) {
$parmStr .= $tp -> toAttribute($k)."='".$tp -> toAttribute($v)."' ";
}


if(file_exists(e_IMAGE."newspost_images/".$code_text))
{
$code_text = e_IMAGE."newspost_images/".$code_text;
}

if (function_exists("getimagesize")) {
$size = getimagesize($url);
if ($size !== false) {
$w = $size[0];
$h = $size[1];
$maxW = 500;
if ($w > $maxW) {
$h = intval($h / ($w/$maxW));
$w = $maxW;
}
$parmStr .= "width='$w' height='$h'";
}
}
if (!$postID) {
return "<img src='".$code_text."' {$parmStr} />";
} else {
if(strstr($postID,'class:')) {
$uc = substr($postID,6);
}
if ($pref['image_post']) {
if(!isset($uc) || ($uc == '')) {
if (!function_exists('e107_userGetuserclass')) {
require_once(e_HANDLER.'user_func.php');
}
$uc = e107_userGetuserclass($postID);
}
if (check_class($pref['image_post_class'],$uc)) {
return "<img src='".$code_text."' {$parmStr} />";
}
else
{
return ($pref['image_post_disabled_method'] ? "[ image disabled ]" : "Image: $code_text");
}
}
else
{
if ($pref['image_post_disabled_method']) {
return '[ image disabled ]';
} else {
return "Image: $code_text";
}
}
}


Change line 38: $maxW = 500; to whatever max width you require
Go to top
Website
scrambler
Feb 24 2007, 06:49AM
Registered Member #28937
Joined: Jul 14 2006, 08:36AM
Posts: 263
If I use this .img that you posted I get the following parse errors as in line 1 even when I delete the htacess file I get an error like in line 3

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/content/x/x/x/xxxxxxx/html/cms/e107_handlers/bbcode_handler.php(269) : eval()'d code on line 8

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/content/x/x/x/xxxxxx/html/cms/e107_handlers/bbcode_handler.php(269) : eval()'d code on line 8


If I use the code from marj's post a few pages back I don't get the error but the image is not resized.

// add
if (!function_exists('resizeme')) {
function resizeme ($code_text) {
$size = getimagesize($code_text);
if ($size !== false) {
$w = $size[0];
$h = $size[1];
$maxW = 595; // change max width here
if ($w > $maxW) {
$h = intval($h / ($w/$maxW));
$w = $maxW;
$parmStr .= " width='$w' height='$h'";
return $parmStr;
}
}
return false;
}
}
$resizeme = resizeme ($code_text);
$resizeme_prefix ="";
$resizeme_postfix="";
if ($resizeme != false) {
$resizeme_prefix .= "<a href='$code_text' rel='external'>";
$parmStr .= $resizeme;
$resizeme_postfix .= "</a>";
}
// end add
[ Edited Feb 24 2007, 07:24AM ]
Go to top
Go to page  1 2 3 4 5 ... 9 10 11  

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System