Skip to content

Instantly share code, notes, and snippets.

@uupaa
Last active November 25, 2024 22:02
Show Gist options
  • Save uupaa/f77d2bcf4dc7a294d109 to your computer and use it in GitHub Desktop.
Save uupaa/f77d2bcf4dc7a294d109 to your computer and use it in GitHub Desktop.
image resize in github flavored markdown.

Image source

https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png

Try resize it!

  • ![](https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png | width=100)

  • ![](https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png =250x250)

  • ![](https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png)

    • Copy <img> in browser DevTools. Replace ![](url) to <img>. Add width(and height) attr.
    • <img src="https://camo.githubusercontent.com/..." data-canonical-src="https://gyazo.com/eb5c5741b6a9a16c692170a41a49c858.png" width="200" height="400" />

Other information

@mjbear
Copy link

mjbear commented Aug 12, 2024

alt{: width="50%"}

Still does not work in github repo readme. The {: width="50%"} part just does ignore.

The syntax for images with a specified width has changed over time.

HTML image tags are the way to go

@AndrianD
Copy link

height="450px" works for me. Thanks!

@mahendranv
Copy link

Just throwing in the Obsidian's image format

![[<url>|400]]

// Here 400 is the width

@AndrianD
Copy link

@mahendranv : Can you give an example with full syntax since your example doesn't work? Thanks

@mjbear
Copy link

mjbear commented Oct 2, 2024

@uupaa
I couldn't get any of the suggestions to function on GitHub.

img tags work fine though.

<img src="https://media1.tenor.com/m/ofDuH0hvGh8AAAAd/so-what-do-you-think.gif" width="200" title="Ray Romano saying What do you think?" alt="Ray Romano saying What do you think?"/>

Ray Romano saying What do you think?

Update: Except that markdown linters dislike inline HTML tags. 😞

@rahaaatul
Copy link

can we round the image border?

@mjbear
Copy link

mjbear commented Oct 7, 2024

can we round the image border?

@rahaaatul
It appears not.
I tried to use CSS styles via Preview, but they're stripped off.
Plus the official statement from the markup repo (as seen below).

Note

The HTML is sanitized, aggressively removing things that could harm you and your kin—such as script tags, inline-styles, and class or id attributes.

reference: https://github.com/github/markup

@rnag
Copy link

rnag commented Oct 25, 2024

alt{: width="50%"}

Still does not work in github repo readme. The {: width="50%"} part just does ignore.

The syntax for images with a specified width has changed over time.

HTML image tags are the way to go

Agreed... 100%.

GitHub (or markdown) syntax for images seems to be unstable, or else changes pretty frequently.

Going forward, a healthy mix of HTML image tags and anchor links seems the best approach (Example).

[
    <img
        src="MY_SRC_HERE" 
        width=70%
        title="My Image"
        alt="My Image"
    />
](MY_LINK_HERE)

@Sandwich1699975
Copy link

The following worked well for me

<p align="center">
    <img src="assets/image.png" alt="Description" width="300">
</p>

The centring container is optional of course

@mjbear
Copy link

mjbear commented Oct 27, 2024

The following worked well for me

<p align="center">
    <img src="assets/image.png" alt="Description" width="300">
</p>

The centring container is optional of course

@Sandwich1699975
That's all fine and well except that markdown linters don't like inline HTML...

I found that out the hard way today. 🤷 😐

@crissyg
Copy link

crissyg commented Nov 16, 2024

If you want all your images to automatically resize to 150 x 150 pixels in the README.md with no additional HTML or CSS in GitHub, the following steps worked for me:

  1. Upload image(s) to your repo.
  2. Go to to where your image is saved in you repo using your browser. Notice the image size is just a preview and not the actual size.
  3. Right click and select copy image.
  4. Edit and paste in the README.md(use browser to edit).
  5. Github briefly shows !!Uploading image.. in the editor then it changes ![image](https://github.com/user-attachments/assets/ffggfg-3202-0000-fdfd-somerandomnumbers
  6. Go to preview before you commit to check the image size which is now ~150 x 150 pixels in the readme.md file.

Additional Notes I noticed no matter how large your image is, GitHub image preview in the browser is ~610 x 610 pixels but if you manually copy and paste the image into README.md file it automatically goes to 150 x150 px . You can copy any image from any page on the web and paste it in the README.md, it does the same thing. Be sure to copy image and not image address. I used google Chrome browser for the above steps.

@mjbear
Copy link

mjbear commented Nov 16, 2024

If you want all your images to automatically resize to 150 x 150 pixels in the README.md with no additional HTML or CSS in GitHub, the following steps worked for me:

1. Upload image(s) to your repo.

2. Go to to where  your image is saved in you repo using your browser. Notice the image size is just a preview and not the actual size.

Is this the online repo on GitHub?

3. Right click and select _copy image_.

4. Edit and paste in the README.md(use browser to edit).

5. Github briefly shows **_!!Uploading image.._** in the editor then it changes _![image](https://github.com/user-attachments/assets/ffggfg-3202-0000-fdfd-somerandomnumbers_

6. Go to preview before you commit to check the image size which is now ~150 x 150 pixels in the readme.md file.

Additional Notes I noticed no matter how large your image is, GitHub image preview in the browser is ~610 x 610 pixels but if you manually copy and paste the image into README.md file it automatically goes to 150 x150 px . You can copy any image from any page on the web and paste it in the README.md, it does the same thing. Be sure to copy image and not image address. I used google Chrome browser for the above steps.

Hello @crissyg,

I wasn't able to duplicate this "preview" behavior with GitHub in my web browser.
What am I doing differently than you're describing?

For example I don't see a preview for these icons at vscodium.
https://github.com/VSCodium/vscodium/tree/master/icons/stable

Or at GitHub docs.
https://github.com/github/docs/tree/main/contributing/images

Thank you!

@crissyg
Copy link

crissyg commented Nov 17, 2024

Hi @mjbear ,

I clicked on one of the icons first. Example below:

image

https://github.com/VSCodium/vscodium/blob/master/icons/stable/codium_clt.svg
previewIcon

@mjbear
Copy link

mjbear commented Nov 17, 2024

I clicked on one of the icons first. Example below:

@crissyg
Thank you for the response.
Awesome.
There is certainly a small preview for SVG images as you've demonstrated.

I can't seem to get that to work for PNG or JPG though.
https://github.com/github/docs/blob/main/contributing/images/repository-fork-button.png
https://github.com/github/docs/blob/main/contributing/images/fastly_purge.jpg

@crissyg
Copy link

crissyg commented Nov 19, 2024

@mjbear You're welcome and yes you're right about .jgp and .png files. Those are showing the actual sizes and not automatically resizing like the .svg files. I've been using svg for icons mostly . But you could convert jpg to svg using https://www.freeconvert.com/jpg-to-svg and then try it that way or resize each jpg/png using html like in the previous posts. <img src="image_location/image_name.png" width="10%"/> and change the width percentage to your liking. Example <img src="https://github.com/github/docs/blob/main/contributing/images/fastly_purge.jpg" width="10%"/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment