1

Topic: Auto resize images

..ok, I've searched a while, but couldn't find anything working.

I have a fixed width of my forum and the postarea is about 660px wide. Now, if a image, larger than that, is posted with the image tag it is getting squeezed to the width of the postarea, but remains in the original height. Is it possible to have it "scaled" down to fit the width but aspect ratio? Clicking on that image would open it in original size with Lightbox?

2

Re: Auto resize images

Moved. That would certainly be a mod if it involves lightbox integration.

3

Re: Auto resize images

...well I have a Lightbox integration for the mod "Image_Upload", but what can I do with the images displaying with the image tag? I don't understand, why they are squeezed in the width.

4 (edited by Tjalve 2007-06-27 17:15)

Re: Auto resize images

they are squeezed in with because of there is no overflow controll in the css.
You can add it but still annoying too have too scroll too see the rest.

I just added a new image tag instead. ex: the image gets resized too x width and i added a text under saying "This image has been resized, click here to view the full-sized image."
I can post the code if you like

Post hoc ergo propter hoc

5

Re: Auto resize images

Tjalve wrote:

they are squeezed in with because of there is no overflow controll in the css.
You can add it but still annoying too have too scroll too see the rest.

I just added a new image tag instead. ex: the image gets resized too x width and i added a text under saying "This image has been resized, click here to view the full-sized image."
I can post the code if you like

..yes, please smile

6 (edited by Tjalve 2007-06-27 17:30)

Re: Auto resize images

parser.php:

Find:

'#\[img\]\s*(.*?)\s*\[/img\]#is',

Add after:

'#\[imgrs\]\s*(.*?)\s*\[/imgrs\]#is',

Find:

'[img]$1[/img]',

Add after:

'[imgrs]$1[/imgrs]',

Find (2 palces):

$text = preg_replace('#\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]#e', 'handle_img_tag(\'$1$3\')', $text);

Add after:

$text = preg_replace('#\[imgrs\]((ht|f)tps?://)([^\s<"]*?)\[/imgrs\]#e', 'handle_img_tag_res(\'$1$3\')', $text);

Find:

    return $img_tag;
}

Add after:

function handle_img_tag_rs($url, $is_signature = false)
{
    global $lang_common, $pun_config, $pun_user;

    $img_tag = '<a href="'.$url.'" onclick="window.open(this.href); return false;"><'.$lang_common['Image link'].'></a>';

    if ($is_signature && $pun_user['show_img_sig'] != '0')
        $img_tag = '<img class="sigimage" src="'.$url.'" alt="'.htmlspecialchars($url).'" />';
    else if (!$is_signature && $pun_user['show_img'] != '0')
        $img_tag = '<img width="500" class="postimg" src="'.$url.'" alt="'.htmlspecialchars($url).'" /> <br> This image has been resized, click <a href="'.htmlspecialchars($url).'">here</a> to view the full-sized image.';
    return $img_tag;
}

Save and upload smile
Hope that was everything, long time since I added it


Now you have a new image tag called

[imgrs][/imgrs]
Post hoc ergo propter hoc

7

Re: Auto resize images

...thank's, I will try that smile

8

Re: Auto resize images

..hmmm, doesn't work - maybe I have already too many mods in my parser.
I got this error:

Fatal error: Call to undefined function: handle_img_tag_res() in /kunden/994499865/forum/include/parser.php(810) : regexp code on line 1

Re: Auto resize images

hmm you did something wrong when adding:

function handle_img_tag_rs($url, $is_signature = false)
{
    global $lang_common, $pun_config, $pun_user;

    $img_tag = '<a href="'.$url.'" onclick="window.open(this.href); return false;"><'.$lang_common['Image link'].'></a>';

    if ($is_signature && $pun_user['show_img_sig'] != '0')
        $img_tag = '<img class="sigimage" src="'.$url.'" alt="'.htmlspecialchars($url).'" />';
    else if (!$is_signature && $pun_user['show_img'] != '0')
        $img_tag = '<img width="500" class="postimg" src="'.$url.'" alt="'.htmlspecialchars($url).'" /> <br> This image has been resized, click <a href="'.htmlspecialchars($url).'">here</a> to view the full-sized image.';
    return $img_tag;
}

try and remove it  and add it at the bottom of the file.

Post hoc ergo propter hoc

10

Re: Auto resize images

no, doesn't work either
I got the same error, but for another line after this:

$text = preg_replace('#\[imgrs\]((ht|f)tps?://)([^\s<"]*?)\[/imgrs\]#e', 'handle_img_tag_res(\'$1$3\')', $text);

