1640

I just got started with Markdown. I love it, but there is one thing bugging me: How can I change the size of an image using Markdown?

The documentation only gives the following suggestion for an image:

![drawing](drawing.jpg)

If it is possible I would like the picture to also be centered. I am asking for general Markdown, not just how GitHub does it.

Matthias Braun
  • 32,039
  • 22
  • 142
  • 171
cantdutchthis
  • 31,949
  • 17
  • 74
  • 114
  • 1
    For top image (like repo logo) I just make a "white padding" in original image before export to PNG. – Enrique René Oct 21 '20 at 22:09
  • 1
    You should really fix the accepted answer the to HTML one as the current answer uses non-standard markdown features that don't work broadly – VoteCoffee Apr 14 '21 at 15:22
  • 1
    What is that `!` about? – buhtz Dec 11 '22 at 12:15
  • 2
    @buhtz It is to differentiate a normal HTML link `[text](URL)` from an image `![alt text](image URL)`. – VonC Dec 24 '22 at 09:26
  • 7
    Note: [GitLab 15.7+, Dec. 2022, officially adopts](https://stackoverflow.com/a/74906593/6309) the `![alt text](image URL){width=x height=y}` convention. – VonC Dec 24 '22 at 09:43
  • The answer basically is: it is not possible. You have to use html. :( – eric May 25 '23 at 12:36

38 Answers38

1723

You could just use some HTML in your Markdown:

<img src="drawing.jpg" alt="drawing" width="200"/>

Or via style attribute (not supported by GitHub)

<img src="drawing.jpg" alt="drawing" style="width:200px;"/>

Or you could use a custom CSS file as described in this answer on Markdown and image alignment

![drawing](drawing.jpg)

CSS in another file:

img[alt=drawing] { width: 200px; }
Tieme
  • 62,602
  • 20
  • 102
  • 156
  • 72
    Using inline `style` does not work in most websites (e.g. GitHub) site it will get sanitized. Prefer `width` and `height` instead as mentioned by @kushdillip. – Ciro Santilli OurBigBook.com Nov 22 '14 at 08:48
  • 9
    The solution based on the alt attribute is very bad and you shouldn't use it, it breaks **accessibility**. – Regnareb Oct 17 '16 at 09:44
  • The alt in markdown put a caption, the alt in html does something completely different (put text if figure cannot be loaded). – Julien Colomb May 02 '18 at 21:06
  • I was putting an image in a table and it worked better to use `max-width` instead to ensure images are not squished – kashiraja Jul 24 '19 at 00:32
  • 10
    Would it be a good idea to recommend a percentage instead of device-dependent pixels? E.g. `drawing` ? Tested it on GitHub, it works nicely – VasiliNovikov Jan 03 '21 at 20:29
  • 1
    This solution worked for me – Jorge Santos Neill Apr 17 '21 at 20:42
  • Works on GitHub ...`drawing` , but sadly does not work in the WebStorm/Jetbrains markdown viewer. – spodell Jun 18 '21 at 18:36
  • 3
    @JulienColomb `alt` is _always_ what's displayed as alternative for when the image can't load OR when the user can't see it. It does exactly the same thing. You're thinking of a separate attribute, `title` which makes hover text. Some browsers, if there's no `title` supplied, will display the alt text in both places. The accessibility complaint is valid. – maco Apr 15 '22 at 13:02
851

With certain Markdown implementations (including Mou and Marked 2 (only macOS)) you can append =WIDTHxHEIGHT after the URL of the graphic file to resize the image. Do not forget the space before the =.

![](./pic/pic1_50.png =100x20)

You can skip the HEIGHT

![](./pic/pic1s.png =250x)

And Width

![](./pic/pic1s.png =x250)
sud007
  • 5,824
  • 4
  • 56
  • 63
prosseek
  • 182,215
  • 215
  • 566
  • 871
487

The accepted answer here isn't working with any Markdown editor available in the apps I have used till date like Ghost, Stackedit.io or even in the StackOverflow editor. I found a workaround here in the StackEdit.io issue tracker.

The solution is to directly use HTML syntax, and it works perfectly:

<img src="http://....jpg" width="200" height="200" />
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
kushdilip
  • 7,606
  • 3
  • 24
  • 30
  • 15
    This worked great for me! Inline CSS wasn't working with GitHub Markdown but the "old school" height/width attributes worked just fine. – niczak Dec 19 '14 at 19:53
  • 1
    Good thing is that this one also works if you're trying to use a markdown viewer for local files in a browser extension/add-on. – code_dredd Mar 23 '18 at 00:16
  • 8
    Github likes this. – Teoman shipahi May 03 '18 at 20:50
  • 1
    This is great except not in my ipython notebooks at github. – eric Mar 17 '20 at 14:35
  • 2
    Note that on Stack Exchange sites you must use this exact format, and no other attributes (note even `alt`) are seemingly allowed (you may omit `width` or `height`, and the space before `/>` is optional, but other than that no extra whitespace is allowed). GitHub, by contrast, supports (at least) also `alt` and `title` attributes, and allows extra whitespace. – mklement0 Jul 09 '20 at 21:09
  • 2
    On Stack Overflow, the simple solution is to link to a different version of the picture. Each image you upload gets rendered in six different versions, which you can switch between by adding a character to indicate the desired size before the `.png` extension. For details, see https://meta.stackoverflow.com/questions/253403/how-to-reduce-image-size-on-stack-overflow – tripleee Oct 30 '20 at 05:53
  • This does NOT work for me in Jupyter. The image just stays the original size. " The version of the notebook server is: 6.4.6" – SteveWithamDuplicate Apr 18 '22 at 13:23
209

Just use:

<img src="Assets/icon.png" width="200">

instead of:

![](Assets/icon.png)
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
138

Combining two answers I came out with a solution, that might not look that pretty,
but it works!

It creates a thumbnail with a specific size that might be clicked to bring you to the max resolution image.

[<img src="image.png" width="250"/>](image.png)

Here's an example! I tested it on Visual Code and Github. Example markdown

Thanks to the feedback, we know that this also works on:

  • GitLab
  • Jupyter Notebook
Igor Suhotin
  • 41
  • 1
  • 2
  • 5
proximab
  • 1,865
  • 1
  • 13
  • 18
123

If you are writing MarkDown for PanDoc, you can do this:

![drawing](drawing.jpg){ width=50% }

This adds style="width: 50%;" to the HTML <img> tag, or [width=0.5\textwidth] to \includegraphics in LaTeX.

Source: http://pandoc.org/MANUAL.html#extension-link_attributes

rudolfbyker
  • 2,034
  • 1
  • 20
  • 25
  • 2
    It is even nicer than specifying size in points directly. I am glad this is the approach Pandoc has chosen! – jciloa May 02 '17 at 10:08
  • 2
    @m0z4rt GitHub probably does not use PanDoc to render the MarkDown. – rudolfbyker Nov 17 '17 at 17:54
  • 3
    @rudolfbyker thank you so much. For Mkdocs-material it worked with adding ```-attr_list``` in ```markdown_extensions```` in ```mkdocs.yml```. – Lilya Nov 25 '20 at 10:27
  • Works for R v. 4.2.0 with `tinytex`! – fitzberg Mar 01 '23 at 09:56
  • Recently Gitlab adopted this format when using rich text editing. @VonC already said it some months ago – Bit-Man Jul 17 '23 at 13:46
  • Thanks. I find this the best solution given here: (1) it does not assume use of html, (2) it shows how to define the width by relative size, (3) it is concise. To be perfect, it could also have included how to define the width/height by absolute size. – W7GVR Jul 26 '23 at 12:52
82

Maybe this has recently changed but the Kramdown docs show a simple solution.

From the docs

Here is an inline ![smiley](smiley.png){:height="36px" width="36px"}.

And here is a referenced ![smile]

[smile]: smile.png
{: height="36px" width="36px"}

Works on github with Jekyll and Kramdown.

sayth
  • 6,696
  • 12
  • 58
  • 100
  • 10
    May have worked in the past but doesn't work now on Github. Adding an old fashioned tag with width and height still works. – mez.pahlan Oct 11 '16 at 15:00
  • 3
    This is the best solution if you're using Kramdown or Jekyll (which uses Kramdown by default). – Nick McCurdy Oct 15 '16 at 21:35
  • 4
    [Block attributes](https://kramdown.gettalong.org/quickref.html#block-attributes) as shown here are a good option with kramdown. The syntax here is slightly wrong, which may be why @piratemurray is having trouble. It should be `{: height=36 width=36}`; this generates HTML attributes, so it should not have the `px` suffix. Alternately, you can use css with `{: style="height:36px; width:36px"}`. – Quantum7 Jan 18 '18 at 15:10
  • 1
    Works for jekyll! thx. I don't even need height and width, just one is enough. `![alt text](image.png){:height="36px" }` – Matthias Dec 08 '18 at 10:13
  • 1
    I had to make a small change to get this to work properly in Jekyll. This answer as-written outputs malformed HTML, as the `width` and `height` attributes include the "px" part. For me I needed to use `{:height="36" width="36"}` – Maximillian Laumeister Dec 22 '18 at 21:30
  • As of today, the above code for me if I upload a kramdown file to GitHub Pages and lets Jekyll to translate it to \*.html. The double quotes in `height="36"` *do* matter. See [this commit](https://github.com/vojtech-filipec/vojtech-filipec.github.io/commit/eb617af9d12fde8c8244443bb8c60950016c585d#diff-ba0609637b02c25ea9b4dc0a300c1487), line 11. – Vojta F Aug 02 '19 at 10:48
43

Replace ![title](image-url.type) with <img src="https://image-url.type" width="200" height="200"/>

prabhu
  • 878
  • 9
  • 17
  • Works. But using HTML defeats the object of using a **simpler than HTML** markup language. – Martin Jul 12 '23 at 11:54
  • It's NOT working for every markdown implementation. You should specify the particular markdown package in your answer. So the down vote – us_david Aug 18 '23 at 15:55
30

One might draw on the alt attribute that can be set in almost all Markdown implementations/renderes together with CSS-selectors based on attribute values. The advantage is that one can easily define a whole set of different picture sizes (and further attributes).

Markdown:

![minipic](mypic.jpg)

CSS:

img[alt="minipic"] { 
  max-width:  20px; 
  display: block;
}
petermeissner
  • 12,234
  • 5
  • 63
  • 63
  • 1
    Isn't this the same as [Tieme's earlier answer](http://stackoverflow.com/a/14747656/477035)? – RedGrittyBrick Feb 16 '15 at 12:39
  • 28
    This is a misuse of the alt attribute and hurts accessibility. – sbuck Mar 22 '16 at 19:32
  • 3
    Yes, it is a hack BUT still seems to be the only thing that works across Markdown flavors. +1 for pointing that out (people using screen readers get problems with that right? They will get also problems with all those not bothering with using alt the right way). – petermeissner Apr 02 '16 at 19:00
23

If you are using kramdown, you can do this:

{:.foo}
![drawing](drawing.jpg)

Then add this to your Custom CSS:

.foo {
  text-align: center;
  width: 100px;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Zombo
  • 1
  • 62
  • 391
  • 407
  • 3
    I would recommend against setting the width only in CSS. It is useful to tell the browser how large the image element will be before the image and stylesheet are done loading so that it can optimize the layout of elements around the image without doing a reflow. – Nick McCurdy Oct 15 '16 at 21:34
20

Building on from Tiemes answer, if you're using CSS 3 you can use a substring selector:

This selector will match any image with an alt tag that ends with '-fullwidth':

img[alt$="-fullwidth"]{
  width:  100%;
  display: block;
}

Then you can still use the alt tag for its intended purpose to describe the image.

The Markdown for the above could be something like:

![Picture of the Beach -fullwidth](beach.jpg)

I've been using this in Ghost markdown, and it has been working well.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bennetimo
  • 341
  • 2
  • 4
17

If you are using reference style images in GitHub Flavored Markdown:

Here is an image of tree: 
![alt text][tree]{height=400px width=500px}


[//]: # (Image References)
[tree]: ./images/tree.png "This is a tree"

robertspierre
  • 3,218
  • 2
  • 31
  • 46
zardosht
  • 3,014
  • 2
  • 24
  • 32
  • 3
    This didn't work for me. The reference linked mentions nothing about height/width – Shubham Chaudhary Jun 19 '20 at 07:53
  • @ShubhamChaudhary The referenced link shows "what is a _reference style image_" in _[Github Flavored Markdown](https://en.wikipedia.org/wiki/Markdown#GitHub_Flavored_Markdown_(GFM))_. Maybe you don't have a reference style image or are using another variant of Markdown. – zardosht Jun 19 '20 at 08:32
  • 3
    Oh, you linked it to explain 'reference style'. In context of the answer, the link doesn't mention anything about the height/width syntax `{height=100px width=100px}` – Shubham Chaudhary Jun 19 '20 at 08:36
16

For those intereseted in an rmarkdown and knitr solution. There are some ways to resize images in an .rmd file without the use of html:

You can simply specify a width for an image by adding {width=123px}. Don't introduce whitespace in between the brackets:

![image description]('your-image.png'){width=250px}

Another option is to use knitr::include_graphics:

```{r, fig.cap="image description", out.width = '50%'}
knitr::include_graphics('your-image.png')
```
symbolrush
  • 7,123
  • 1
  • 39
  • 67
  • 2
    How can I change both height and width? For the first option specifically. I tried putting height and width in the same `{}` but failed. Separate `{}`s fail too. – NelsonGon Dec 03 '19 at 08:36
  • 2
    @NelsonGon: I never needed to specify both, since the height also scales, when width is specified. Therefore I don't know whether that would be possible and how to achieve it. Good question, though.. – symbolrush Dec 03 '19 at 09:18
  • 2
    Thanks, I since figured I can do it like so: `{height=x width=y}`. It seems this syntax does not recognize commas but I could specify other attributes including style elements. – NelsonGon Dec 03 '19 at 09:30
14

I came here searching for an answer. Some awesome suggestions here. And gold information pointing out that markdown supports HTMl completely!

A good clean solution is always to go with pure html syntax for sure. With the tag.

But I was trying to still stick to the markdown syntax so I tried wrapping it around a tag and added whatever attributes i wanted for the image inside the div tag. And it WORKS!!

<div style="width:50%">![Chilling](https://www.w3schools.com/w3images/fjords.jpg)</div>

So this way external images are supported!

Just thought I would put this out there as it isn't in any of the answers. :)

Umang Desai
  • 428
  • 2
  • 5
  • 14
14

This one works for me it's not in one line but i hope it works for you.

<div>
<img src="attachment:image.png" width="500" height="300"/>
</div>
13

For all looking for solutions which work in R markdown/ bookdown, these of the previous solutions do/do not work or need slight adaption:

Working

  • Append { width=50% } or { width=50% height=50% }

    • ![foo](foo.png){ width=50% }
    • ![foo](foo.png){ width=50% height=50% }

    • Important: no comma between width and height – i.e. { width=50%, height=30% } won't work!

  • Append { height="36px" width="36px" }

    • ![foo](foo.png){ height="36px" width="36px" }
    • Note: {:height="36px" width="36px"} with colon, as from @sayth, seems not to work with R markdown

Not working:

  • Append =WIDTHxHEIGHT
    • after the URL of the graphic file to resize the image (as from @prosseek)
    • neither =WIDTHxHEIGHT ![foo](foo.png =100x20) nor =WIDTH only ![foo](foo.png =250x) work
mavericks
  • 1,005
  • 17
  • 42
13

If you have one image in each md file, one handy way to control image size is:

adding css style as follows:

## Who Invented JSON?
`Douglas Crockford`

Douglas Crockford originally specified the JSON format in the early 2000s.
![Douglas Crockford](img/Douglas_Crockford.jpg)

<style type="text/css">
    img {
        width: 250px;
    }
</style>

and the output will be like: enter image description here

If you have more images in each md page, then the handy way to control each image or each customized tag is to define each element in css. For this case for the img tag we could have:

//in css or within style tags:
    img[alt="Result1"] {
    width: 100px;
    }

    img[alt="Result2"] {
    width: 200px;
    }
    img[alt="Result3"] {
    width: 400px;
    }

// try in md one of the methods shown below to insert image in your document:
 <br/>
<img src="https://i.stack.imgur.com/xUb54.png" alt="Result1"> <br/>
<img src="https://i.stack.imgur.com/xUb54.png" alt="Result2"> <br/>
<img src="https://i.stack.imgur.com/xUb54.png" alt="Result3"> <br/>

<br/>

in md:<br/>
![Result1](img/res-img-1.png) <br/>

![Result2](img/res-img-2.png) <br/>

![Result3](img/res-img-3.png) 
General Grievance
  • 4,555
  • 31
  • 31
  • 45
Ali Safari
  • 1,535
  • 10
  • 19
12

You could use this one as well with kramdown:

markdown
![drawing](drawing.jpg)   
{:.some-css-class style="width: 200px"}

or

markdown
![drawing](drawing.jpg)   
{:.some-css-class width="200"}

This way you can directly add arbitrary attributes to the last html element. To add classes there is a shortcut .class.secondclass.

Majid Golshadi
  • 2,686
  • 2
  • 20
  • 29
rriemann
  • 528
  • 4
  • 17
12

I know that this answer is a bit specific, but it might help others in need.

As many photos are uploaded using the Imgur service, you can use the API detailed here to change the size of the photo.

When uploading a photo in a GitHub issue comment, it will be added through Imgur, so this will help a lot if the photo is very big.

Basically, instead of https://i.stack.imgur.com/Y682Q.gif, you would put http://i.imgur.com/12345m.jpg for medium sized image.

Iulian Onofrei
  • 9,188
  • 10
  • 67
  • 113
  • Stack Overflow has a similar facility; see the comment I left on another answer for a link. https://stackoverflow.com/questions/14675913/changing-image-size-in-markdown#comment114230318_21972032 – tripleee Oct 30 '20 at 05:55
11

I scripted the simple tag parser for using a custom-size img tag in Jekyll.

https://gist.github.com/nurinamu/4ccf7197a1bdfb0d7079

{% img /path/to/img.png 100x200 %}

You can add the file to the _plugins folder.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nurinamu
  • 240
  • 4
  • 9
10

For those using Markdown on Google Colaboratory, there is no need to have the image uploaded to the session storage folder, or linked on Google Drive. If the image has a URL, and it can be included on the Jupyter notebook, and its size changed as follows:

<img src="https://image.png" width="500" height="500" />

enter image description here

Note that entering just the width leaving the height completely out allows the image to adjust to small screens (i.e. phone).

Antoni Parellada
  • 4,253
  • 6
  • 49
  • 114
7

For R-Markdown, neither of the above solutions worked for me, so I turned to regular LaTeX syntax, which works just fine.

\begin{figure}
 \includegraphics[width=300pt, height = 125 pt]{drawing.jpg}
\end{figure}

Then you can use e.g. the \begin{center} statement to center the image.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Knarpie
  • 258
  • 4
  • 7
  • 1
    +1, but better just `\centering` after `\begin{figure}` or nothing, if you use ` \includegraphics[width=\linewidth]{drawing.jpg}` that I think that should be the default pandoc output at least when the image is wider that the text. – Fran Oct 24 '17 at 09:26
7

Obsidian has its own syntax for this:

![Engelbart|100x145](https://history-computer.com/ModernComputer/Basis/images/Engelbart.jpg)

Or, to use the example from the question:

![drawing|200x100](drawing.jpg)

From: Basic formatting syntax - Obsidian Help

aboy021
  • 2,096
  • 2
  • 23
  • 23
  • Nice. But that's not a universal solution. – Martin Jul 12 '23 at 11:49
  • As @Martin has pointed out this isn't a universal solution, but since it's a solution to a common version of this problem I think it's still worth having here. – aboy021 Jul 12 '23 at 20:46
6

Resizing Markdown Image Attachments in Jupyter Notebook

I'm using jupyter_core-4.4.0 & jupyter notebook.

If you're attaching your images by inserting them into the markdown like this:

![Screen%20Shot%202019-08-06%20at%201.48.10%20PM.png](attachment:Screen%20Shot%202019-08-06%20at%201.48.10%20PM.png)

These attachment links don't work:

<img src="attachment:Screen%20Shot%202019-08-06%20at%201.48.10%20PM.png" width="500"/>

DO THIS. This does work.

Just add div brackets.

<div>
<img src="attachment:Screen%20Shot%202019-08-06%20at%201.48.10%20PM.png" width="500"/>
</div>

Hope this helps!

MrFun
  • 2,303
  • 1
  • 15
  • 16
5

When using Flask (I am using it with flat pages)... I found that enabling explicitly (was not by default for some reason) 'attr_list' in extensions within the call to markdown does the trick - and then one can use the attributes (very useful also to access CSS - class="my class" for example...).

FLATPAGES_HTML_RENDERER = prerender_jinja

and the function:

def prerender_jinja(text):
    prerendered_body = render_template_string(Markup(text))
    pygmented_body   = markdown.markdown(prerendered_body, extensions=['codehilite', 'fenced_code', 'tables', 'attr_list'])
    return pygmented_body

And then in Markdown:

![image](https://octodex.github.com/images/yaktocat.png "This is a tooltip"){: width=200px}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mat
  • 59
  • 1
  • 2
5

There is way with add class and css style

![pic][logo]{.classname}

then write down link and css below

[logo]: (picurl)

<style type="text/css">
    .classname{
        width: 200px;
    }
</style>

Reference Here

Community
  • 1
  • 1
Cropse
  • 53
  • 1
  • 4
5

For future reference:

Markdown implementation for Joplin allows controlling the size of imported images in the following manner:

<img src=":/7653a812439451eb1803236687a70ca" width="450"/>

This feature was requested here and as promised by Laurent this has been implemented.


It took me a while to figure the Joplin specific answer.

kgkmeekg
  • 524
  • 2
  • 8
  • 17
5

Via plain backward compatible MD:

![<alt>](<imguri>#<w>x<h> "<title>")

where w, h defines the bounding box to aspect fit into, as eg in Flutter package https://pub.dev/packages/flutter_markdown

Code: https://github.com/flutter/packages/blob/9e8f5227ac14026c419f481ed1dfcb7b53961475/packages/flutter_markdown/lib/src/builder.dart#L473

Reconsider html workarounds breaking compatibility as people might use native/non-html components/apps to display markdown.

0llie
  • 8,758
  • 2
  • 24
  • 13
4

The sheer <img ... width="50%"> said above, did work on my Github Readme.md document.

However my real issue was, that the image was inside a table cell, just compressing the text in the beside cell. So the other way was to set columns width in Markdown tables, but the solutions did not really seem enough markdownish for my morning.

At last I solved both problems by simply forcing the beside text cell with as much "& nbsp;" as I needed.

I hope this helps. Bye and thanks everybody.

Andrea
  • 41
  • 1
4

Put the image URL in tag below. Remember to change the width and height accordingly. Like This

<img src="IMAGE_URL_HERE"  width="300" height="300">

You can specify width without height attribute and vice versa.

Alternatively, you can change image size using percentage value like below:

<img src="IMAGE_URL_HERE"  width=50% height=50%>
Saleem Yasin
  • 120
  • 5
3

The addition of relative dimensions to the source URL will be rendered in the majority of Markdown renderers.

We implemented this in Corilla as I think the pattern is one that follows expectations of existing workflows without pushing the user to rely on basic HTML. If your favourite tool doesn't follow a similar pattern it's worth raising a feature request.

Example of syntax:

![a-kitten.jpg](//corilla.com/a-kitten-2xU3C2.jpg =200x200)

Example of kitten:

kitten

davidryan
  • 2,222
  • 20
  • 31
  • A shame that it doesn't work on GitHub at present, but I'd suggest raising a feature request all the same. – davidryan Mar 14 '19 at 06:26
3

If we just use normal HTML image tag like this it is working, if you use bootstrap for styling. I use this in website made with Jekyll.

<img class="img-fluid" src="./img/face.jpg" alt="img-verification">

If we add bootstrap classes as per this example it works fine.

akshay_sushir
  • 1,483
  • 11
  • 9
2

If changing the initial markdown is not an option for you, this hack might work:

newHtml = oldHtml.replace(/<img/g, '<img height="100"');

I used this to be able to resize images before sending them in an email (as Outlook ignores any image css styling)

Yannickv
  • 527
  • 4
  • 13
1

This will work

<style>
img{width: 50%;}
#foo {color: red;}
</style>

<p id="foo">foo</p>

<p style="color: blue">bar</p>

MD SHAYON
  • 7,001
  • 45
  • 38
1

If you are using markdown-it, first you need to enable HTML render:

const md = require("markdown-it")({
  html: true,
});

then you can use in your .md file:

<img src="" alt="drawing" width="100%" height="200"/>
Elisei Nicolae
  • 293
  • 2
  • 12
0

Tieme's answer is best for most cases.

In my case, I am using pandoc to convert markdown to latex. HTML tags won't work here.

My solution is to re-implement \includegraphics

\let\maxincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\maxincludegraphics[max width=\textwidth]{#1}}

The is analogous to using CSS after a conversion to HTML.

Stewart
  • 4,356
  • 2
  • 27
  • 59
0

I would just edit the image in some image editor - enlarge the image horizontally, therefore it will get smaller vertically when resized by the renderer to the width of the page.

So, just add some transparent left and right margins.

-5

You can set size at the end of the image like this:

![image.png](source **=600x400**)
buhtz
  • 10,774
  • 18
  • 76
  • 149
user3342209
  • 133
  • 1
  • 7