Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
Use p5js script for an NFT?

I have seen people use this method for SVG-based NFTs:

function p5jsToImageURI(){
    string memory baseURL = "data:image/svg+xml;base64,PUT-BASE64-HERE"
}

But, since I don't want to generate a fixed image how can I use my p5js script (that looks slightly different each time the js code runs)? Is there a way to just somehow pass the seed to my script and the script with the seed passed to it is stored on-chain?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

var img,inpt,div

function convertImgToDataURLviaCanvas(url, callback, outputFormat){
    var img = new Image();
    img.crossOrigin = 'Anonymous';
    img.onload = function(){
        var canvas = document.createElement('CANVAS');
        var ctx = canvas.getContext('2d');
        var dataURL;
        canvas.height = this.height;
        canvas.width = this.width;
        ctx.drawImage(this, 0, 0);
        dataURL = canvas.toDataURL(outputFormat);
        callback(dataURL);
        canvas = null; 
    };
    img.src = url;
}

function convertFileToDataURLviaFileReader(url, callback){
    var xhr = new XMLHttpRequest();
    xhr.responseType = 'blob';
    xhr.onload = function() {
        var reader  = new FileReader();
        reader.onloadend = function () {
            callback(reader.result);
        }
        reader.readAsDataURL(xhr.response);
    };
    xhr.open('GET', url);
    xhr.send();
}


function img2b64(imagefile){
    var imageUrl = imagefile;
    var convertType = 'Canvas';    
    var convertFunction = convertType === 'FileReader' ?  convertFileToDataURLviaFileReader :   convertImgToDataURLviaCanvas;
    convertFunction(imageUrl, function(base64Img){
        code='foto = "'+base64Img+'";'
        inpt.value(code)
        div.html('<img src="'+base64Img+'">');  
     });
}



function setup() {
  but = createButton("CONVERT");
  but.mousePressed(function () {
      img2b64('nature100b.jpg');

  });
  inpt = createP('');
  inpt = createElement("textarea",'');
  inpt.elt.rows = 5;
  inpt.elt.cols = 50;
  div = createDiv('');

}

Try this https://editor.p5js.org/josepssv/full/wsCZnJqkA

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!