PDA

View Full Version : Image resize on non hosted images


vtx1800
01-21-2006, 10:00 PM
This is my first attempt on vB code changes, so I hope this works. I also believe this should be a vB ACP feature in the near future.

Credit: I was reading this thread (https://vborg.vbsupport.ru/showthread.php?t=103915&page=4&pp=15&highlight=image+size) and decided to make this hack. I used it as a place to start and make my version.

What this does: What this will do is restrict images that a user posts that are not hosted on a user defined server.

1. All images not hosted on a defined server will be set to 100x100.
2. User can set the host domain to allow normal image sizes.

Reason for this: I wanted this code to prevent a user from posting a huge image and cause the forum layout to get destroyed. I hated it when a image size of 1024x768 gets posted and my forums width is only 700px.

To install: I don't know how to make a plugin, so it's all via editing the "class_bbcode.php" file in the /includes folder.

Find: (Line 1828)

return '<img src="' . $link . '" border="0" alt="" />';

Replace with: (Note this must be enclosed with the {} to work.)
{if (preg_match("/allowedDomain.com/i", $link))
{
return '<img src="' . $link . '" border="1" />';
} else {
return '<img src="' . $link . '" border="1" height="100" width="100" />';
}

You must change the "allowedDomain" text to be the site you want to allow. So, if you want to allow http://www.putfile.com, do not include the 'http' or 'www'.

Hope this is useful to all of you, I know it's something I was looking for, but never found. If it is on the site, sorry, I can't seem to find much with the search feature.

If you like it, please click INSTALL if you use it.

All comments are welcome, as this was my first attempt and would like to make more.

evenmonkeys
01-22-2006, 01:55 AM
I'm going to test this out, but it looks like it will effect signatures.

evenmonkeys
01-22-2006, 02:00 AM
error: parse error, unexpected T_IF, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /html/includes/class_bbcode.php on line 1971

vtx1800
01-22-2006, 02:05 AM
You are missing the { and } to surround the IF statement.

This is a copy of my code... a few line above and below of the original insert.

* @param string The URL to the image.
*
* @return string HTML representation of the tag.
*/
function handle_bbcode_img_match($link)
{
$link = $this->strip_smilies(str_replace('\\"', '"', $link));

// remove double spaces -- fixes issues with wordwrap
$link = str_replace(' ', '', $link);

{if (preg_match("/yourDomain.com/i", $link))
{
return '<img src="' . $link . '" border="1" />';
} else {
return '<img src="' . $link . '" border="1" height="100" width="100" />';
}
}
# return '<img src="' . $link . '" border="0" alt="" />';
}

/**
* Removes the specified amount of line breaks from the front and/or back
* of the input string. Includes HTML line braeks.

Note, I kept the old original code, just added the '#' to block the line.

UPDATE: I just checked the test posts, it appears it will effect the signatures. I'll update it to not effect sigs later tonight.

UPDATE 2: I found out why my test didn't catch the sig images... I have a custom BB code for Sig images.

evenmonkeys
01-22-2006, 07:51 AM
Yeah. I've got that same problem. I've been trying to seperate posts from signatures... but can't.

Snake
01-22-2006, 08:51 AM
Definitely going to install this once I get back to home!

RyanC
01-22-2006, 09:03 PM
Is there anyway to do this just by width so that the image doesn't lose aspect ratio? I hate it when folks break my designs with big ole images, but I don't want to torture their images either... just curious.

thanks!

vtx1800
01-22-2006, 09:06 PM
I think the other hack, https://vborg.vbsupport.ru/showthread.php?t=103915&page=4&pp=15&highlight=image+size might work better for you.

I wanted it to crush them down, so the users knew that the image was not hosted on our servers, and if anything adult was posted, it wouldn't be as noticable.

I am working on this now, to prevent the signature images being effected.

Zia
01-24-2006, 05:29 AM
helo....
just let me a bit more clear....xplaining

In our forum: we use imageshack.us & photobucket.com 's free image host service..

will this hack create all the image hosted on those both place to thumbnail ?
and it should not touch the sigs that also hosted on photobucket/imageshack?

will this hack only works on pre-define domain? wont it work on universal??

Waiting for some xplanation...

Thankx

vtx1800
01-24-2006, 05:34 AM
helo....
just let me a bit more clear....xplaining

In our forum: we use imageshack.us & photobucket.com 's free image host service..

will this hack create all the image hosted on those both place to thumbnail ?
and it should not touch the sigs that also hosted on photobucket/imageshack?

will this hack only works on pre-define domain? wont it work on universal??

Waiting for some xplanation...


Thankx

At the moment, this will make a thumbnail of any image used in the [img] tag. So yes, sigs are included.

I have code for just the users posts, but it's causing an error in the quick reply of 3.5.3. The new code, not yet posted, does work with only the posts, and not the sigs, but the quickreply error is slowing me down.

I hope to have the 2nd code up soon, once I find out why the error is being generated.

Zia
01-24-2006, 05:39 AM
nice to know...this will generate thumbnail any image within https://vborg.vbsupport.ru/ code...

but the same probs...re-size sigs...:S

will it follow the pre-defined domain name for thumbnail gen. ???

Its nice ..
waiting for ur modication/update..

Thnkx for prompt-reply.

ggiersdorf
01-29-2006, 10:36 AM
Regardless of what you do they are still using the [IMG] tag so all images signatures included will be resized. I mad a slight modification to the code in my post that allows any image over 500ox to be resized down to 150 or whatever and that allows my signatures to be up to 400-500 size plenty for users..

Though an Ideal fix would be to create something that ignores the img tag when used within the $signature tag.. I am working on this and having some success.

vtx1800
01-30-2006, 06:40 PM
Regardless of what you do they are still using the [IMG] tag so all images signatures included will be resized. I mad a slight modification to the code in my post that allows any image over 500ox to be resized down to 150 or whatever and that allows my signatures to be up to 400-500 size plenty for users..

Though an Ideal fix would be to create something that ignores the img tag when used within the $signature tag.. I am working on this and having some success.


I have the code (very different that this one) to fix the images in the posts, but not the sig. The code works perfectly. Problem is, in 3.5.3, it is causing a double post in the quick reply. ggiersdorf, you want to team up with me and help figure this out?

lazytown
01-31-2006, 08:06 AM
Wouldn't it be better to implement an image auto-resize client side with javascript? That way a user can click to enlarge it, the aspect ratio would be correct, and it wouldn't have any server impact. It looks like this one has no server impact, but it produces ugly thumbs and I don't think its really an improvement over the one you copied it from at all (with the exception of ignoring a user specified server). The one you copied it from maintaned the aspect ratio.

-vissa

vtx1800
01-31-2006, 06:20 PM
Wouldn't it be better to implement an image auto-resize client side with javascript? That way a user can click to enlarge it, the aspect ratio would be correct, and it wouldn't have any server impact. It looks like this one has no server impact, but it produces ugly thumbs and I don't think its really an improvement over the one you copied it from at all (with the exception of ignoring a user specified server). The one you copied it from maintaned the aspect ratio.

-vissa

Thats why the credited version would be better for you.

I could care less about the ratio when a person hosts huge images. Plus, I want it crushed, so the members will know the image is off my server and not, well, approved. I removed the link from this, but it would be an easy add to get an href added.

S@NL - BlackBik
01-31-2006, 06:53 PM
Vissa, check this post (https://vborg.vbsupport.ru/showpost.php?p=887015&postcount=92), an anwer to this question 'bout javascript that you also posted in that thread ;)

Zia
02-01-2006, 03:17 AM
finally what comes with this ?

exclude sigs ...possible?

hiiped
03-17-2006, 11:01 PM
Is there anyway to do this just by width so that the image doesn't lose aspect ratio? I hate it when folks break my designs with big ole images, but I don't want to torture their images either... just curious.

thanks!
use

border="1" width="100" /

OR

border="1" height="100" /