Giter Site home page Giter Site logo

Loading images with require about react HOT 5 CLOSED

p5-wrapper avatar p5-wrapper commented on March 28, 2024
Loading images with require

from react.

Comments (5)

jamesrweb avatar jamesrweb commented on March 28, 2024 1

I have updated the examples in my fork of this repo to show a workaround for loading images, feel free to check the example there and hopefully it helps in the future. I will be aiming to look into the types library more because it is missing modules like p5.sound also, as discussed in #11.

from react.

jwilso48 avatar jwilso48 commented on March 28, 2024

Did you ever figure this out?

from react.

Jack-Wiebe avatar Jack-Wiebe commented on March 28, 2024

HI there, I am struggling with the same issue of passing an image to the p5-wrapper.
Does anyone have a solution to this problem?

from react.

icatstudio avatar icatstudio commented on March 28, 2024

I think I have found the solution but still working on it tho! Its something along the following lines;

FIRST
import your images into your top most module.

import turnBuddy from '../img/pmini3.png'
import pickBuddy from '../img/pmini2.png'
import robotBuddy from '../img/pmini1.png'

You do not necessarily have to use them in your code, its just for reference purposes for react to correctly build the project with your "images at the correct location".

After build process your images will be located @ [... yourReactDirectory]/build/static/media with some hash like numbers added to their original names.

My pmini2.png file became pmini2.263db811.png after the build. As far as I could observe this renaming process happens once so you wont have to update your references each time a build is executed.

SECOND
Once the react build is complete you may either access these images locally or through some API you might run in the background. I already have an API running for locally serving state data so I just added another route to access images located under the location explained above.

using loadImage() method of p5 I could some how access and touch the images. Loads without an error BUT when I console.log the image; the image array appears to be empty. All the rest attributes including the image size and name data appears to be correct. But the image wont show up!

let address = 'http://127.0.0.1:3000/image/'

let turnBuddy = p5.loadImage(address + '3', () => {
        console.log(turnBuddy)
        p5.image(turnBuddy, 0, 0, 50, 50)
      })

So far my solution ...

from react.

jamesrweb avatar jamesrweb commented on March 28, 2024

Closing due to inactivity.

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.