[Request]Nw.js write image file

Post your work in progress addons and get feedback

Post » Fri Apr 22, 2016 7:14 pm

I mean zipping them rather than making a blob.
There should be libs for doing that.

Just so you know.
I have saved multiple images from Chrome from a web app.
So it's doable that way, but you have to change a few settings in Chrome.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Fri Apr 22, 2016 8:21 pm

I dunno, that's sounds like a lot more complicated approach to me than storing each image directly
Even if there's a lib, someone would still need to make a plugin to use it
And I doubt adding an extra step for unzipping will help my loading times
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Sat Apr 23, 2016 12:25 am

HURRAY

NW.JS Write File > Browser.ExecJS("atob("""&tokenat(Sprite.ExtractImage.currentImage,1,",")&""")")

This finally works, and saves a PNG file representation of the Sprite in the specified folder automatically
I mentioned ExecJs + atob() a few posts above, and couldn't get the quotes right, then I dug out this post
The link to the video tutorial that James linked is gone, I found it again here on Youtube thanks to the title

For general screenshots on disk: Browser.ExecJS("atob(""" & tokenat(CanvasSnapshot, 1, ",") & """)")

Now this method doesn't work (anymore?), and produces the same corrupted image I had in other tests
I also had to edit the original NW.JS plugin, and exchange the Write File encoding from "utf8" to "binary"
This now works, and here's the change below, with a UI mockup to hopefully have it for the official plugin

Runtime.js
Code: Select all
   Acts.prototype.WriteFile = function (path_, contents_)
   {
      if (!isNWjs)
         return;
      
      try {
         fs["writeFileSync"](path_, contents_, {"encoding": "binary"});
      }
      catch (e)
      {}
   };


Suggestion
Image

Also while I'm at it I added another suggested option to choose between Synchronous/Asynchronous
Like rexrainbow mentioned, it would be worth having to maybe improve performance in some cases
Anyway, I think it's important to have a way to save live screenshots or batch of image on desktop apps

@Ashley can you have a look at this suggestion for the nwjs plugin?
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Sat Apr 23, 2016 6:49 am

+1 to request support for this simple addition to the only method of exporting to all desktops.
A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,286
Reputation: 47,556

Post » Sat Apr 23, 2016 7:07 am

For screenshot:

Code: Select all
Browser.ExecJS("var fs = require('fs');fs['writeFileSync']('" &replace(NodeWebkit.UserFolder & "screenshot" & ".png","\","\\")& "','" &CanvasSnapshot& "'.split(',')[1], {'encoding': 'base64'});")
Image Image
B
26
S
15
G
143
Posts: 882
Reputation: 74,562

Post » Sat Apr 23, 2016 1:01 pm

@MadSpy - thank you for that - adding it to my library of useful info!
A big fan of JavaScript.
B
76
S
20
G
76
Posts: 2,286
Reputation: 47,556

Post » Sat Apr 23, 2016 1:14 pm

@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
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Mon Apr 25, 2016 11:19 am

You want something like this?
Image
Image
Image
Image Image
B
26
S
15
G
143
Posts: 882
Reputation: 74,562

Post » Mon Apr 25, 2016 1:15 pm

@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

Code: Select all
"var fs = require('fs');fs['writeFileSync']('" & replace(replace(AppPath & "Img\" & replace(Box.Title,":", "~") & " (" & Box.Year & ").png","\","\\"),"'","\'") & "','" & Box.ExtractImage.currentImage & "'.split(',')[1], {'encoding': 'base64'});"


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 :]
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Mon Apr 25, 2016 2:11 pm

It should work with the expression from extractimage plugin... and other image convert to base64 string
Image Image
B
26
S
15
G
143
Posts: 882
Reputation: 74,562

PreviousNext

Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 0 guests