This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
apemanzilla's profile picture

nfp2png - Screenshots just got a lot easier.

Started by apemanzilla, 11 July 2014 - 04:43 PM
apemanzilla #1
Posted 11 July 2014 - 06:43 PM
nfp2png (Beta!)

I was getting tired of the long, tedious process of embedding a screenshot of a program on the forums. That's why I started this three part project - nfp2png. The end goal is to have something that will allow you to, at any time while running a program on a computer, press a key-combo (Like ctrl + p, ctrl + u, etc) and have it take a screenshot (as a Sketch file most likely) which will be uploaded to Pastebin automatically. At this point a dialog will appear on the screen with the paste's ID, which can then be typed into a web page and instantly converted into a complete image tag, ready for pasting into a thread.

The parts

As I mentioned in the above blob, this project is broken up into three parts:

- ​The backend - this is the PHP code that converts the file to a PNG image so it can be embedded. This part is already done and working for NFP pastes.

- The frontend - this is the page that the client can use to provide a paste ID and have it automatically converted, with a preview, embed code, and possibly other tools.

- The screenshot utility - this will most likely be the most difficult part to create, as it would require everything from a custom terminal API to advanced coroutine control. This would be available for install on a CC computer, which would then be able to save the data from the screen as a Sketch file (I'm working on adding support for Sketch files to the backend) so that it can be converted to a PNG when necessary.

How it works

Right now, the only part that can be tested is the PHP backend. It can currently convert any nfp (paint) file into a PNG which can then be embedded:

To demonstrate, here's some random scribbles:


And here's the link that I embedded it with:


As you can see, this uses the GET protocol to specify the parser version (This will be critical for backwards-compatibility) and the paste ID of the file. The PNG is generated "on-the-fly" by the script (not saved) to preserve disk space. For anyone who looks carefully, you'll notice that I'm passing these parameters to a file called "convert.png." This is a redirect, not a real file, to the "convert.php" file. This is critical, because the forums do not allow you to embed images if the extension isn't an image extension - no matter what the MIME type is. Without this, an error will be shown when posting and the image tag would be converted to a link.


As the frontend is not complete yet, the only way to use this is manually typing out the parameters - but here's a template:


Just replace the part that says to replace it (Including the [ and ]) with the ID of a paste with an NFP. If you really feel like it, you can also change the debug flag to "true" - this just numbers each pixel by column.

How to help/Code

I am a strong believer in open-source software. All three parts of this project are/will be available on GitHub here for anyone to see/contribute to.

More examples



One of the original testing images



All 16 colors



Another testing image, with debug mode enabled. Each number represents the column of the pixel.

License

All of the code is licensed under the MIT Open-Source License.
Edited on 12 July 2014 - 04:51 PM
Saldor010 #2
Posted 11 July 2014 - 09:54 PM
Very neat! Can't wait until it's done ;)/>
apemanzilla #3
Posted 11 July 2014 - 11:20 PM
Very neat! Can't wait until it's done ;)/>
Thanks - I'm currently working on adding the frontend and support for nft/skch files, then I can start on the in-game utility.
Cranium #4
Posted 11 July 2014 - 11:22 PM
Not bad at all. It's neat someone is trying to implement this.
apemanzilla #5
Posted 12 July 2014 - 12:05 AM
Not bad at all. It's neat someone is trying to implement this.
Thanks!

It only took me two hours to figure out that .nft and .skch files use non-printing characters, so with any luck I'll have at least .nft support by the end of the weekend.
SquidDev #6
Posted 13 July 2014 - 09:56 PM
This is pretty awesome idea. I don't like the idea of using someone elses web interface though, it results in dependance. I've written a Nfp2Bmp converter instead, which runs in CC. I prefer PNGs but the structure of PNGs is massivly messed up so I've had to settle with BMP.

Sorry for hijacking your thread.
oeed #7
Posted 14 July 2014 - 12:51 AM
Awesome!

Just one question in regards to using Sketch files, and it may sound silly from me really, but what's the advantage over using it over NFT? It's essentially NFT but with layers, and I'm not really sure how you'd work them.

Anyway, this is really neat. Maybe we can have a CC version of puush soon :P/>
Agoldfish #8
Posted 14 July 2014 - 01:15 AM
Maybe we can have a CC version of puush soon :P/>
You misspelled 'lightshot'.
Engineer #9
Posted 14 July 2014 - 11:57 AM
Maybe we can have a CC version of puush soon :P/>/>
You misspelled 'lightshot'.
If you don't know, puush is a screenshot program with the purpose of sharing it quickly, lightshot files can only be viewed in cc. Plus, lightshot is more of a video as opposed to an image.

So, puush is not lightshot, like at all. And btw, ik talking about the lightshot on cc and not the program irl (i actually don't know how lightshot really works :P/>)
apemanzilla #10
Posted 14 July 2014 - 02:19 PM
This is pretty awesome idea. I don't like the idea of using someone elses web interface though, it results in dependance. I've written a Nfp2Bmp converter instead, which runs in CC. I prefer PNGs but the structure of PNGs is massivly messed up so I've had to settle with BMP.

Sorry for hijacking your thread.
Thanks. Why don't you like using external web interfaces? Pastebin and GitHub are external web interfaces…
Awesome!

Just one question in regards to using Sketch files, and it may sound silly from me really, but what's the advantage over using it over NFT? It's essentially NFT but with layers, and I'm not really sure how you'd work them.
I'm not actually sure - I had considered OSX style screenshots where you could select areas, which would be separated into their own layers, but it may be better to just capture the whole screen as an NFT.
Anyway, this is really neat. Maybe we can have a CC version of puush soon :P/>
That's the end goal :3
Maybe we can have a CC version of puush soon :P/>
You misspelled 'lightshot'.
If you don't know, puush is a screenshot program with the purpose of sharing it quickly, lightshot files can only be viewed in cc. Plus, lightshot is more of a video as opposed to an image.

So, puush is not lightshot, like at all. And btw, ik talking about the lightshot on cc and not the program irl (i actually don't know how lightshot really works :P/>)
Additionally, lightshot is targeted at in-game computers, as they're saved as programs. Converting lightshot programs to nfa files and finally to a gif could work, but at that point it'd just be overkill.
Agoldfish #11
Posted 14 July 2014 - 03:13 PM
This is pretty awesome idea. I don't like the idea of using someone elses web interface though, it results in dependance. I've written a Nfp2Bmp converter instead, which runs in CC. I prefer PNGs but the structure of PNGs is massivly messed up so I've had to settle with BMP.

Sorry for hijacking your thread.
Thanks. Why don't you like using external web interfaces? Pastebin and GitHub are external web interfaces…
Awesome!

Just one question in regards to using Sketch files, and it may sound silly from me really, but what's the advantage over using it over NFT? It's essentially NFT but with layers, and I'm not really sure how you'd work them.
I'm not actually sure - I had considered OSX style screenshots where you could select areas, which would be separated into their own layers, but it may be better to just capture the whole screen as an NFT.
Anyway, this is really neat. Maybe we can have a CC version of puush soon :P/>
That's the end goal :3
Maybe we can have a CC version of puush soon :P/>
You misspelled 'lightshot'.
If you don't know, puush is a screenshot program with the purpose of sharing it quickly, lightshot files can only be viewed in cc. Plus, lightshot is more of a video as opposed to an image.

So, puush is not lightshot, like at all. And btw, ik talking about the lightshot on cc and not the program irl (i actually don't know how lightshot really works :P/>)
Additionally, lightshot is targeted at in-game computers, as they're saved as programs. Converting lightshot programs to nfa files and finally to a gif could work, but at that point it'd just be overkill.
You guys know lightshot is an actually windows/mac program, right?
apemanzilla #12
Posted 14 July 2014 - 03:44 PM
–snip–
You guys know lightshot is an actually windows/mac program, right?
Yeah, but we thought you were talking about the CC version, since, this is the CC forums…
Bomb Bloke #13
Posted 14 July 2014 - 06:05 PM
The screenshot utility - this will most likely be the most difficult part to create, as it would require everything from a custom terminal API to advanced coroutine control. This would be available for install on a CC computer, which would then be able to save the data from the screen as a Sketch file (I'm working on adding support for Sketch files to the backend) so that it can be converted to a PNG when necessary.

Sounds to me like it'd be worth looking into the possibility of a script that loads altered versions of multishell + window API functions (to get the screen data from the terminal buffer already implemented on all advanced systems since CC 1.6).
SquidDev #14
Posted 14 July 2014 - 06:49 PM
This is pretty awesome idea. I don't like the idea of using someone elses web interface though, it results in dependance. I've written a Nfp2Bmp converter instead, which runs in CC. I prefer PNGs but the structure of PNGs is massivly messed up so I've had to settle with BMP.

Sorry for hijacking your thread.
Thanks. Why don't you like using external web interfaces? Pastebin and GitHub are external web interfaces…

Ok, when I say external web interfaces I mean small, one man band, websites, not a $750 million company (no offence). My main issue is if your website goes down, expires or whatever, any image that uses your service will be gone (though if Computer Craft will still be around when your website dies I don't know). I know my image is still on pastebin but everywhere I've linked it to is gone.

I think this is a great idea but would be more flexible using an image hosting service like Dropbox or Imgur, but even that has its problems.
apemanzilla #15
Posted 14 July 2014 - 08:01 PM
This is pretty awesome idea. I don't like the idea of using someone elses web interface though, it results in dependance. I've written a Nfp2Bmp converter instead, which runs in CC. I prefer PNGs but the structure of PNGs is massivly messed up so I've had to settle with BMP.

Sorry for hijacking your thread.
Thanks. Why don't you like using external web interfaces? Pastebin and GitHub are external web interfaces…

Ok, when I say external web interfaces I mean small, one man band, websites, not a $750 million company (no offence). My main issue is if your website goes down, expires or whatever, any image that uses your service will be gone (though if Computer Craft will still be around when your website dies I don't know). I know my image is still on pastebin but everywhere I've linked it to is gone.

I think this is a great idea but would be more flexible using an image hosting service like Dropbox or Imgur, but even that has its problems.
Ah, I see. I have been carefully monitoring bandwidth and disk usage as I work on this and right now it seems fine although I am not sure if it would stay that way with more widespread usage. If it does start to get dangerous, I'd definitely warn everyone though.

I've been working on NFT support, but am having some problems. Later I'll update the repo with the latest code if anyone wants to help out some.
apemanzilla #16
Posted 16 July 2014 - 02:07 AM
I think to get this to work properly with different file formats I'm going to have to rewrite most of the current code - it's too slow and inefficient right now. I'll keep the format the same, so anything generated with this version shouldn't be affected.