question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Control image size in output PDF?

See original GitHub issue

Context:

  • version: 5.0.1
  • platform: macOS
  • node version: v17.3.1

I have a markdown file like this

# Foo

Blah blah

![img|200](images/something.png)

In the above scenario, something.png is 1000x1000px (example). I am trying to control its size to 200px wide.

When I output this using md-to-pdf, the image is full size. Is there any workaround or other syntax I can use? Thank you 🙏

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
luckman212commented, Jan 14, 2022

Ah, didn’t realize the renderer was extensible with JS. 🤯 I guess I should have read the docs more closely. Thanks for the tip, much appreciated!

0reactions
simonhaenischcommented, Jan 14, 2022

Marked only supports a couple of markdown flavors and neither of them have any shorthand syntax for adding a width to an image, sorry.

That being said, it’s relatively simple to extend marked, and overwrite the image renderer so that you can use some custom syntax (see https://marked.js.org/using_pro#renderer).

// config.js

const { marked } = require('marked');

const renderer = new marked.Renderer();

renderer.image = (href, title) => {
  const lastPipeIndex = title.lastIndexOf('|');
  
  const alt = title.slice(0, lastPipeIndex);
  const width = title.slice(lastPipeIndex + 1);

  return `<img src="${href}" alt="${alt}" style="width: ${width}px">`;
}

module.exports = {
  marked_options: { renderer },
};
# The file

![something|200](img/something.jpg)
md-to-pdf --config-file config.js path/to/the-file.md

Disclaimer: this has not been tested so might need some adjustments but I hope you get the idea.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resize a PDF image
On the top toolbar, click Tools > Edit PDF > Edit. · Hover your cursor over the image you want to edit. ·...
Read more >
5.4 Control the size of plots/images | R Markdown Cookbook
5.4 Control the size of plots/images. The size of plots made in R can be controlled by the chunk option fig.width and fig.height...
Read more >
How to control output image size · Issue #93
Sometimes when i converted a pdf file to images, each image is more than 20MB. How can i reduce the size of the...
Read more >
How to set size for local image using knitr for markdown?
For pdf output, you will have to specify units for the figure dimensions, e.g. out.width='100pt' , otherwise latex will throw an error about...
Read more >
Adjust Image Sizes
While the % unit was supported in older versions of HTML, it was removed starting in HTML 5. If you need to specify...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found