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

Added page.clipRect for rasterizing via PhantomJS #45

Closed
wants to merge 2 commits into from

Conversation

jkphl
Copy link
Contributor

@jkphl jkphl commented May 14, 2016

This might be an issue specific for my platform (running on Node.js v5.10.1 on a Gentoo box), but I need to have settings for page.clipRect (docs here) in place as well (alongside with page.viewportSize) to make the rendered PNG have the correct dimensions. If clipRect is missing, there will always be PhantomJS' default dimensions (400 x 300 px) kicking in for the sides being less than these defaults. I.e. an SVG supposed to render as 500 x 100 px will end up being 500 x 300 px, and a 100 x 500 px one will end up with 400 x 500 px. The page.clipRect might not be necessary for other platforms, but I don't see any harm for them either.

@jkphl
Copy link
Contributor Author

jkphl commented May 14, 2016

Secondly, PhantomJS obviously has got some problems with SVG files containing CSS media queries (see mediaqueries.svg.txt as an example; had to give it a .txt ending for upload). It looks like setting the page dimensions after the SVG has been loaded won't trigger PhantomJS to properly re-render the viewport and reflect the changes caused by the media queries. Forcing PhantomJS to reload the SVG once more after setting the dimensions seems to solve this problem.

@domenic
Copy link
Owner

domenic commented Aug 5, 2016

I'm taking the first commit. I can't take the second without a test; what is the expected rendering of mediaqueries.svg?

domenic added a commit that referenced this pull request Aug 5, 2016
Apparently this helps on some platforms, and it seems like it won't hurt. See #45.
@jkphl
Copy link
Contributor Author

jkphl commented Aug 5, 2016

@domenic When you open mediaqueries.svg in your browser and resize the window, the color of the zebra should change depending on the window width (there are 3 color variants). I don't remember the exact situation, but normally PhantomJS should render the the file at its original size, which means that the zebra should be red. It wasn't, however, because PhantomJS seemed to apply the size shortly after exporting the binary data.

@domenic domenic closed this in d5a7d32 Aug 9, 2016
@domenic
Copy link
Owner

domenic commented Aug 9, 2016

Thanks. It looks like this already works, so I committed some tests to make sure it stays that way.

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.

2 participants