Can not find the correct attributes or methods to get the correct values of croping #4820
-
|
Hi there! I am trying to get the data using the below script. But I am still struggleing to get the values of cropped images that where exported as pdf by mac pages or mac keynote. Any ideas where to pinpoint me? `import fitz def rgb_to_hex(rgb_tuple): def get_rotation_from_matrix(matrix): def process_shapes_and_lines(page, z_counter): def process_images(doc, page, image_bucket, document_id, z_counter): |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
This is not an issue but a typical "Discussions" item. Transferring ... |
Beta Was this translation helpful? Give feedback.
-
|
You did not include the "problem" file, so there is no way to checkout the situation. Nonetheless one idea you may want to pursue is that the picture may be covered by gray areas ... and is not really cropped. |
Beta Was this translation helpful? Give feedback.
-
|
Hello Jorj, Thank you for your initial feedback. I apologize for the previous post's poor formatting and for posting on the wrong board—thank you for moving this conversation to the appropriate channel. I also understand that the extensive code made debugging difficult. My overall goal is to accurately reconstruct a PDF page as an interactive HTML/CSS stylesheet using PyMuPDF to extract all visual elements (text, vectors, and images) with their correct rendered positions and crops. I had no issues finding the accurate positions, flipping images, getting the fonts and colors. The core issue is that images exported to PDF by Apple Pages and Keynote (which often embed the full image but apply a clipping mask) are not being correctly clipped or masked when I extract their bounding box (BBox) for CSS rendering. 🖼️ The Problem Illustrated The extracted images always bleed because the BBox I retrieve corresponds to the raw, uncropped image dimensions, not the visually clipped area; the cropping dimension values remain the same as the images dimension values. Extraced pdf source: 🛠️ Trials and Current Approach I have extensively modified my image extraction logic (process_images in https://github.com/AntoineFachez/script-pitcher/blob/main/run/pdf-processor/visuals.py ) across several days, coding agents and different maskings, croppings, clipping of pdf outputs and with the help of the documentation of pyMuPDF to address this specific clipping problem. My latest attempt combines several strategies based on PyMuPDF's advanced extraction features: The logic now attempts to set the final crop attribute to the geometrically derived effective_crop_rect. Here is the current state of my process_images function that attempts to find the correct visual bounding box/crop: From pdf-processor/visuals.pydef process_images(doc, page, image_bucket, document_id, z_counter): ❓ My Core Question Despite this complex logic involving get_drawings (for clips and fills) and get_image_info, the effective_crop_rect I calculate still often matches the raw full_pos_rect when processing PDFs from Mac apps. Is there a specific PyMuPDF function or MuPDF concept (perhaps related to the graphics state stack or a different type of masking operator used by Apple products) that I am missing to reliably determine the visually rendered bounding box of a clipped image? I included the original PDF file for analysis. Thank you for your time and continued support. Anthony |
Beta Was this translation helpful? Give feedback.
-
|
I'm afraid there is limited degree of freedom to deal with this. As I wrote: the image is not "cropped" nor "clipped". |
Beta Was this translation helpful? Give feedback.



This is not an issue but a typical "Discussions" item. Transferring ...