Skip to content

Instantly share code, notes, and snippets.

@uupaa
Last active October 2, 2024 14:07
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

@itbj
Copy link

itbj commented Dec 27, 2021

👍

@shakiz
Copy link

shakiz commented Mar 10, 2022

HTML syntax worked great. Not that much more complicated than existing markup. You only need to set the width, the image tag will automatically set the height for you to keep the right aspect ratio

<img src="https://your-image-url.type" width="300">

this works easily

Yeah!! This works easily! Thanks.

@vinirossa
Copy link

for me, I need to remove the "px" in order to get it to work ;)

@arlenyvalle
Copy link

arlenyvalle commented Jun 22, 2022

@dirkk0
Copy link

dirkk0 commented Aug 17, 2022

Apply style to image, plz try this my css style

img[src*="#thumbnail"] {
   width:150px;
   height:100px;
}
img[title="thumbnail"] {
   width:200px;
}
img[alt$="-thumbnail"]{
    width:300px;
}

my coding style

![img](link#thumbnail) <!-- src = link#thumbnail -->
![img](link "thumbnail") <!-- title = thumbnail -->
![img -thumbnail](link) <!-- alt = img -thumbnail -->

awesome, thanks @iphearum !

@ericthemarques
Copy link

Thanks guys, it also worked for me. After getting the URL from pasting the image in the "Issues" tab, i pasted it on the readme file and replaced: ![image](https://your-image-url.type) with <img src="https://your-image-url.type" width="600">

That is really helpfull my man, ty

@GuillermoFidalgo
Copy link

This worked for me.
I'm using this for a jekyll site.

![alt](image.png){: width="50%"}

@rnag
Copy link

rnag commented Dec 25, 2022

@GuillermoFidalgo thanks, you my hero 😺

work for me in a jekyll scenario as well.

@stravid87
Copy link

Thank You!
(used the img tag trick)

@andry81
Copy link

andry81 commented Dec 29, 2022

![alt](image.png){: width="50%"}

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

@rnag
Copy link

rnag commented Dec 30, 2022

@andry81 from what I understand that's just for building static sites with jekyll - i.e. with github pages or similar

@sebaptcd
Copy link

sebaptcd commented Jan 3, 2023

Great info, worked for me!

@SuayMack
Copy link

SuayMack commented Jan 5, 2023

Thank You!

@gforien
Copy link

gforien commented Jan 11, 2023

Thank you !!
![alt|500](https://image.png) or simply ![|500](https://image.png) worked for me in Obsidian

@asgar72
Copy link

asgar72 commented Jun 7, 2023

@nipgrnc104
Github doesn't apply the style attribute but obeys the width and height. So for github you can use the following HTML tag directly in the markdown:

<img src="url" alt="alt text" width="whatever" height="whatever">

Working...

Thanks bro that's worked

@iamamanporwal
Copy link

thanks brdr

@dideler
Copy link

dideler commented Sep 5, 2023

Everyone, please just use the HTML img tag with src and width attributes. Bonus if using alt and title for accessibility.

It is simple, understandable, works in every Markdown engine, and is practically what Markdown's ![]() compiles to.

@Jackiexiao
Copy link

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

@igorskyflyer
Copy link

But anybody knows how to make them responsive? I applied both width and height in my profile's README and it works great on my desktop but looks so bad on my phone.

Yes, I could just take out the height attribute but you actually need them both to avoid CLS -cumulative layout shift, which is why I added the attributes to begin with.

@dirkk0
Copy link

dirkk0 commented Oct 11, 2023

@igorskyflyer not sure if you can inject css files, but if you can, you could try css variables with media queries.

@igorskyflyer
Copy link

The style attribute gets stripped out...

@dafurman
Copy link

dafurman commented Apr 9, 2024

I found myself referring to this gist a lot over the years for the sake of reducing the size of gigantic images when I put them in PR descriptions, so I've turned this into a simple Shortcut:
https://www.icloud.com/shortcuts/7415f6fa654144479bf5e965701c8838

@neoacevedo
Copy link

When you upload or copy/paste a raw image, github markdown will put in the rendered img tag the style max-width: 100%, so, it's mandatory to add the width and the height attributes for the img tag, any other thing will be removed by the renderer, so, only replacing the markdown with the img html tag adding the width and height will work.

@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?

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