PDA

View Full Version : New Posting Features - Auto Resize images when Quoted


rokked
04-25-2007, 10:00 PM
Auto Resize Images when they're Quoted
Test with: 3.6.5

This is a pretty basic add on and also my first add on. If you see anything messed up in the code or something that could be done better, please comment and I'll fix it. I'm relatively new to the add-on scene, so there could be better ways to do this.

What does this mod do?
images that get posted within the QUOTE tag will be resized to a width of 100.
thumbnails will link to the url of the actual image.

Installation:
open includes/class_bbcode.php

find:

$template = $this->printable ? 'bbcode_quote_printable' : 'bbcode_quote';
eval('$html = "' . fetch_template($template) . '";');
return $html;
}


replace with:

$template = $this->printable ? 'bbcode_quote_printable' : 'bbcode_quote';
eval('$html = "' . fetch_template($template) . '";');
//### RESIZE IMAGES IN QUOTE TAGS
if ($this->contains_bbcode_img_tags($html))
{
$html = preg_replace('#\[img\]\s*(https?://([^<>*"]+|[a-z0-9/\\._\- !]+))\[/img\]#iUe', "\$this->handle_bbcode_timg(str_replace('\\\"', '\"', '\\1'), '')", $html);
}
//### RESIZE IMAGES IN QUOTE
return $html;
}


find:

function handle_bbcode_img_match($link)
{
$link = $this->strip_smilies(str_replace('\\"', '"', $link));

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

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


underneath that paste the following:

function handle_bbcode_timg($link)
{
$link = $this->strip_smilies(str_replace('\\"', '"', $link));

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

return '<a href="' . $link . '" target="_blank"><img src="' . $link . '" border="0" width="100" alt="" /></a>';
}


Save & Upload.

That should be it. Hopefully it works for you!

Shazz
04-25-2007, 10:52 PM
Nice thought, Creative idea, Ill try it on my test site :)

Fungsten
04-26-2007, 04:12 AM
I'll try it on my test server.

dope15gd
04-26-2007, 07:41 PM
working perfectly for me. thanks

Get Shorty
04-27-2007, 02:51 AM
Works flawlessly... Installed!

letsjoy
04-29-2007, 08:35 PM
Nice one thanks :)

Get Shorty
04-30-2007, 04:37 AM
I changed this to resize to 200 pixels...

It would be great if it didn't increase the size of small images.

hippiesimz
05-12-2007, 10:32 PM
works for 3.65

arco
05-13-2007, 02:03 AM
It would be great if it didn't increase the size of small images.
I'll second that. Looks kinda silly. :)

dope15gd
05-29-2007, 11:44 PM
I have a question regarding this and another hack.

I'm running the Nested Quotes (https://vborg.vbsupport.ru/showthread.php?threadid=148372) hack and it seems to have killed this hack. I'm not good with the code or I'd fix it myself. Anyway if you feel it's worth your time I'd appreciate it.

thanks

edit// solved my problem. somewhere along the line the file got replaced so I just had to reapply the hack.

JKatz
04-13-2008, 02:38 AM
Will this work with 3.6.9?

mahsazn
04-13-2008, 08:38 AM
what a good idea! i'll try it too...

pablete
01-31-2010, 02:14 AM
This mod work for vb4?

Thank's

PinkMilk
06-05-2012, 10:35 PM
I changed this to resize to 200 pixels...

It would be great if it didn't increase the size of small images.

I'll second that. Looks kinda silly. :)


I think changing to a link would be better, this way no small images are enlarged and saves even more space.

In the last code box find:
return '<a href="' . $link . '" target="_blank"><img src="' . $link . '" border="0" width="100" alt="" /></a>';
Replace with:
return '<a href="' . $link . '" target="_blank">' . $link . '</a>';

Not tested but should work

Crimdog
06-23-2012, 10:44 AM
I think changing to a link would be better, this way no small images are enlarged and saves even more space.

In the last code box find:
return '<a href="' . $link . '" target="_blank"><img src="' . $link . '" border="0" width="100" alt="" /></a>';
Replace with:
return '<a href="' . $link . '" target="_blank">' . $link . '</a>';

Not tested but should work

PinkMilk -

Is there any way you could modify this to return an if/then statement? I am using your modification above, but users are complaining and want to have the first image or two displayed as images, and the rest displayed as links. Is this easily possible?

PinkMilk
06-25-2012, 11:23 PM
@Crimdog: Sorry that's a little out of my PHP knowledge, good idea though.

christon26
06-26-2012, 12:32 AM
I changed this to resize to 200 pixels...

It would be great if it didn't increase the size of small images.

Change

return '<a href="' . $link . '" target="_blank"><img src="' . $link . '" border="0" width="100" alt="" /></a>';to

return '<a href="' . $link . '" target="_blank"><img src="' . $link . '" border="0" style="max-width: 100px;" alt="" /></a>';and that should do it, change the 100px to whatever size you want it to be :)