-
Notifications
You must be signed in to change notification settings - Fork 510
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
Question / Comment: Setting xres/yres for new image pages #479
Comments
Actually, I'm seeing a bug here as well. Reference this PDF: https://github.com/wohali/hough/blob/master/samples/Newman_Computer_Exchange_VAX_PC_PDP11_Values.pdf Comparing with
Is this a MuPDF bug? Are xres/yres hardcoded to 96? |
Hi,
I need to check this. I am just passing through what the MuPDF API is giving me. |
First finding: A remark about the document interface for images: Still checking why method |
In your example PDF, none of the 4 images contain resolution information. I verified this by extracting the raw streams and let another image reader analyze them (IrfanView): those two fields are empty in all 4 cases. Independent from this, there is an issue with the correct values provided by So this is where I am now with my modifications:
|
Thanks for the info! I'll be sure to grab a new sample PDF with proper resolution info in it once this fix lands for my own testing, though it's interesting that this PDF provided a different, yet still entirely important test 😆 |
@JorjMcKie After re-reading, I have two questions:
|
I will provide a new Pixmap method for this:
Of course there is nothing that prevents you from putting information in the metadata of a PDF once you have created one from an image document. I would wonder though if that would serve any purpose apart from sheer documentation. # imgbytes is an image in memory ... bytes or bytearray
img_dict = fitz.TOOLS.image_profile(imgbytes) # returns basic image properties
# returns None if unsuccessful
width = img_dict["width"]
height = img_dict["height"]
xres = img_dict["xres"] # (*)
yres = img_dict["yres"] # (*)
page = doc.newPage(width=width, height=height)
page.insertImage(page.rect, stream=imgbytes)
# insertImage internally also uses TOOLS.image_profile Please note that (the currently undocumented) Keys in dictionary I already have modified
|
More or less finished with testing the announced / discussed changes. Also implemented this This restriction only pertains to pixmap saves. As mentioned before: saved images which have been extracted before via Any urgency for publishing the new version? |
@JorjMcKie I can wait a week or so if you have another version pending. Thanks! |
@wohali - if you have a Linux or Mac, you can download a v1.16.17 wheel from here. This is where the Travis generator stores them for the two platforma - look in branches You may want to test the new version a little and provide feedback if you see areas for improvement, before I actually publish it. |
should be addressed by version 1.16.17 uploaded today |
Hey @JorjMcKie , sorry I haven't gotten back to this - work has exploded in the last week and I barely have any free time. I'll try and get you feedback soon, but it looks like the info above + 715a017 will give me what I need to get moving with this. Thanks again! |
No problem at all. |
Hi @wohali - you may be interested to know, that the latest v1.18.0 automatically sets the dpi for PNG images created from pixmap values |
@JorjMcKie Wow, very nice! Thanks. |
Hi there,
PyMuPDF is great! Thanks for the best PDF support in Python on the planet.
I'm currently working on some code to straighten scanned images in PDFs. I use PyMuPDF, imageio and numpy/scikit to do most of the heavy lifting.
Following the guide, I can't figure out how restore the original xres/yres of the extracted image.
Code excerpt, very similar to your example:
I think the issue is in the
fitz.open()
call. I don't see any way to pass inxres/yres
(ppi) options to the constructor. No matter what I do, I end up with 96ppi. (Certain "fruit-branded" PDF readers care about this value a lot.)How do I retain the original
xres/yres
values when creating a new document from an image byte stream?The text was updated successfully, but these errors were encountered: