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

Orientation of some images is incorrect #2972

Open
aen1gma opened this issue Nov 21, 2024 · 4 comments
Open

Orientation of some images is incorrect #2972

aen1gma opened this issue Nov 21, 2024 · 4 comments

Comments

@aen1gma
Copy link

aen1gma commented Nov 21, 2024

Describe the bug
Some images are rendered with the incorrect orientation (i.e. rotated 90 CCW)

To Reproduce
Try to render this file
14584b6b25987936ec666db6445209d5

Expected behavior
The image should be rendered the same way as when you open the file in an image viewer

Screenshots
comparison

Desktop (please complete the following information):

  • OS: Windows 11
  • Browser: Chrome
  • React-pdf version 9.1.1
  • React renderer version 4.1.3
@aen1gma
Copy link
Author

aen1gma commented Dec 2, 2024

Is there anyone who could provide some insight on this? I've taken a look at the EXIF data and I can't see any difference between this photo and another that is oriented correctly

@diegomura
Copy link
Owner

I spent the last hour trying to figure it out and I actually don't know. EXIF orientation is being correctly decoded, and in the PDF the image has correct dimensions. Seems to be something on how it's encoded that makes it render incorrectly. JPEG viewers seems to be understanding it, but couldn't figure out what it is. I'll leave this open in case someone else with more experience on JPEG format knows. I recommend re-encoding the image

@giancarlo-cf
Copy link

I encountered the same issue in a Next.js project. I noticed a brief flicker of the correct image during hot reloading, which led me to this workaround:

// ...
const [data, setData] = useState<DataInterface | null>(null);
useEffect(() => {
    // ... 
    setData(data);
    setTimeout(() => { setData(null); setTimeout(() => { setData(data) }, 1) }, 1);
}, []);

return (
    {data &&
        (<PDFViewer>
            <Document>
              <Page>
                <View>
                  <Image src="https://example.com/image.jpg" />
    // ...
);

The trick seems to be conditionally rendering the PDF and triggering a second render.

Without the workaround:

image

With the workaround:

image

Please ignore the red numbered circles as they are absolute-positioned and placed on top of the image.

@aen1gma
Copy link
Author

aen1gma commented Dec 16, 2024

@giancarlo-cf thank you, this workaround worked for me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants