Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image resizing with Markdown assumes height = width and distorts image #1064

Closed
1 task done
maubuz opened this issue Mar 11, 2020 · 2 comments · Fixed by #1065
Closed
1 task done

Image resizing with Markdown assumes height = width and distorts image #1064

maubuz opened this issue Mar 11, 2020 · 2 comments · Fixed by #1065
Labels

Comments

@maubuz
Copy link
Contributor

maubuz commented Mar 11, 2020

Bug Report

Steps to reproduce

Resize a rectangular image with Markdown by specifying only a width. Bug started after latest update on March 9th.

![canoe](assets/canoe.png ':size=200')

What is current behaviour

The rendered html is an image with width and height equal to the width specified in Markdown.

<img src="/./wk7/assets/canoe.png" data-origin="assets/canoe.png" alt="canoe" width="200" height="200">

image

What is the expected behaviour

The rendered image to have the width as specified in Markdown, and no height. This would cause the html to automatically resize the height in order to respect its aspect ratio (default html behavior).

<img src="/./wk7/assets/canoe.png" data-origin="assets/canoe.png" alt="canoe" width="200">

image

This would be consistent with the Docsify documentation for resizing images with Markdown. The image example in the documentation works because it is nearly a square.

Other relevant information

I'm not very familiar with Docsify yet but I believe the bug is caused by image.js between lines 20 and 27:

    if (config.size) {
      const [width, height] = config.size.split('x');
      if (height) {
        attrs.push(`width="${width}" height="${height}"`);
      } else {
        attrs.push(`width="${width}" height="${width}"`);
      }
    }

If height="${width}" is removed from the else statement then the html will fall back to default behavior.

I compiled a local version with the change above and it seemed to fix it. I'm not sure if breaks anything else tho .

Love the project and really appreciate all the work that goes into it.

  • Bug does still occur when all/other plugins are disabled?

  • Your OS: Fedora 31

  • Node.js version: v13.10.1

  • npm/yarn version: 6.13.7

  • Browser version: Firefox 73 and Chrome 80

  • Docsify version: src="//unpkg.com/docsify/lib/docsify.min.js"

  • Docsify plugins: docsify-themeable, search, docsify-pagination, zoom-image, copy-code

@anikethsaha anikethsaha added the bug confirmed as a bug label Mar 11, 2020
@anikethsaha
Copy link
Member

anikethsaha commented Mar 11, 2020

Seems
like a bug . It should be

  if (config.size) {
      const [width, height] = config.size.split('x');
      if (height) {
        attrs.push(`width="${width}" height="${height}"`);
      } else {
        attrs.push(`width="${width}"`);
      }
    }

Feel free to submit a fix.
do check for the behavior when this example - :size=100

@maubuz
Copy link
Contributor Author

maubuz commented Mar 11, 2020

Thanks for the quick response. I've checked the example :size=100 and resizing looks as expected.
PR #1065 submitted.

jingqinglin added a commit to jingqinglin/blog that referenced this issue Jul 6, 2020
之前版本的图片显示尺寸有问题,docsify 修复了这个 bug(docsifyjs/docsify#1064
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants