Screenshot Function?

A while back I came across an event-based UI character creator in a RPG Maker MV game, and I couldn't help but wonder how it was done. I forgot about it over time, and don't even remember the name by now, but the thought came back to me recently while working on my current project.

From what I could gather, he seemed to take a screenshot of the character you made in his custom UI and save the image under a specific name into the images folder.


I can't seem to find a built-in screenshot function that works anything like this, so does anyone know if there's something in javascript you could do? Or am I overlooking something within RPG Maker MV itself?

If not, then please move this to script requests. Thanks in advance.
It would not be a screenshot function.  It would have been creating a new bitmap by combining lots of other bitmaps of all the parts, and then saving it as a png file.  Not sure what functions MV has that would allow that.  Previous makers needed to have additional libraries added for the extra functionality.
You can blit the character bitmap to another bitmap to build it as it must be stored and save it using something like this:

Code:
function saveCharacter(bitmap, filename) {
  var fs = require('fs');
  var dir = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/');

  if (dir.match(/^\/([A-Z]\:)/)) {
  	dir = dir.slice(1);
  }

  var fileName = decodeURIComponent(dir) + 'img/characters/' + encodeURIComponent(filename + '.png');
  var image64 = bitmap._canvas.toDataURL().replace(/^data:image\/png;base64,/, "");

  fs.writeFileSync(filename, image64, 'base64');
};
It would not be a screenshot function.  It would have been creating a new bitmap by combining lots of other bitmaps of all the parts, and then saving it as a png file.  Not sure what functions MV has that would allow that.  Previous makers needed to have additional libraries added for the extra functionality.

Ah I figured it was probably that, though I wasn't sure because of how explained it in his demo. A bit more complicated than just a simple screenshot, but I know how it works now at the very least, along with the specific javascript functions required.


I was honestly just hoping someone knew a shortcut. Ah well. Thanks you!
You can blit the character bitmap to another bitmap to build it as it must be stored and save it using something like this:



function saveCharacter(bitmap, filename) {
var fs = require('fs');
var dir = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/');

if (dir.match(/^\/([A-Z]\🙂/)) {
dir = dir.slice(1);
}

var fileName = decodeURIComponent(dir) + 'img/characters/' + encodeURIComponent(filename + '.png');
var image64 = bitmap._canvas.toDataURL().replace(/^data:image\/png;base64,/, "");

fs.writeFileSync(filename, image64, 'base64');
};

This is simpler than the code I worked out, though the UI my friend and I made has some 15-20 layers so maybe it just looks simpler. I'll try this out and see how it works.
Looks good, tell me if this work  🙂
It doesn't appear to work properly at all...however rather than the game crashing like my script did(after freezing up for 5 seconds), yours just doesn't appear to do...anything. At least for me. Perhaps I'm using it wrong?

My script had selected a set number of pictures from the 'img/pictures' folder based on about 20 variables.
So let's say variable 1 is 1, then it would pick "1-1.png"
If variable 5 is 2, then it'd pick "5-2.png".

Is there a way to shorten that all down, as well as compress all the selected pictures into a single image? Because I thought I knew but that just made it crash.
How exactly are you calling the function when it does nothing? 
I tried a few ways. Firstly through an event, then as an external plugin itself and giving it its own plugin command, then running it through my own plugin that can call scripts in bulk but only calling that individual script. Wanted to see what worked, what didn't.
Maybe its not finding the directory path, try saving in another place for testing purposes.


I use a similar function in a plugin and it works fine.
What did you use as the script call in the event? Can you copy/paste the code you used?
Maybe its not finding the directory path, try saving in another place for testing purposes.


I use a similar function in a plugin and it works fine.



Ah that wasn't it. I tried it in a different project and it worked just fine. I guess there's something either blocking the script, a script conflict(doubt it), or my project is just bugged. I'll figure it out on my own from here. Thanks a bunch 😀
I see... well good luck [:

Original thread: https://forums.rpgmakerweb.com/threads/screenshot-function.67664/