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.

Issue With Image width and Height

See original GitHub issue

Expected Behavior

I want to convert a DIV element into the image in react.js. It’s converting exactly that DIV, but it adds some extra width and height in the image, with toPNG, toJpeg functions, with toSvg we get the exact image with same width and height but its base64-size too large, so I want to get the same result in PNG or JPEG with small size. here is the link: orignnale-code

https://codesandbox.io/s/jovial-cohen-ugwum?file=/src/App.js

it should return same result as toSvg in the toPng and toJpeg functions

Current Behavior

I want to convert a DIV element into the image in react.js. It’s converting exactly that DIV, but it adds some extra width and height in the image, with toPNG, toJpeg functions, with toSvg we get the exact image with same width and height but its base64-size too large, so I want to get the same result in PNG or JPEG with small size. toJpeg

https://codesandbox.io/s/jovial-cohen-ugwum?file=/src/App.js

it should return same result as toSvg in the toPng and toJpeg functions

Possible Solution

it should return same result as toSvg in the toPng and toJpeg functions

Steps To Reproduce

  • Remove extra width and height in “toPng” and “toJpeg”
Error Message & Stack Trace

<!-- Provide a log message if relevant -->

Additional Context

Your Environment

window10 Node: v12.16.2 React: v16.13.1

  • html-to-image: [e.g. 0.1.0]
  • OS: [e.g. macOS Sierra 10.12.3]
  • Browser: [e.g. chrome 78.0.3904.108]

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
gtabuadacommented, Jan 12, 2021

The generated image size is based off it’s root node dimensions multiplied by the device pixel ratio. If you want to keep the generated image’s size equal to your node’s, add the following to your config object: pixelRatio: 1

0reactions
vivcat[bot]commented, Apr 10, 2022

This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting Height And Width On Images Is Important Again
To prevent layout shifts and improve performance scores, we need to always set width and height attributes on our images.
Read more >
Image height and width not working? - Stack Overflow
Avoid setting both width and height, as the image itself might not be scaled proportionally. But you can set the dimensions to whatever...
Read more >
Fix Image Elements Do Not Have Explicit Width and Height
Option 1: Use the width and height attributes to define the image's width and height ... The first approach is to use the...
Read more >
Quick Tips: How to fix "Image elements do not have explicit ...
Option 1 - define the width and height of the image using the width and height attributes. ... The first option is to...
Read more >
Behavior of img Height and Width Not What I Expected
As others have mentioned above its best to maintain the aspect ratio of the image when resizing and you should set height to...
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