Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#76 2010-07-17 22:41:51

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Images are 1st class citizens of TXP

Yeah baby, yeah. Spank that image!

I mean, cool, Stef :-)

Offline

#77 2010-07-17 23:42:33

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Images are 1st class citizens of TXP

Bloke wrote:

(for Adi) size="0" will shut off the dimensions for you. Easy!

Small but beautifully formed, thanks.

Offline

#78 2010-07-18 12:51:36

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: Images are 1st class citizens of TXP

Wait guys, let me keep step:
In case I’ve understood, a numerary, 0, is the equivalent of auto?


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#79 2010-07-18 12:55:09

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,424
Website GitHub

Re: Images are 1st class citizens of TXP

uli wrote:

Wait guys, let me keep step:
In case I’ve understood, a numerary, 0, is the equivalent of auto?

Hold fire. I broke rule #3: never code at midnight becuase you miss the obvious. Namely that <txp:thumbnail /> already has width and height attributes so it makes sense to do the same here. Yes it’s a bit more typing (sorry Adi) but it’s much cleaner and shorter. Good thing wet’s here to keep me in check eh?!

Fix on its way.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#80 2010-07-18 13:08:08

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,424
Website GitHub

Re: Images are 1st class citizens of TXP

Take two. Same feature set, just requires a bit more typing to turn width and height off (sorry again Adi but it makes sense for consistency).

So to turn off both height and width you use width="0" height="0". If either are omitted you get the size from the database being output.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#81 2010-07-18 13:48:56

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: Images are 1st class citizens of TXP

Bloke wrote:

So to turn off both height and width you use width="0" height="0".

My concern was rather the use of 0. TXP uses 0 as a boolean, for px measures, and now it seems to mean auto, and of all things in a context where otherwise numbers are used for pixel measures: if the numeral is not 0. Confuses me, I’d expect to use auto in these cases. Would be much more unambiguous.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#82 2010-07-18 16:36:50

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,424
Website GitHub

Re: Images are 1st class citizens of TXP

uli wrote:

My concern was rather the use of 0. TXP uses 0 as a boolean, for px measures, and now it seems to mean auto,

It doesn’t mean auto… err does it? It retains its usual meaning: ‘off’, i.e. don’t put a width and height in the <img> tag. Why would you want to specify that one dimension of your image was ‘0’ — your image would not be visible?

If you use any other value(s) then you set the width/height to those fixed dimensions. If you omit one (or both) entirely you get default behaviour — as it has always been — which uses the size from the database.

Or have I got it wrong again?

Last edited by Bloke (2010-07-18 16:38:39)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#83 2010-07-18 20:21:48

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Images are 1st class citizens of TXP

I’m not sure if auto would be a good idea – it might get confused with the CSS auto value. What we’re doing here is just preventing the width="" height="" attributes from being rendered.

I haven’t got an issue with using 0 – it’s just one of those conventions in computing. In fact, I’ve seen the use of -1 in the past to switch something off, as opposed to setting to zero.

One other thing. Shouldn’t width="0" imply height="0? I can’t imagine why you’d want to specify only one dimension in HTML & maybe the other in CSS.

Offline

#84 2010-07-18 20:39:34

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Images are 1st class citizens of TXP

gomedia wrote:

Shouldn’t width="0" imply height="0? I can’t imagine why you’d want to specify only one dimension in HTML & maybe the other in CSS.

If you set only one dimension, the browser will scale the image accordingly in correct aspect ratio.

Last edited by Gocom (2010-07-18 20:40:20)

Offline

#85 2010-07-18 20:55:34

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Images are 1st class citizens of TXP

Gocom wrote:

If you set only one dimension, the browser will scale the image accordingly in correct aspect ratio.

Maybe, but if HTML <img width="x" height="y" /> is the same as <img height="y" /> then what’s the point of <txp:image width="0" />?

Are we making things too complicated? Why not have a TXP image attribute dimensions="0" and let the user use CSS to manipulate width/height?

Offline

#86 2010-07-18 21:38:03

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,424
Website GitHub

Re: Images are 1st class citizens of TXP

gomedia wrote:

if HTML <img width="x" height="y" /> is the same as <img height="y" />

It’s not… is it? <img width="x" height="y" /> means your image will appear x wide and y high. <img height="y" /> means your image will appear y high and take on the x dimension as stored in the database, potentially stretching/squashing the image. Adding width="0" means use ‘whatever x is necessary to avoid aspect ratio distortion’.

I can see a use for this if, say, you’ve uploaded a bunch of images and want to show a gallery via <txp:image_list />. You could fix the size of the images on the screen so when they view as a grid they are all nice and identical but that might distort some of them more than we cared — especially if they were a mix of portrait and landscape. Conversely, letting them be of any size at all might mean visual problems (especially if you have multiple people uploading pics and don’t want to impose too many restrictions). So perhaps you as designer might like to always ensure visitors see 4 images in each row of the grid. So you set width="100" height="0", your grid takes up 400 px (+padding/margin) but all images will retain their aspect ratio and be less distorted.

I think part of the reason I decided on a single size attribute in the first place over separate width and height was convenience; though the two outcomes are identical in terms of rendered markup, size="0" (a.k.a. dimensions="0") really did mean “shut up and let me do all the sizing myself”. With separate width and height you really do need to specify both (even if they are both 0) for any reasonable non-distorted output.

