posthtml / posthtml-img-autosize

Auto setting the width and height of <img>
MIT License
28 stars 8 forks source link

Auto-size percent values #2

Open maltsev opened 8 years ago

maltsev commented 8 years ago
// <img src="100x50.png" width="50%" height="auto">
// ->
// <img src="100x50.png" width="50" height="25">
maltsev commented 6 years ago

@bashaus I tested your solution a bit and noticed that it works differently from the browser approach to render images and what developers are expected to see.

So <img src="100x50.png" width="50%" height="50%"> becomes <img src="100x50.png" width="50" height="25"> which looks logical. But a browser would render that differently: https://jsfiddle.net/5w8wy5m8/5/

So I think we should keep percentage values as they're and don't change them. But I'm not sure how should we handle <img src="100x50.png" width="50%" height="auto"> then. Converting it to <img src="100x50.png" width="50" height="25"> doesn't seem right to me now. Neither is <img src="100x50.png" width="50%" height="25"> correct.

Any ideas?

bashaus commented 6 years ago

I'm not entirely sure what to choose.

To be honest, I would never use 100% width/height in image attributes to represent 100% of the screen because that should be done in CSS. The reason that I use this plugin is to put the image width/height into the HTML to ensure that a redraw does not occur.

I guess it depends on the use case of the plugin. What do you think?

maltsev commented 6 years ago

Right. Though, the whole idea of PostHTML (as I understand it) is to extend HTML, not to change its behavior. Therefore I think changing percent values by default isn't right thing to do. So maybe we should add an option for enabling that (like processEmptySize)?