Advertisement:

Author Topic: Allowing align in img tags  (Read 24437 times)

Offline Mike Bobbitt

  • Full Member
  • ***
  • Posts: 597
    • Army.ca
Allowing align in img tags
« on: October 30, 2004, 10:30:20 AM »
If you "Enable basic HTML in posts" then you can use <img> tags which is nice, but it would be very handy if you could do something like this:

Code: [Select]
<img src="http://army.ca/img/tmp/tdv_int_1.jpg" align="right">
Without the alignment, the image forces text down to the next line, but with the above tag, the text 'wraps' around it. It looks *much* nicer with the text wrapped around the images.

Unfortunately SMF doesn't recognize align as a valid attribute at the moment, and ignores the whole tag.

Offline Mike Bobbitt

  • Full Member
  • ***
  • Posts: 597
    • Army.ca
Re: Allowing align in img tags
« Reply #1 on: October 30, 2004, 01:54:46 PM »
Here's an example of what you can do: http://army.ca/forums/index.php/topic,21969.0.html

I had to edit the entry directly in the DB for that to work as is.

Offline codenaught

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 14,653
  • Gender: Male
  • Formerly Known As akabugeyes
Re: Allowing align in img tags
« Reply #2 on: October 30, 2004, 02:31:09 PM »
Yeah, I also would like something like that.

It can be handy to not have the text below the image I think it could be quite useful.
Dev Consultant
Former SMF Doc Coordinator

Offline force

  • Semi-Newbie
  • *
  • Posts: 21
Re: Allowing align in img tags
« Reply #3 on: October 31, 2004, 10:19:53 AM »
Try this:

In subs.php

Find:
Code: [Select]
'~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?\s*\](?:<br />)*(.+?)(?:<br />)*\[/img\]~ei' => isset($disabled['img']) ? '\'$5\'' : '\'<img src="$5" alt=""\' . (\'$2\' != \'\' ? \' width="$2"\' : \'\') . (\'$4\' != \'\' ? \' height="$4"\' : \'\') . \' border="0" />\'',
Add below:
Code: [Select]
'~\[img(\s+width=([\d]+))?(\s+align=(.+?))?\s*\](?:<br />)*(.+?)(?:<br />)*\[/img\]~ei' => isset($disabled['img']) ? '\'$5\'' : '\'<img src="$5" alt=""\' . (\'$2\' != \'\' ? \' width="$2"\' : \'\') . (\'$4\' != \'\' ? \' align="$4"\' : \'\') . \' border="0" hspace="5"/>\'',
Now you can post images like this:
Code: [Select]
[img align=right]http://www.yoursite.com/pic1.jpg[/img]

or

[img align=left]http://www.yoursite.com/pic2.jpg[/img]

force

Offline Elijah Bliss

  • Sophist Member
  • *****
  • Posts: 1,340
Re: Allowing align in img tags
« Reply #4 on: November 02, 2004, 05:31:48 AM »
Try this:

In subs.php

Find:
Code: [Select]
'~\[img(\s+width=([\d]+))?(\s+height=([\d]+))?\s*\](?:<br />)*(.+?)(?:<br />)*\[/img\]~ei' => isset($disabled['img']) ? '\'$5\'' : '\'<img src="$5" alt=""\' . (\'$2\' != \'\' ? \' width="$2"\' : \'\') . (\'$4\' != \'\' ? \' height="$4"\' : \'\') . \' border="0" />\'',
Add below:
Code: [Select]
'~\[img(\s+width=([\d]+))?(\s+align=(.+?))?\s*\](?:<br />)*(.+?)(?:<br />)*\[/img\]~ei' => isset($disabled['img']) ? '\'$5\'' : '\'<img src="$5" alt=""\' . (\'$2\' != \'\' ? \' width="$2"\' : \'\') . (\'$4\' != \'\' ? \' align="$4"\' : \'\') . \' border="0" hspace="5"/>\'',
Now you can post images like this:
Code: [Select]
[img align=right]http://www.yoursite.com/pic1.jpg[/img]

or

[img align=left]http://www.yoursite.com/pic2.jpg[/img]

force

This works fine but the problem is that is disables the height and width attributes.

Offline force

  • Semi-Newbie
  • *
  • Posts: 21
Re: Allowing align in img tags
« Reply #5 on: November 02, 2004, 06:57:16 AM »
You can still use width like this:

Code: [Select]
[img width=200 align=right]http://www.yoursite.com/pic1.jpg[/img]

You can see an example here: http://www.pocketforce.com/forum/index.php?topic=2780.0 [nofollow]
(this is just a temporary post, and will be deleted later)

Offline Mike Bobbitt

  • Full Member
  • ***
  • Posts: 597
    • Army.ca
