mdvanes / mdworld-jackson

mdworld theme "Jackson"
https://mdvanes.github.io/mdworld-jackson
MIT License
0 stars 0 forks source link

Replace header images by procedurally generated art based on a hash function #12

Closed mdvanes closed 6 years ago

mdvanes commented 6 years ago

hash of the content or title+date of the article

Shapes:

Emulate pencil drawing with fuzzy mesh

NPM package name: pg-post-cover (pg is procedurally generated) On-hover of each cover image: show info about the name and how it was created

mdvanes commented 6 years ago
sudo apt-get install libcairo2-dev libjpeg-dev libpango1.0-dev libgif-dev build-essential g++
npm i --save canvas
var Canvas = require('canvas')
  , Image = Canvas.Image
  , canvas = new Canvas(200, 200)
  , ctx = canvas.getContext('2d');
const crypto = require('crypto');

const getSHA1ofJSON = function(input){
    return crypto.createHash('sha1').update(JSON.stringify(input)).digest('hex')
}

const x = getSHA1ofJSON({'this':'too'})
// sha1 always 40 chars long
console.log('sha1 is', x);

ctx.font = '30px Impact';
ctx.rotate(.1);
ctx.fillText("Awesome!", 50, 100);

var te = ctx.measureText('Awesome!');
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.beginPath();
ctx.lineTo(50, 102);
ctx.lineTo(50 + te.width, 102);
ctx.stroke();

//console.log('<img src="' + canvas.toDataURL() + '" />');

var base64Data = canvas.toDataURL().replace(/^data:image\/png;base64,/, "");

require("fs").writeFile("out.png", base64Data, 'base64', function(err) {
  console.log(err);
});
mdvanes commented 6 years ago

public.zip

mdvanes commented 6 years ago

Also for retro post json