Being able to control image size through CSS is great if you want to use ems or %: I dunno as I’ve never done it. On the pixel front, what’s the difference between:

<txp:image class="pic" width="600" height="800" />

and

<txp:image class="pic" width="0" height="0" />
<style type="text/css">
.pic {
   width:600px;
   height:800px;
}
</style>

besides a lot more bytes to download? At least being able to specify your own width and height inline means you’re not forced to size them entirely with CSS or entirely from the database: you can mix and match whatever suits the application.

Last edited by Bloke (2010-07-18 21:40:19)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#87 2010-07-18 21:52:01

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Images are 1st class citizens of TXP

Bloke wrote:

It’s not… is it? <img width="x" height="y" /> means your image will appear x wide and y high. <img height="y" /> means your image will appear y high and take on the x dimension as stored in the database, potentially stretching/squashing the image.

Er, I’m talking about rendered HTML code here – <img width="x" height="y" /> – so TXP & the database has already done its thing.

I can see a use for this if, say, you’ve uploaded a bunch of images and want to show a gallery via <txp:image_list />. You could fix the size of the images on the screen so when they view as a grid they are all nice and identical but that might distort some of them more than we cared — especially if they were a mix of portrait and landscape. Conversely, letting them be of any size at all might mean visual problems (especially if you have multiple people uploading pics and don’t want to impose too many restrictions). So perhaps you as designer might like to always ensure visitors see 4 images in each row of the grid. So you set width="100" height="0", your grid takes up 400 px (+padding/margin) but all images will retain their aspect ratio and be less distorted.

I’ve never done a gallery, so I’m happy to defer to your wisdom on this.

… “shut up and let me do all the sizing myself” …

That’s the goldfish I want!

Offline

#88 2010-07-18 22:11:56

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,316

Re: Images are 1st class citizens of TXP

Bloke wrote:

Or have I got it wrong again?

No, this time it was me. At least a tad. (But then again the post with the tag’s terminology has vanished.)

What I actually mean: will users remember to use the zero for dimensions off or omit dimensions?
You’re right, auto is misleading. But I don’t care how you name it, for my part height="off" or height="omit" would be pretty memorable and unequivocally, but I’m afraid very few people will remember using the 0 in a place where the use of other numerals has a completely different meaning. They rather will take it literally and useit for obtaining zero-height images.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#89 2010-07-18 22:42:22

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,424
Website GitHub

Re: Images are 1st class citizens of TXP

gomedia wrote:

Er, I’m talking about rendered HTML code here – <img width="x" height="y" /> – so TXP & the database has already done its thing.

Right, gotcha. I see what you’re getting at. I’ll probably have to test this more thoroughly as I may be talking gibberish but my understanding was that if the <img> tag had a width and a height the browser displayed the image at those exact dimensions: if they happen to coincide with the dimensions of the actual image then it’s displayed pixel-perfect; otherwise it’s scaled / squashed / stretched to meet your demands.

If, however, only one of the dimensions is present in the <img> tag, the other is calculated by the browser to maintain aspect ratio. Here’s my reference test: upload a landscape picture of about 600 × 800px, create an article and set the article image to the ID of your image, then put this in the article Body, and view the output (both on-screen and HTML source):

<txp:article_image /> <!-- TXP actual full image size (TXP outputs width and height) -->
<txp:article_image width="0" height="0" /> <!-- No height/width. Create your own (default: actual image size) -->
<txp:article_image width="100" height="0" /> <!-- Fixed width: browser-controlled (or your own custom) height  -->
<txp:article_image width="0" height="100" /> <!-- Fixed height: browser-controlled (or custom) width -->
<txp:article_image width="100" /> <!-- Fixed width: TXP adds height="600" so the image is horizontally squashed -->
<txp:article_image height="100" /> <!-- Fixed height: TXP adds width="800" so the image is vertically squashed  -->
<txp:article_image width="80" height="100" /> <!-- Browser forced to render the image at these reduced dimensions -->

That gives a variety of different effects that I think make sense. If anyone disagrees let’s iron out the expected behaviour now.

uli wrote:

very few people will remember using the 0 in a place where the use of other numerals has a completely different meaning

Maybe. I was just trying to build some flexibility into it without introducing magic numbers that are more things people would have to remember. In TXP the convention is:

  • 0=off
  • unset=default behaviour

and I figured that it was safe to use 0 in this context simply because I can’t see any reason for someone to go to the trouble of writing an image tag that didn’t display an image (i.e. willfully display an invisible image). Perhaps I’ve missed a use case somewhere…?


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#90 2010-07-18 23:29:17

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Images are 1st class citizens of TXP

Please, don’t change the 0 (false) to anything else. Every attribute in every tag should use same value for false. And as 0 is the standard used across programming languages, then it’s the best choise no matter what the attribute does.

Using yet different value makes it extremely hard to remember the values. And as a extra bonus, using 0 makes TXP source code smaller by couple bits than doing string comparisons.

Last edited by Gocom (2010-07-18 23:35:06)

Offline

Board footer

Powered by FluxBB