Skip to content

Instantly share code, notes, and snippets.

@vladfrangu
Created June 9, 2019 15:15
Show Gist options
  • Save vladfrangu/e018d41c9840b746d729dbcccae7ebca to your computer and use it in GitHub Desktop.
Save vladfrangu/e018d41c9840b746d729dbcccae7ebca to your computer and use it in GitHub Desktop.
Create simple pride flags for your needs

Simple script to create quick pride flags for your needs

I've encountered the need to create pride flags for our project, https://pfp.lgbt and since we had the colors already defined API side, I decided to re-use that and automate the creation of the flags for me.

if any colors are wrong, please let me know on Twitter

Dependencies

  • nodejs > 10
  • canvas npm i canvas
  • canvas-constructor npm i canvas-constructor
const { Canvas } = require('canvas-constructor');
const { promises: fs } = require('fs');
const flags = {
pride: ["#E70000", "#FF8C00", "#FFEF00", "#00811F", "#0044FF", "#760089"],
trans: ["#55CDFC", "#F7A8B8", "#FFFFFF", "#F7A8B8", "#55CDFC"],
pan: ["#FF148C", "#FFDA00", "#05AEFF"],
ace: ["#000000", "#A3A3A3", "#FFFFFF", "#800080"],
nb: ["#FFF433", "#FFFFFF", "#9b59d0", "#000000"],
bi: ["#D9006F", "#744D98", "#0033AB"],
lesbian: ["#A40061", "#B75592", "#ECECEA", "#C44E55", "#8A1E04"],
agender: ["#000000", "#FFFFFF", "#AFECB9", "#BBBBBB", "#000000"],
};
const width = 500, height = 400;
const processImage = (name) => {
const c = new Canvas(width, height);
const colors = flags[name];
const stripeHeight = height / colors.length + 1;
for (let y = 0; y < colors.length; y++) {
c.setColor(colors[y]);
c.addRect(0, y * stripeHeight, width, y * stripeHeight + stripeHeight);
}
return c.toBufferAsync();
}
const main = async () => {
const keys = Object.keys(flags);
for (const key of keys) {
const buffer = await processImage(key);
await fs.writeFile(`./flags/${key}.png`, buffer);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment