Add image without distorting ratio
See original GitHub issue“I have read and understood the contribution guidelines.”
I am trying to add an image (dataURL format) to my PDF to fit in a 65*60 mm box.
My current code is:
doc.addImage(imageURL, "JPEG", config_settings.x, config_settings.y, 65, 60, "", "FAST", 0);
However I get a distorted image as below, which doesn’t respect the aspect ratio of the original image.
My images are already in the correct dimensions to fit in the box (see below for the correct ratio) so I’d like to be able to add them to the PDF without enforcing a width and height.
Alternatively, is there a way to specify a resize mode for my image (e.g. ‘contain’)?
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top Results From Across the Web
Steps to Resize Images Without Distortion 2022
Step 1: Launch Photoshop · Step 2: Open the Aspect Ratio Window · Step 3: Set the Aspect Ratio · Step 4: Set...
Read more >Resize image without distorting it - css - Stack Overflow
The issue is with setting width to 100%. Try removing width="100%", or set the width manually based on the aspect ratio. Share.
Read more >How to fill a box with an image without distorting it
The image should completely fill the box, retaining aspect ratio, and cropping any excess on the side that is too big to fit....
Read more >Resizing Images in Office without distorting (Word, Excel, and ...
To avoid distortion, just drag using SHIFT + CORNER HANDLE–(No need to even check if the image is proportionally locked):.
Read more >How to Resize an Image without Distorting it | Phancybox NZ
You need to crop the image first. Cropping an image is essentially cutting out a portion of it, which will alter it's ratio....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah it uses an html as input and then converts it into an Image. For your case u can directly use the Image url
Thanks for your answer @JobSoltero! It helped me find a solution. I didn’t know about
pdf.getImageProperties()
- it did the trick!