[Request]Nw.js write image file

0 favourites
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • MadSpy - thank you for that - adding it to my library of useful info!

  • MadSpy Thanks that also works, and even better than my version as I don't have to call the nw.js plugin and keep a modified version of it with "binary" encoding mode :]

    It's pretty much like in the first link I posted on this thread, but I had no idea you could use nw.js functions in execjs too so, it's good to know

    Looks like the "base64" encoding choice does the conversion directly, also saving a step which is nice (so let's says Encoding dropdown: Utf-8 | Base64 | BInary for my suggestion above!)

    Although this is good for temporary work around, I rather not have a capx that looks like a full JS script, and hopefully we can have more "C2-friendly" options in the actual NWJS plugin

  • You want something like this?

  • MadSpy Yes, that's pretty much it, or rather for the name just "Write Image" or "write File +"

    So people could save other things rather than only CanvasSnapshot

    In my case, like I mentioned above I save a bunch of Sprites though the base64 extract plugin

    "var fs = require('fs');fs['writeFileSync']('" & replace(replace(AppPath & "Img\" & replace(Box.Title,":", "~") & " (" & Box.Year & ").png","\","\\"),"'","\'") & "','" & Box.ExtractImage.currentImage & "'.split(',')[1], {'encoding': 'base64'});"[/code:sawspujv]
    
    But yeah my execJS looks like above, would be much cleaner with a proper C2 action... does it mean you are making the plugin?
    If you are, it would be great to have the synchronous/asynchronous dropdown as well :]
  • It should work with the expression from extractimage plugin... and other image convert to base64 string

  • Yeah I guessed it would from the pics, I was just nitpicking about the naming of "Write Canvas Screenshot" instead of something more general

  • "Write image data (base64)" ^^

  • Okay sounds alright

    Btw in case of a separate action from the other Write File, maybe no need to have the utf8/base64, and just keep base64 for this one

    Probably best to have a png/jpg dropdown in that case actually

    How would you plan to implement an extra action to the official plugin like in your pic though, keeping this post in mind?

  • it's a new plugin (I don't change the plugin icon for now) I create extra features and merge with original features

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I see, sounds pretty good then

    Either way Ashley there's still time to consider such a MINOR change for a very HANDY feature in the official plugin.

    I mean, proper games do have a hotkey to save their captures as images in a Screenshots folder... and the file I/O actions are a major reason for people to use nwjs

    PS: In my case of sprite extract and image library, being able to save/load PNGs on disk (currently with the execJS action) instead of TXT images boosted my loading times from 7sec to now just 3sec

  • I don't think this is a minor feature. Data URIs/base64 encoding are a slow and bloated way of dealing with binary data and I don't think we should continue to build on them or encourage their use. It would be better to invent a new efficient general-purpose way to deal with binary data in C2, and then use that to support taking screenshots as a true binary image, and then write true binary to a file. That is a pretty significant feature though.

  • I will try with node buffer

  • Thanks for the reply Ashley

    Can you guys explain what you mean by a "true" binary image (or a fake one)?

    With the method above in the end we seem to get a proper binary PNG file, and very different from it's base64 string counterpart

    Also, either using {'encoding': 'base64'} or atob() and {'encoding': 'binary'} seems to produce the same result

    Can you see the capx below, and explain how the resulting PNG isn't a true binary one?

    NWimagefile.capx

    Otherwise yeah I suppose it would be more efficient to remove the "base64" middle man from the CanvasSnapshot method (or extract base64 plugin),

    and somehow access the binary image data from a layer or a sprite for the user with say Sprite.imageData, and be able to save it directly ^^

    PS: MadSpy I posted a couple of links on page1 with (apparently?) buffer examples

  • I mean using binary data without using a string as an intermediate format. The conversion to and from the string is slow and can waste memory. Ideally it would get binary data and be able to write it directly.

  • Ashley

    Okay yeah I hear you about the intermediate/middle man process

    Looks like it would take a while to develop such mechanics though, and maybe it will happen only for C3

    In the meantime there's no built-in function in C2 to save image screenshots on desktops, and people might still prefer a "slow function" than none at all

    See just yesterday, apparently this guy made his first post on the forums just to ask about this feature (is conversion speed even relevant for a few screenshots?)

    All that's needed is an extra switch in the plugin code, to have the choice in writeFileSync() from {"encoding": "utf8"}, to {"encoding": "base64"} or {"encoding": "binary"}

    So I wouldn't say you "continue to build on them" but rather provide an instant fix/adjustment to have a feature otherwise impossible for the moment

    (*possible now but even more bloated through the use of a custom EjecJS expression)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)