Skip to content
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

PNG Bug #83

Merged
merged 3 commits into from
Nov 13, 2024
Merged

PNG Bug #83

merged 3 commits into from
Nov 13, 2024

Conversation

Filimoa
Copy link
Owner

@Filimoa Filimoa commented Nov 13, 2024

No description provided.

@Filimoa
Copy link
Owner Author

Filimoa commented Nov 13, 2024

Note some PDF will "slice" up their images. We need to recombine these and that's what the new CombineSlicedImages transform does. Note it's pretty naive, if there's a single image on the page it combines everything together. This might be problematic with small logos.

CleanShot 2024-11-12 at 18 02 16
There is still a bug that PNG will sometimes be flipped. Have not figured out the root cause.

You can hardcode something into _combine_images_in_group but this will break non flipped images. From what I understand we need to somehow get data from the Transformation Matrix to figure out an images orientation.

    def _combine_images_in_group(
        self, image_elements: List[ImageElement]
    ) -> ImageElement:
        """Combine a list of ImageElements into a single ImageElement."""
        if not image_elements:
            raise ValueError("No images to combine.")

        images = []
        for node in image_elements:
            image_data = base64.b64decode(node.image)
            image = Image.open(io.BytesIO(image_data))
            # image = image.rotate(180) # THIS 
            images.append(image)

_process_png_image in src/openparse/text/pdfminer/core.py should theoretically be responsible for this flipping operation.

@Filimoa Filimoa merged commit 385882e into main Nov 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant