Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to load a default file? #37

Open
SlightlyRadioactive opened this issue Jun 7, 2022 · 1 comment
Open

How to load a default file? #37

SlightlyRadioactive opened this issue Jun 7, 2022 · 1 comment

Comments

@SlightlyRadioactive
Copy link

I want to use this code in a program of mine, but instead of having the users choose the image they want to use I want to assign an image from another separate program on page load. I've been finding it troublesome to find in which line the this program gets the image. Is there an easy way to do it?

@n-peugnet
Copy link
Owner

This is related to #36. Loading an image programmatically was one of the features I wanted to add but I never really did it.

The image is loaded in the handleFile function, but for now it requires a p5.File variable type. So if you manage to create one from an image it should work if you pass it to that function.

handeFile(file: p5.File): void {
if (file.type == "image") {
this.img.data = this.p5.loadImage(file.data, img => this.resetView(img));
this.img.file = file.file;
if (!this.map.getName()) {
this.map.setName(file.name);
this.settings.setValue("Map Name", this.map.getName());
}
} else if (file.subtype == 'json') {
fetch(file.data)
.then(res => res.blob())
.then(blob => {
let reader = new FileReader();
reader.onload = () => {
let json = reader.result;
if (typeof(json) == "string") {
this.importMap(json);
}
};
reader.readAsText(blob);
});
}
this.bgLayer.disappear();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants