How to adjust the image during convertion? #89

Closed
opened 2021-04-25 19:59:00 +00:00 by josch · 1 comment
Owner

By Thiago Moraes on 2021-01-27T22:15:54.273Z

The images downloaded have width, height = 320, 240 but when converted in PDF they are streched, I was looking for inside code a param to use a fix size.
Is there a way?

from bs4 import BeautifulSoup
import requests
import re
import wget
import img2pdf
import glob, os
import subprocess

html_doc = requests.get(URL).content

soup = BeautifulSoup(html_doc, 'html.parser')

tags = soup.findAll('img')
for tag in tags:
    img_jpg = re.match(r'\bhttp(:?s)?:[^)''"]+\.(?:jpg)(?![a-z/])',tag.attrs['src'])
    if img_jpg:
        #Download Images
        try:
            wget.download(img_jpg.group(0))
        except(err):
            print(err)
            

# Group Images to convert PDF File
img = []
for file in glob.glob("*.jpg"):
    img.append(file)

with open("name.pdf","wb") as f:
  f.write(img2pdf.convert(img))


By josch on 2021-01-27T22:27:31.374Z


This should not happen.

Can you please provide an image for which it does happen?


By Thiago Moraes on 2021-01-28T12:00:57.065Z


Both are in 100%, first is the image and the second pdf. You can observe that the second has been stretched. If I apply zoom in image I can read, different with pdf

image
image


By josch on 2021-01-28T13:17:58.092Z


Maybe you misunderstood. I don't need a screenshot. I need the exact image that you used as an input. Either attach it to this issue or send it to me via email josch@mister-muffin.de.

I also do not see how your image is "stretched". Maybe you are using the wrong terminology? The screenshots you sent seem to both show the image with the exact same aspect ratio.

*By Thiago Moraes on 2021-01-27T22:15:54.273Z* The images downloaded have `width, height = 320, 240 ` but when converted in PDF they are streched, I was looking for inside code a param to use a fix size. Is there a way? ``` from bs4 import BeautifulSoup import requests import re import wget import img2pdf import glob, os import subprocess html_doc = requests.get(URL).content soup = BeautifulSoup(html_doc, 'html.parser') tags = soup.findAll('img') for tag in tags: img_jpg = re.match(r'\bhttp(:?s)?:[^)''"]+\.(?:jpg)(?![a-z/])',tag.attrs['src']) if img_jpg: #Download Images try: wget.download(img_jpg.group(0)) except(err): print(err) # Group Images to convert PDF File img = [] for file in glob.glob("*.jpg"): img.append(file) with open("name.pdf","wb") as f: f.write(img2pdf.convert(img)) ``` --- *By josch on 2021-01-27T22:27:31.374Z* --- This should not happen. Can you please provide an image for which it does happen? --- *By Thiago Moraes on 2021-01-28T12:00:57.065Z* --- Both are in 100%, first is the image and the second pdf. You can observe that the second has been stretched. If I apply zoom in image I can read, different with pdf ![image](/uploads/f20785c242b875d3f178ecb37f2f9419/image.png) ![image](/uploads/380db94626b95ec81384a2c9cdacdc8f/image.png) --- *By josch on 2021-01-28T13:17:58.092Z* --- Maybe you misunderstood. I don't need a screenshot. I need the exact image that you used as an input. Either attach it to this issue or send it to me via email josch@mister-muffin.de. I also do not see how your image is "stretched". Maybe you are using the wrong terminology? The screenshots you sent seem to both show the image with the exact same aspect ratio.
Author
Owner

Closing because of inactivity.

Closing because of inactivity.
josch closed this issue 2022-04-11 06:23:05 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#89
No description provided.