Comments (5)
Base 64 would work for images, but it sometimes causes problems with larger ones.
I think what you are looking for is piping streams, and that's the same reason I came here too.
from node-pureimage.
Yes, you can do this. You'll need to store them in memory as a buffer instead of saving them to disk. However, you'll still need to serve them to the browser regardless of how they are stored. Your options are to base 64 encode them as a data URL, or you can render them directly to the data stream, referenced by a unique id. ex:
<img src="http://theserver.com/render?format=png&text=foobar"/>
then your server does something like
in event handler for the /render URL route
var ctx = img.getContext('2d');
//draw stuff
img.renderToStream(res);
from node-pureimage.
Doing a bit of necromancy here.
Like the OP I'd like to send images as a datauri, they are all below 200x200 px bandwith shouldn't be an issue here, but I can't seem to figure out how I would generate the datauri from my img object.
I've tried using https://www.npmjs.com/package/datauri which takes a buffer, but the buffer from img.data fails when I try.
I don't seem to have the 'renderToStream' function either. I do have 'encodePNGToStream', but I can't figure out how to use it for generating a datauri either.
Any help would be appreciated.
from node-pureimage.
How does it fail? What error does it give?
from node-pureimage.
Well, the output seems to be an order of magnitude larger than what I expect
(https://pastebin.com/BRHzYvvN)
And when I try to use the datastring as an image I'm being told that "the image cannot be displayed because it contains errors", which is not a lot to go on.
What I'm trying to do is:
datauri.format('.png', img.data);
And then use
datauri.content
from node-pureimage.
Related Issues (20)
- context.font TypeScript types declaration are wrong. HOT 4
- on 'error' is registered 2 times
- work in cloudflare workers HOT 7
- Error: SOI not found
- Rendered path rounding some lines? HOT 1
- fillText produces odd results with some fonts HOT 7
- how to embed the image which i have just created with the message? HOT 5
- ctx.restore() doesn't appear to clear clipping region. HOT 4
- support reading large files HOT 3
- transforms not taking effect for fillRect and drawImage? HOT 7
- drawImage. RangeError: Maximum call stack size exceeded HOT 2
- pngjs outdated causing deprecation warning HOT 1
- [feature] createConicGradient missing
- Path is distorted
- Please support lineCap
- Transparent background HOT 2
- Create a virtual Canvas (without `canvas#data` object)
- Image transparency overwrites existing content
- Error: export 'make' (imported as 'PImage') was not found in 'pureimage' (module has no exports) HOT 7
- [feature request] setting the encode option (e.g. PNG compression level) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-pureimage.