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

Image export broken on components #210

Open
bernaferrari opened this issue Mar 18, 2025 · 3 comments
Open

Image export broken on components #210

bernaferrari opened this issue Mar 18, 2025 · 3 comments

Comments

@bernaferrari
Copy link
Owner

bernaferrari commented Mar 18, 2025

Image

bug.fig.zip

@mimshwright
Copy link
Contributor

mimshwright commented Mar 19, 2025

<div data-layer="Frame 98" class="Frame98" style="width: 130px; height: 118px; position: relative; background: white; overflow: hidden">
  <img data-layer="image 8" class="Image8" style="

>>> width: 422px; height: 470px; left: -146px; top: -176px;

position: absolute" src="https://placehold.co/422x470" />
</div>

I think it may have to do with the Clip Contents setting. this is actually a larger image that is cropped to the size of the component frame. I wonder if maybe it's getting confused about how big the image actually is and how much of it to show?

for example, when i only select the image, you can see that it's showing a piece that is 130x118 (the size of the comonent) but the size in the HTML is 422x470 (the original size of the image). So maybe when you do exportAsync, it is exporting the cropped version but the size information is for the full image.

Image

@mimshwright
Copy link
Contributor

The solution might be to get the size of the exported image and use that rather than the native size of the node.

This is an AI generated function for getting the dimensions of a PNG file and it could be called in images.ts line 75

const getImageDimensionsFromBytes = (
  bytes: Uint8Array,
): { width: number; height: number } => {
  // Check if the bytes represent a valid PNG file
  const pngSignature = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
  for (let i = 0; i < pngSignature.length; i++) {
    if (bytes[i] !== pngSignature[i]) {
      console.error("Invalid PNG file");
      return { width: -1, height: -1 };
    }
  }

  // The IHDR chunk starts at byte 16
  const width =
    (bytes[16] << 24) | (bytes[17] << 16) | (bytes[18] << 8) | bytes[19];
  const height =
    (bytes[20] << 24) | (bytes[21] << 16) | (bytes[22] << 8) | bytes[23];

  return { width, height };
};

@bernaferrari
Copy link
Owner Author

I wonder what is different from frame to component

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

No branches or pull requests

2 participants