The current resizing syntax accepts a size argument in the form of |WxH[, perc%]
, where the WxH
part appears always madatory. However, folks (read: I) occasionally want to only specify either the width/height (maintaining ratio, of course) or the percentage only. Will it be a good idea to relax these constraints?
Here’s a list of possible extensions, meant to duplicate the functionalities of MediaWiki’s image sizes:
-
WxH
extensions-
|W
(e.g.![foo|220]
) can interpreted as a request to only add awidth
attribute to theimg
element generated. -
|xH
(e.g.![foo|x200]
) can interpreted as a request to only add aheight
attribute to theimg
element generated. -
brainless scalng:
|MWxH
(e.g.![foo|M200x200]
) sets the maximum dimension of the image to 200x200px, but does not distort it when scaling. (Inlinestyle
?)- usage note: on Wikipedia this is most useful for fitting images into a box of a given size, centered and padded automatically. There aren’t many fixed-size boxes in discourse, so it might be more useful making it an
img
with margin/padding added to reach the target size. Sounds a bit too complicated though.
- usage note: on Wikipedia this is most useful for fitting images into a box of a given size, centered and padded automatically. There aren’t many fixed-size boxes in discourse, so it might be more useful making it an
- Most modern browsers does a proportional scaling with only one dimension given. Something along the lines of
img { width: auto; height: auto }
may be required for older stuff. - Only specifying one dimension obviously can cause abrupt layout changes as the image gets loaded. To avoid it, maybe auto-rewrite the expression into the full
WxH
form on save?
-
- percent-only sizing (
![|50%]
)- This is the same as
[|WxH,perc%]
, whereWxH
are the real dimensions of the image. - Applying percentages to
img
's dimension attributes is awful, so this must get rewritten into the fullWxH
form.
- This is the same as
Security considerations
- Expanding the expression into a usual
WxH
form involves opening an image and reading its dimensions. If there’re some vulnerbilities in your image-handling libraries, you may be doomed. - Having the server fetch a remote image is a good way to expose the server IP, which might be hidden behind some sort of an anti-DDoS CDN. Maybe only rewrite the sizes on local imgs?
- Discourse already fetches remote images to generate a metadata section.