Hi everyone,
I am quite new to p5js world and I am trying to create an Image slicing tool.
The code gets me the wanted result – sliced input image
but it seems that it doesn’t retain the intial resolution of the image,
the output resolution of final saved sliced canvas is really low.
You can test the tool here http://pritomnost.matejvojtus.com/
or see it in action here https://www.instagram.com/p/B-cGNwWBupC/
let input;
let pix;
let img;
let obr;
let x1, x2, y1, y2;
let w, h, m;
let a = 0;
let sr = 40;
function setup() {
let c = createCanvas(window.innerWidth, window.innerHeight);
textAlign(CENTER);
textSize(16);
text('PRITOMNOST IMAGE TOOL 1.6', width / 2, height / 2-48);
text('DRAG AND DROP AN IMAGE', width / 2, height / 2);
text('MOVE CURSOR AROUND TO CHANGE IMAGE PLACEMENT', width / 2, height / 2+20);
text('PRESS AND HOLD MOUSE TO STOP', width / 2, height / 2+40);
text('SAVE TO DESKTOP BY PRESSING S', width / 2, height / 2+60);
c.drop(gotFile);
}
function gotFile(file) {
img = createImg(file.data, created).hide();
clear(); //clears drop image screen
}
function created() {
graphics = createGraphics(img.width, img.height);
graphics.image(img, 0, 0, graphics.width, graphics.height);
let pix = graphics.get(0, 0, graphics.width, graphics.height);
obr = pix;
obr.loadPixels(draw);
}
function draw() {
if (obr){
obr.resize(0, window.innerHeight);
//image(obr, 0, 0);
a = a + sr;
if (a > windowWidth) {
a = 0;
}
m = m + 10;
if (m > height / 4) {
m = 0;
}
m = int(m);
copy(obr, x1, y1, w, h, a, y2, w, h);
x1 = m+mouseY;
y1 = 0;
y2 = 0;
w = sr;
h = height;
}
}
function keyTyped() {
if (key === 's') {
noLoop();
saveCanvas('myCanvas.jpg');
}
}
function mousePressed() {
noLoop(); // Holding down the mouse activates looping
}
function mouseReleased() {
loop(); // Releasing the mouse stops looping draw()
}
I really appreciate any help! Thank you in advance.