-
Notifications
You must be signed in to change notification settings - Fork 860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: image scaling #72
Comments
I agree, that would be a handy feature. Do you have any suggestions to how the feature you're describing could work, and/or what it's syntax could be like? The background image scaling is pretty easy since the implicit rule for scaling is to keep within the boundaries of the slide. Scaling of non-background images, however, would need a different rules. On option would be to enable setting max width and height per image, that would serve as scaling boundaries. |
Markdown image syntax is not obvious to extend, so for lack of a really good idea, I'd go rather lazily for permitting HTML image tags with all their attributes. |
You can actually use HTML image tags, an any other tag for that matter. There's an issue with the Markdown converter though, that autolinks URLs, even inside the |
What I currently use is something like this: .image-50[![sketch](assets/sketch.png)] .image-50 img {
width: 50%;
} Apparently, some markdown implementations allow to specify image dimensions like this: ![alt](img.png =100x20) Would be nice if the proportions could also be given as a percentage. To me that's the whole point, fixed sizes don't help much unless you know at which resolution you're going to be presenting. Some examples: ![alt](img.png =50%)
![alt](img.png =50%x25%)
![alt](img.png =x25%)
![alt](img.png =100x200)
![alt](img.png =100) What do you think? |
I totally agree for this feature. For now I'm obligated to go for: <img src="images/hepa.png" width="800"> And that's pretty much all the html code I have to use instead of markdown. The solution of @matf sounds good. |
I think it is a nice solution as well. Another alternative, however, that I've considered before, is using the initial image alternative text field, i.e.:
This would be even easier to implement, as the existing parsing and conversion of images could be left as-is, and simply doing an post-processing of the generated HTML looking for image tags whose alternative text matches the suggested dimension formats from above. Also, using the alternative text field would be in line with what the DeckSet app does, as suggested in #133. |
Yes, it could also be great that way. Moreover, the image's path would be more readable (and more easily accesible trough Vim's shortcuts, but that's not a big deal). And the use of the "[]" is rare, so it could be used for that. But on the other hand, it would create another "implementation" of Markdown. |
If I could weigh in here, cause I like where this is all going... I was just looking at this article. I really like the idea of a "macro" that was invented by this dude.
At the end of the day there is going to be a lot of debate around how to extend Markdown. Why not just have a catch all syntax for all the wacky stuff. This method at least allows you to build out specific logic for popular scenarios. Things like youtube and vimeo are great examples. I find that plopping in iframes like reveal.js recommends makes it all so hard to read. Understandably it is not a Markdown first approach, being that it uses data-markdown. Personally I am here because this project is Markdown first! I think the colon is key because it does make a logical separation from the existing use of You could also leave out brackets if you invented some kind of wild macro like this...
Why not! |
I just simply add a style to limit image to fit its container
Now the image will just scale to fit container. And I think it would be nice if the image can be clicked to popup a simple box to show original image. |
Occurrences of \![:name arg1, arg2](obj), where only name is mandatory, will be handled as macros, whose corresponding expansion functions are expected to be predefined on the remark.macros object.
I added support for macros on the develop branch. Example markdown: Uppercase: ![:upper](word)
Random: ![:random one, of, these, words] Corresponding JavaScript: remark.macros.upper = function () {
// `this` is the value in the parenthesis, or undefined if left out
return this.toUpperCase();
};
remark.macros.random = function () {
// params are passed as function arguments: ["one", "of", "these", "words"]
var i = Math.floor(Math.random() * arguments.length);
return arguments[i];
};
var slideshow = remark.create(); Example output:
Macros are currently expanded synchronously during parsing. As for the original issue, one could easily create a macro that would scale an image by setting the width percentage: remark.macros.scale = function (percentage) {
var url = this;
return '<img src="' + url + '" style="width: ' + percentage + '" />';
}; Usage:
Output: <img src="image.jpg" style="width: 50%" /> |
This is really great stuff! I love the the If you are curious I have been doing a bit of writing about "Macros" in a more big picture sense. I really feel Markdown is about to take off in big ways. |
Awesome, gj! 🍻 |
This looks really good, thanks! |
The macro support has now been released in version 0.8.0. Will have to look into which macros becomes part of remark over time. For now there are no built-in macros, but the examples above illustrates how to add macros, specifically for scaling images. |
I hope that the instruction on this useful feature should be added to the tutorial / wiki of the page. |
Naive question, but where should I place the macro definition? |
@Enrico16 : right before this line
|
Great feature, makes Markdown cleaner and more compact. Maybe macro definition should be added to the Wiki page? It would make easier for new users to learn about this tool and use it. |
with this macro, as per gnab/remark#72, one can now do ````julia # A plot ```@example index using Plots; gr() Plots.plot(rand(10)) savefig("statplot.png"); ``` ![:scale 90%](statplot.png) ````
Another little macro that keeps the alt text option: remark.macros.img = function (altText, width) {
var url = this;
return '<img alt="' + altText + '" src="' + url + '" style="width: ' + width + '" />';
}; Usage:
|
How could I get this to work with a locally stored image (not a url)? In the slide
Works well, but after adding the |
This works great, can you add it to https://github.com/gnab/remark/wiki/Formatting#images so that people find it quickly? One problem I have is that if you put images in Markdown tables, the column width is still scaled to full image size. Is there anyway around this? Thanks! |
px instead of % seems to solve this:
|
Still to do: * Fit text - see gnab/remark#316 * Fit images - see gnab/remark#72 * Add Codethink logo at start and end * Remove 'bottom bar' - ? * Make it more beautiful
Non-background images are always shown at their original size, which is often not at all adapted to a slideshow. For locally stored images, preprocessing is a solution, but not for pointing directly to images on other servers. Explicit image scaling would therefore be a nice feature to have.
The text was updated successfully, but these errors were encountered: