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.
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; }
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)
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" />
Just use:
<img src="Assets/icon.png" width="200">
instead of:
![](Assets/icon.png)
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.
Thanks to the feedback, we know that this also works on:
GitLab
Jupyter Notebook
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
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.
Replace ![title](image-url.type) with <img src="https://image-url.type" width="200" height="200"/>
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;
}
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;
}
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.
If you are using reference style images in Gihub 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"
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')
```
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>
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.
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 http://i.imgur.com/12345.jpg, you would put http://i.imgur.com/12345m.jpg for medium sized image.
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. :)
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.
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
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:
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)
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" />
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.
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!
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}
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
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.
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.
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.
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:
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)
I have some problems to create responsive image maps with Matt Stows jQuery Plugin. I followed all the advices, but the image maps are still not responsive. I hope you can help. These are the instructions (Full page: https://github.com/stowball/jQuery-rwdImageMaps):
If possible, add correct, unitless width and height attributes to your image map images. You can override these in CSS to make them responsive.
Add a link to jQuery in your page, preferably at the bottom just
before the closing </body>
After jQuery, either in a block or a separate file, call:
$('img[usemap]').rwdImageMaps();
That's my code, I set a fixed width and height which is overwritten in CSS.
<div class="banners">
<img src="wcf/images/blueTemptation/logo2.jpg" style="width: 980px; height: 80px; display:block;" alt="banner-x" usemap="#banner-y" />
<map name="banner-y"><area shape="rect" coords="560,1,765,79" href="http://www.filmfutter.com/" alt="Kgergrfr" title="Filmfutter Startseite">
</div>
at the bottom of my php I placed this:
<script src="https://raw.github.com/stowball/jQuery-rwdImageMaps/master/jquery.rwdImageMaps.min.js"></script>
<script>
$(document).ready(function(e) {
$('img[usemap]').rwdImageMaps();
});
</script>
In case you wonder, I changed the script source to a URL because I wasn't sure about the right path on my server, but that should not be the issue.
So, I did not manage the plugin to get working and I still wonder because obviously I did nothing wrong, but I used another plugin instead, and finally it works properly. In case some others have the same issues, David Bradshaw's library does exactly what I want and resizes image maps the way they should: https://github.com/davidjbradshaw/imagemap-resizer
I had the same issue, it turns out that I was using JQuery v1.8.3, when I updated it to JQuery v1.9, that seemed to do the trick.
Maybe it's a JQuery versioning problem?
I have 4 thumbnail images on the bottom of my page with a main, large image above it. I want to be able to click the thumbnail and have it load into the big image. Additionally, I want to be able to hover over the thumbnail and have a black border appear around it.
I have 40 pages that have the exact same setup (4 thumbs, 1 main image) but all different images (products). The thumbs are all in class="bottom-pic".
It seems easy enough, but perhaps I'm wrong. I'm thinking CSS for the hover, JS for the clicking? I'm VERY new to JS.
Here is the source code:
<a href=""img src="images-large/cobra-dark-wood.jpg" alt="" id="main-photo" >
<img src="images-large/cobra-dark-wood.jpg" alt="" name="photo-bottom-one" class="bottom-pic" id="photo-bottom-one">
<img src="images-large/cobra-dark-wood-one.jpg" alt="" id="photo-bottom-two" class="bottom-pic">
<img src="images-large/cobra-black.jpg" alt="" id="photo-bottom-three" class="bottom-pic">
<img src="images-large/cobra-black-one.jpg" alt="" name="photo-bottom-four" class="bottom-pic" id="photo-bottom-four">
Based on your code, and not requiring anchor tags etc, here is the JavaScript you could use.
NB: This examples assumes you are using jQuery
$(document).ready(function() {
$('.bottom-pic').on('click', function(){
$('.bottom-pic').removeClass("active"); //Removes class from all items
$(this).addClass("active"); //Adds class only to the currently clicked on item
$('#main-photo').attr('src', $(this).attr('src')); //Changes the source of the image tag
});
});
To see a working demo, I created this fiddle for you.
http://jsfiddle.net/2ZgjR/
Please note that the images don't match up because they are being dynamically loaded from a server, but the effect is exactly what you're asking for, just use this code with your images!
I also added an "active" style if you want the border to stay on the item you've clicked on. Simply add some CSS to the style .active { }
Hope this helps
Yes, I would use CSS for the border on hover. You may have to use box-sizing: border-box to make sure things don't jump around a bunch.
First, your main image should be something like this:
<a href="whatever_link">
<img src="images-large/cobra-dark-wood.jpg" alt="" id="main-photo">
</a>
Since you're using jQuery, it would be easy enough to get the switch out the source of the main image on click. Something like this:
$('.bottom-pic').on('click', function(){
var imgSrc = $(this).attr('src');
$('#main-photo').attr('src', imgSrc);
});
That's just off the top of my head. I haven't tested it.
I have a bunch of images in a gallery on a new website im building and Im wanting to have content displayed when a user hovers over an image.
For example if a user hovered over a picture of a car in my gallery then a low opacity content div would fade over the entire image to show text and maybe a link.
I presume this effect could be done with a bit of JS or even CSS Transitions to give the fade.
I just need to know how to make a content box appear over the image on hover, possibly at 80% opacity.
Heres an example of what I have in mind:
Thanks for the help, if anyone could point me in the right direction it would be appreciated.
I can post more information if needed.
This is somewhat simple way of implementing a hover show and hide with jquery.
Working example: http://jsfiddle.net/va2B8/2/
jQuery ( http://jquery.com/ ):
$(document).ready(function() {
$("#Invisible").hide()
$("#hoverElement").hover(
function () {
$('#Invisible').stop().fadeTo("slow", 0.33);
},
function () {
$('#Invisible').stop().fadeOut("slow");
}
);
});
html:
<p id="hoverElement">This little piggy will show the invisible div.</p>
<div id="Invisible">This is the content of invisible div.</div>
css:
#Invisible { background: #222; color: #fff; }
Edit: I changed url for the working example cause i forgot to fade out on mouse out.
Edit2: Changed url again and changed the code cause i had some extra code there.. plus i thought that i might as well add those two .stop() in there so that it stops the animation If the mouse over or mouse out occurs while animation is going on.
( Without the stops one could hover in and out several times and then when he would stop, the animation would still keep going till it has done each animation as many times as he triggered it. You can test that in here http://jsfiddle.net/va2B8/1/ )
You can start using this fiddle :
http://jsfiddle.net/Christophe/2RN6E/3/
1 div containing image and span like :
<div class="image-hover">
<img src="" />
<span class="desc">text to be displayed when imae hover</span>
</div>
Update
All can be done with CSS...
http://jsfiddle.net/Christophe/2RN6E/4/
Here's an easy jQuery plugin you can implement: http://file.urin.take-uma.net/jquery.balloon.js-Demo.html
It works like this:
$(function() {
$('img').balloon(options);
});
This jQuery applied the balloon function to all images on the page. Here's your HTML:
<img src="example.png" alt="Here's your caption." />
The text in the balloon is going to be whatever is in the alt attribute for images and whatever is in the title attribute for other tags.
I've just done this:
http://twostepmedia.co.uk
It uses hoverintent jquery plugin so there is a delay of 250ms after the user hovers over to avoid erratic hover behaviour.
I am creating a small application where I am displaying some text wrapped in 3 divs so I am actually displaying 1 div at a time also there are prev and next buttons for users to toggle between the div's. Now when javascript is turned off i just want to display 1 div without the prev and next buttons. I have and idea that it can be done with javascript by manipulating the CSS like.
document.getelementbyid("id1").style.display="visible";
document.getelementbyid("id1").style.display="none";
Thanks
You could use the <noscript> tag to both define the styles of the scripted elements and display your alternate div instead:
<noscript>
<style type="text/css">
#scripted-div1, #scripted-div2, #scripted-div3 { display:none; }
</style>
<div>
<!-- Alternate content goes here -->
</div>
</noscript>
Arrange your default page view as it would be displayed with javascript turned off, and then, if it is on, you will be able to add desired elements into desired positions.
You can set those div's to display:none; (in CSS) by default, add id for both, and after page load set document.getelementbyid(..).style.display="visible"; (in JavaScript)
PS. u could use jquery or other, will be much more easy ;)
try this:
[style]#prev, #next { display:none; }
[js]
function showButtons()
{
document.getElementById('next').style.display="block";
document.getElementById('prev').style.display="block";
}
[html]
body onload="showButtons()">
div id="next">next..
div id="prev">prev..
This way without JS prev/next wont be displayed, and with JS they will show after page loads.
Maybe you could set the style inside a noscript tag.
Also, perhaps you should accept previous answers and respect the answers other have given you.