Created
December 10, 2021 21:51
-
-
Save sspboyd/07385c03e73c9cc3a7b2770283b25433 to your computer and use it in GitHub Desktop.
This code makes it simple to export a lot of versions of a canvas without having to manually change the downloaded file's name so you don't overwrite it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code makes it simple to export a lot of versions of a canvas without having to manually | |
// change the downloaded file's name so you don't overwrite it. | |
const export_canvas = function () { | |
const file_name = "sspboyd"; // change this to whatever you'd prefix your image file name with | |
const dt = new Date(); // create a new date object representing the current time | |
// Parse the date object to get strings for year, month, day, hour, minute, seconds | |
const year = dt.getFullYear(); | |
const month = (dt.getMonth() + 1).toString().padStart(2, "0"); //months from 1-12 | |
const day = dt.getDate().toString().padStart(2, "0"); | |
const hrs = dt.getHours().toString().padStart(2, "0"); | |
const mins = dt.getMinutes().toString().padStart(2, "0"); | |
const secs = dt.getSeconds().toString().padStart(2, "0"); | |
const file_date = `${year}-${month}-${day}-${hrs}-${mins}-${secs}`; // create one long string of the date info | |
saveCanvas(`${file_name}_${file_date}`, "jpg"); // the last argument here can be either 'jpg', or 'png' | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment