# \`min ratio to crop\` 站点设置应尊重 Markdown 中定义的宽高比

**URL:** https://meta.discourse.org/t/min-ratio-to-crop-site-setting-should-respect-w-h-ratio-as-defined-in-markdown/138374
**Category:** Feature
**Created:** [2020 年1 月 12 日 09:13 UTC](https://meta.discourse.org/t/min-ratio-to-crop-site-setting-should-respect-w-h-ratio-as-defined-in-markdown/138374 "2020-01-12T09:13:44Z")
**Posts on this page:** 1
**Showing post:** 18

<div class="post-metadata">

### 作者： ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### 发布日期： [2020 年1 月 14 日 02:27 UTC](https://meta.discourse.org/t/min-ratio-to-crop-site-setting-should-respect-w-h-ratio-as-defined-in-markdown/138374/18 "2020-01-14T02:27:36Z")

</div>

@zogstrip 你对这段代码怎么看？

```ruby

    if crop
      cropped_width, cropped_height = ImageSizer.crop(original_width, original_height)

      if cropped_width < width
        width = cropped_width
        img["width"] = width
      end

      if cropped_height < height
        height = cropped_height
        img["height"] = height
      end
    end

```

与现有的实现对比：

> <https://github.com/discourse/discourse/blob/609625fa180715fcf253dcbe31d6f8daf8f8c5f8/lib/cooked_post_processor.rb#L324-L328>

这确实比当前行为更不易令人意外，也会让 @awesomerobot 感到满意。唯一明显的缺点是，这个测试显得非常非常非常依赖模拟数据。

> <https://github.com/discourse/discourse/blob/609625fa180715fcf253dcbe31d6f8daf8f8c5f8/spec/components/cooked_post_processor_spec.rb#L546-L572>

如果你认可，欢迎直接提交。

---

_[View the full topic](https://meta.discourse.org/t/min-ratio-to-crop-site-setting-should-respect-w-h-ratio-as-defined-in-markdown/138374)._
