Giter VIP home page Giter VIP logo

Comments (5)

omril1 avatar omril1 commented on May 20, 2024

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.

joshmarinacci avatar joshmarinacci commented on May 20, 2024

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.

TheLogan avatar TheLogan commented on May 20, 2024

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.

robertmain avatar robertmain commented on May 20, 2024

How does it fail? What error does it give?

from node-pureimage.

TheLogan avatar TheLogan commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.