Re: Allowing align in img tags
« Reply #6 on: November 02, 2004, 11:05:36 AM »
That looks great... Thanks for the code snippit. Hopefully it'll make it into the base SMF code at some point. :)

Offline Peter Duggan

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 4,663
  • Gender: Male
    • Peat Stack or Pete's Tack?
Re: Allowing align in img tags
« Reply #7 on: November 02, 2004, 12:52:08 PM »
Perhaps a 'float' tag might be more versatile because anything that could do spans or divs with style="float: left;" or style="float: right;" should effectively render those align attributes redundant.

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Allowing align in img tags
« Reply #8 on: November 02, 2004, 05:52:28 PM »
Perhaps a 'float' tag might be more versatile because anything that could do spans or divs with style="float: left;" or style="float: right;" should effectively render those align attributes redundant.

I agree. I said in the past that I'd do this and then forgot about it or had other things to do. I'll try to code this soon. Just need to search a bit on browser issues with floats and fixes and stuff to make sure it'll render fine for most.
Cristián Lávaque http://cristianlavaque.com

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Allowing align in img tags
« Reply #9 on: November 02, 2004, 06:50:16 PM »
'~\[float=(right|left)\](.+?)\[/float\]~' => '<div style="float: $1;">$2</div>',

And change:
'~\[hr(?:\s*/)?\]~i' => isset($disabled['hr']) ? '' : '<hr style="clear: both;" />',
'~\[br(?:\s*/)?\]~i' => '<br style="clear: both;" />',

-[Unknown]

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Allowing align in img tags
« Reply #10 on: November 02, 2004, 08:03:25 PM »
There also needs to be a clear both at the end of the message body or the float may bleed out. And there's an issue with backgrounds in IE that needs a little tweaking in the template, too.

* Anguz goes look for some links...

http://css.maxdesign.com.au/floatutorial/clear.htm
http://www.positioniseverything.net/explorer/peekaboo.html
http://www.positioniseverything.net/articles/hollyhack.html#haslayout
Cristián Lávaque http://cristianlavaque.com

Offline [Unknown]

  • SMF Friend
  • SMF Master
  • *
  • Posts: 36,102
  • Gender: Male
Re: Allowing align in img tags
« Reply #11 on: November 02, 2004, 11:48:48 PM »
True, but that's the general idea.....

-[Unknown]

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Allowing align in img tags
« Reply #12 on: November 03, 2004, 12:15:30 AM »
Yup. I'll try to get to this mod soon. Gotta finish something else first. ;)
Cristián Lávaque http://cristianlavaque.com

Offline frost

  • Semi-Newbie
  • *
  • Posts: 63
Re: Allowing align in img tags
« Reply #13 on: August 31, 2005, 01:04:22 PM »
any luck with this one?

Offline Mike Bobbitt

  • Full Member
  • ***
  • Posts: 597
    • Army.ca
Re: Allowing align in img tags
« Reply #14 on: August 31, 2005, 04:54:19 PM »
The new beta allows admins to use [html] tags which solves the problem for me...
« Last Edit: August 31, 2005, 06:20:49 PM by [Unknown] »

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Allowing align in img tags
« Reply #15 on: September 01, 2005, 02:33:18 AM »
any luck with this one?

Well, you could use my Custom BBcode mod to create that float tag, but it'd be for 1.0.5 only, cause I haven't re-written it for 1.1 and don't plan to do it soon.
Cristián Lávaque http://cristianlavaque.com

Offline frost

  • Semi-Newbie
  • *
  • Posts: 63
Re: Allowing align in img tags
« Reply #16 on: September 01, 2005, 09:23:17 AM »
i'm a bit confused over the creation of the tag...  ??? ??? ???

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Allowing align in img tags
« Reply #17 on: September 01, 2005, 06:31:44 PM »
Please ignore my previous post in this topic. I totally forgot that the version of my mod that supports parameters I never released. Really sorry :-\.
Cristián Lávaque http://cristianlavaque.com

Offline frost

  • Semi-Newbie
  • *
  • Posts: 63
Re: Allowing align in img tags
« Reply #18 on: September 01, 2005, 06:39:57 PM »
well....now that i installed it, i could use a hint or two... ;)

Offline Anguz

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 3,430
  • Gender: Male
    • cristianlavaque.com
Re: Allowing align in img tags
« Reply #19 on: September 01, 2005, 10:10:34 PM »
Well, it's not really practical without the parameters, but you could create a couple tags named something like imgleft and imgright, but it's not a very elegant solution. What trouble are you having to add the align tag the way [Unknown] suggests?
Cristián Lávaque http://cristianlavaque.com