Skip to content

Instantly share code, notes, and snippets.

@uupaa
Last active December 21, 2024 16:12
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

@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