# Redimensionamento de imagem relaxado (menos parâmetros)

**URL:** <https://meta.discourse.org/t/relaxed-image-resizing-less-params/95442>\
**Category:** Feature\
**Created:** [23 Agosto , 2018 01:24 UTC](https://meta.discourse.org/t/relaxed-image-resizing-less-params/95442 "2018-08-23T01:24:37Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Artoria2e5](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/artoria2e5/32/109009_2.png) [@Artoria2e5](https://meta.discourse.org/u/Artoria2e5)\
**Post date:** [23 Agosto , 2018 01:24 UTC](https://meta.discourse.org/t/relaxed-image-resizing-less-params/95442/1 "2018-08-23T01:24:37Z")

</div>

[The current resizing syntax](https://meta.discourse.org/t/66812) 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](https://en.wikipedia.org/wiki/Wikipedia:Extended_image_syntax#Size):

- `WxH` extensions
  - `|W` (e.g. `![foo|220]`) can interpreted as a request to only add a `width` attribute to the `img` element generated.
  - `|xH` (e.g. `![foo|x200]`) can interpreted as a request to only add a `height` attribute to the `img` 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. (Inline `style`?)
    - 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.

  - 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%]`, where `WxH` are the real dimensions of the image.
  - Applying percentages to `img`’s dimension attributes is awful, so this must get rewritten into the full `WxH` form.

## 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.

---

_[View the full topic](https://meta.discourse.org/t/relaxed-image-resizing-less-params/95442)._