...but that line is empty!?

11

Re: Auto resize images

hmm strange...
ah, remove the

function handle_img_tag_rs($url, $is_signature = false)
{

 blablablalbla

}

from the bottom of the file.

I think you added it in the wrong place the first time.

Find:

    return $img_tag;
}

As you can see, add it after the } and NOT after return $img_tag;

Post hoc ergo propter hoc

12

Re: Auto resize images

....now I have the error for the line:

$text = preg_replace('#\[imgrs\]((ht|f)tps?://)([^\s<"]*?)\[/imgrs\]#e', 'handle_img_tag_res(\'$1$3\')', $text);

....very strange

13

Re: Auto resize images

Fatal error: Call to undefined function: handle_img_tag_res() blablabla ?

Post hoc ergo propter hoc

14

Re: Auto resize images

Yepp,

Fatal error: Call to undefined function: handle_img_tag_res() in /kunden/994499865/forum/include/parser.php(810) : regexp code on line 1

15

Re: Auto resize images

ah, typo on my part there tongue

find:
$text = preg_replace('#\[imgrs\]((ht|f)tps?://)([^\s<"]*?)\[/imgrs\]#e', 'handle_img_tag_res(\'$1$3\')', $text);

replace with:
$text = preg_replace('#\[imgrs\]((ht|f)tps?://)([^\s<"]*?)\[/imgrs\]#e', 'handle_img_tag_rs(\'$1$3\')', $text);

Sorry about that.

Post hoc ergo propter hoc

16 (edited by no64 2007-06-27 19:00)

Re: Auto resize images

smile smile smile smile smile    ....that's it! Thank's Tjalve.   Just one more question: Do you have an idea how to center that image tag?



....or maybe even use it with Lightbox

17 (edited by no64 2007-06-27 19:13)

Re: Auto resize images

...what is the relevant code, that resize the image and how can I control the size of the image?

* ..sorry, found that "size-thing"

18

Re: Auto resize images

Find:

$img_tag = '<img width="500" class="postimg" src="'.$url.'" alt="'.htmlspecialchars($url).'" /> <br> This image has been resized, click <a href="'.htmlspecialchars($url).'">here</a> to view the full-sized image.';

Replace with one of these:

centered:

$img_tag = '<center><img width="500" class="postimg" src="'.$url.'" alt="'.htmlspecialchars($url).'" /> <br> This image has been resized, click <a href="'.htmlspecialchars($url).'">here</a> to view the full-sized image.</center>';

Lightbox:

$img_tag = '<a href="'.$url.'" rel="lightbox"><img width="500" class="postimg" src="'.$url.'" alt="'.htmlspecialchars($url).'" /></a> <br> This image has been resized, click <a href="'.htmlspecialchars($url).'">here</a> to view the full-sized image.';

Lightbox and Centered:

$img_tag = '<center><a href="'.$url.'" rel="lightbox"><img width="500" class="postimg" src="'.$url.'" alt="'.htmlspecialchars($url).'" /></a> <br> This image has been resized, click <a href="'.htmlspecialchars($url).'">here</a> to view the full-sized image.</center>';

You can change the width by changeing the "width="500"" too something else ofc.

Post hoc ergo propter hoc

19

Re: Auto resize images

This is great  big_smile  - you have to post this as an official Mod!

Is it also possible to have this also as the "normal" image tag (without "rs") and let's say have some variable to "tell" Lightbox if the original size of the image is bigger than 660px it will be clickable and opened with Lightbox?

20

Re: Auto resize images

you can with php but if you have alot of images the page is gonna be SLOW.

Post hoc ergo propter hoc

21

Re: Auto resize images

ist it gonna to be slow cause the size check "if or not" or cause it would be the standard image tag?

22

Re: Auto resize images

i made a lightbox gallery for punbb.. and im about to redo it with tickbox about 45% faster than light box...


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

23

Re: Auto resize images

ohhh, just took me the whole day to make tha Lightbox-thing, and now I have to hear it is slow.....so thickbox is better and faster, what about greybox?

24

Re: Auto resize images

all the xxxboxes that is out..hahaha.....

look at my script see how things are done in there...
http://www.punres.org/viewtopic.php?pid=8387#p8387

that might help you..


Q

My stuff or my style might sux, but atleast I'm willing to help when I can.
Don't be stupid and help ! We are the stupid one's !!!

Re: Auto resize images

quaker, can you hop on aim/msn?

~James
FluxBB - Less is more