-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Render GIF images #531
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
Render GIF images #531
Conversation
| expect(dummyRoot.instance.image.mock.calls[0][0]).toBe(image.image.data); | ||
| }); | ||
|
|
||
| /* test('Should render a buffer gif image', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test currently makes the test runner hang, which is why I’ve commented it out. Haven’t worked out why it’s hanging yet 🤔
|
It may not be necessary to use |
1b097a4 to
4d90ed2
Compare
4d90ed2 to
629eb1b
Compare
| if (!BROWSER) { | ||
| const pngBuffer = await sharp(data).toBuffer(); | ||
| return new PNG(pngBuffer); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an issue with the way Rollup bundles this — because it doesn’t do dead-code elimination exactly, the browser builds still import the server-side sharp module, so — even though the BROWSER global is set to true — when it’s consuming the build Webpack processes the import sharp from 'sharp' statement and gives this error:
WARNING: Critical dependency: the request of a dependency is an expression (expand for details)
WARNING in ./node_modules/sharp/lib/libvips.js 51:22-69
Critical dependency: the request of a dependency is an expression
@ ./node_modules/sharp/lib/constructor.js
@ ./node_modules/sharp/lib/index.js
@ ./node_modules/@react-pdf/renderer/dist/react-pdf.browser.es.js
@ ./src/client/components/xocs/jsx-components.pdf.js
@ ./src/client/clientRender.pdf.js
@ ./src/client/index.pdf.js
@ multi (webpack)-dev-server/client?http://localhost:8082 (webpack)/hot/dev-server.js ./src/client/index.pdf ./src/client/style.scss
WARNING in ./node_modules/sharp/lib/libvips.js 52:23-70
Critical dependency: the request of a dependency is an expression
@ ./node_modules/sharp/lib/constructor.js
@ ./node_modules/sharp/lib/index.js
@ ./node_modules/@react-pdf/renderer/dist/react-pdf.browser.es.js
@ ./src/client/components/xocs/jsx-components.pdf.js
@ ./src/client/clientRender.pdf.js
@ ./src/client/index.pdf.js
@ multi (webpack)-dev-server/client?http://localhost:8082 (webpack)/hot/dev-server.js ./src/client/index.pdf ./src/client/style.scss
ERROR: Module not found: Error: Can't resolve 'child_process' (expand for details)
ERROR in ./node_modules/detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'child_process' in './node_modules/detect-libc/lib'
@ ./node_modules/detect-libc/lib/detect-libc.js 4:16-40
@ ./node_modules/sharp/lib/platform.js
@ ./node_modules/sharp/lib/libvips.js
@ ./node_modules/sharp/lib/constructor.js
@ ./node_modules/sharp/lib/index.js
@ ./node_modules/@react-pdf/renderer/dist/react-pdf.browser.es.js
@ ./src/client/components/xocs/jsx-components.pdf.js
@ ./src/client/clientRender.pdf.js
@ ./src/client/index.pdf.js
@ multi (webpack)-dev-server/client?http://localhost:8082 (webpack)/hot/dev-server.js ./src/client/index.pdf ./src/client/style.scss
ERROR in ./node_modules/sharp/lib/libvips.js
Module not found: Error: Can't resolve 'child_process' in './node_modules/sharp/lib'
@ ./node_modules/sharp/lib/libvips.js 6:18-42
@ ./node_modules/sharp/lib/constructor.js
@ ./node_modules/sharp/lib/index.js
@ ./node_modules/@react-pdf/renderer/dist/react-pdf.browser.es.js
@ ./src/client/components/xocs/jsx-components.pdf.js
@ ./src/client/clientRender.pdf.js
@ ./src/client/index.pdf.js
@ multi (webpack)-dev-server/client?http://localhost:8082 (webpack)/hot/dev-server.js ./src/client/index.pdf ./src/client/style.scss
ERROR in ./node_modules/bindings/bindings.js
Module not found: Error: Can't resolve 'fs' in './node_modules/bindings'
@ ./node_modules/bindings/bindings.js 5:9-22
@ ./node_modules/sharp/lib/constructor.js
@ ./node_modules/sharp/lib/index.js
@ ./node_modules/@react-pdf/renderer/dist/react-pdf.browser.es.js
@ ./src/client/components/xocs/jsx-components.pdf.js
@ ./src/client/clientRender.pdf.js
@ ./src/client/index.pdf.js
@ multi (webpack)-dev-server/client?http://localhost:8082 (webpack)/hot/dev-server.js ./src/client/index.pdf ./src/client/style.scss
ERROR in ./node_modules/detect-libc/lib/detect-libc.js
Module not found: Error: Can't resolve 'fs' in './node_modules/detect-libc/lib'
@ ./node_modules/detect-libc/lib/detect-libc.js 5:18-31
@ ./node_modules/sharp/lib/platform.js
@ ./node_modules/sharp/lib/libvips.js
@ ./node_modules/sharp/lib/constructor.js
@ ./node_modules/sharp/lib/index.js
@ ./node_modules/@react-pdf/renderer/dist/react-pdf.browser.es.js
@ ./src/client/components/xocs/jsx-components.pdf.js
@ ./src/client/clientRender.pdf.js
@ ./src/client/index.pdf.js
@ multi (webpack)-dev-server/client?http://localhost:8082 (webpack)/hot/dev-server.js ./src/client/index.pdf ./src/client/style.scss
ERROR in ./node_modules/sharp/lib/libvips.js
Module not found: Error: Can't resolve 'fs' in './node_modules/sharp/lib'
@ ./node_modules/sharp/lib/libvips.js 3:11-24
@ ./node_modules/sharp/lib/constructor.js
@ ./node_modules/sharp/lib/index.js
@ ./node_modules/@react-pdf/renderer/dist/react-pdf.browser.es.js
@ ./src/client/components/xocs/jsx-components.pdf.js
@ ./src/client/clientRender.pdf.js
@ ./src/client/index.pdf.js
@ multi (webpack)-dev-server/client?http://localhost:8082 (webpack)/hot/dev-server.js ./src/client/index.pdf ./src/client/style.scss
ERROR in ./node_modules/sharp/build/Release/sharp.node 1:0
Module parse failed: Unexpected character '�' (1:0)
You may need an appropriate loader to handle this file type.
(Source code omitted for this binary file)
@ ./node_modules/sharp/lib/input.js 5:14-52
@ ./node_modules/sharp/lib/index.js
@ ./node_modules/@react-pdf/renderer/dist/react-pdf.browser.es.js
@ ./src/client/components/xocs/jsx-components.pdf.js
@ ./src/client/clientRender.pdf.js
@ ./src/client/index.pdf.js
@ multi (webpack)-dev-server/client?http://localhost:8082 (webpack)/hot/dev-server.js ./src/client/index.pdf ./src/client/style.scss
ℹ 「wdm」: Failed to compile.
Do you know of a way to shake the non-BROWSER code completely out of Rollup’s browser builds? :)
|
@diegomura I didn’t work out how to push the GIFs’ LZW-compressed image data into the PDF partly due to build issues as discussed in react-pdf/pdfkit#7, so in the end I’m converting the images to PNG (server-side) and JPG (client-side), as it seemed the quickest way of getting the GIF images in. Definitely room to improve on this but in principle, it does the job for now. Would you be able to review this please — it needs testing against GIFs and client- and server-side. There are also a couple of specific issues around tests and bundling which I’ve commented on above. Thanks! |
|
I think this can be easily ported to 2.0. The only think that worries me is the several dependencies this PR adds. How much bundle size will add to the lib? |
Once finished along with react-pdf/pdfkit#7, this would resolve #507.