[Request]Nw.js write image file

Post your work in progress addons and get feedback

Post » Mon Apr 25, 2016 6:19 pm

Yeah I guessed it would from the pics, I was just nitpicking about the naming of "Write Canvas Screenshot" instead of something more general
Last edited by lemo on Mon Apr 25, 2016 8:59 pm, edited 2 times in total.
B
22
S
6
G
8
Posts: 328
Reputation: 6,651

Post » Mon Apr 25, 2016 8:54 pm

"Write image data (base64)" ^^
Image Image
B
25
S
14
G
136
Posts: 876
Reputation: 71,005

Post » Mon Apr 25, 2016 9:00 pm

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

Post » Mon Apr 25, 2016 9:09 pm

it's a new plugin (I don't change the plugin icon for now) I create extra features and merge with original features
Image Image
B
25
S
14
G
136
Posts: 876
Reputation: 71,005

Post » Mon Apr 25, 2016 9:33 pm

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

Post » Mon Apr 25, 2016 9:44 pm

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.
Scirra Founder
B
397
S
236
G
88
Posts: 24,423
Reputation: 194,560

Post » Mon Apr 25, 2016 10:13 pm

I will try with node buffer
Image Image
B
25
S
14
G
136
Posts: 876
Reputation: 71,005

Post » Mon Apr 25, 2016 10:35 pm

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

Post » Tue Apr 26, 2016 8:31 am

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.
Scirra Founder
B
397
S
236
G
88
Posts: 24,423
Reputation: 194,560

Post » Tue Apr 26, 2016 2:14 pm

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

PreviousNext

Return to Work in Progress Addons

Who is online

Users browsing this forum: No registered users and 1 guest