posthtml-img-autosize
posthtml-img-autosize copied to clipboard
Auto-size percent values
// <img src="100x50.png" width="50%" height="auto">
// ->
// <img src="100x50.png" width="50" height="25">
@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?
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?
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)?