Git Product home page Git Product logo

use-image's People

Contributors

khems avatar lavrton avatar miker2049 avatar nko-sh avatar nomyfan avatar stigzord avatar trent1900 avatar xuanduc987 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

use-image's Issues

Problems with img cache

I need update coordinates of my image with setInterval, but everytime image is reloading (not caching)
How fix it?
My component:
`const Rocket = ({x, y}: any) => {
const [ image ] = useImage(rocket_img);

return (
    <Image
        image={image}
        width={44}
        height={82}
        offsetX={22}
        offsetY={62}
        rotation={45}
        x={x}
        y={y}
    />
);

}`

pass upload image to useImage

I have some input for upload the image and then show this image in Layer with useImage.
how to pass an image to useImage when uploading an image.

ChainAlert: npm package release (1.0.11) has no matching tag in this repo

Dear use-image maintainers,
Thank you for your contribution to the open-source community.

This issue was automatically created to inform you a new version (1.0.11) of use-image was published without a matching tag in this repo.

As part of our efforts to fight software supply chain attacks, we would like to verify this release is known and intended, and not a result of an unauthorized activity.

If you find this behavior legitimate, kindly close and ignore this issue. Read more

badge

TS2322: Type '[HTMLImageElement | undefined, "loaded" | "loading" | "failed"]' is not assignable to type 'HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | undefined'.

The complete error looks like:

TS2322: Type '[HTMLImageElement | undefined, "loaded" | "loading" | "failed"]' is not assignable to type 'HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | undefined'.
Type '[HTMLImageElement | undefined, "loaded" | "loading" | "failed"]' is not assignable to type 'OffscreenCanvas'.

I think this line should be changed:

): [undefined | HTMLImageElement, 'loaded' | 'loading' | 'failed'];

My code is pretty simple as per the docs:

const win = {
  width: window.innerWidth,
  height: window.innerHeight,
}

const App = () => {
  const image = useImage('https://konvajs.org/assets/lion.png')

  return (
    <Stage width={win.width} height={win.height}>
      <Layer>
        <Image image={image} />
      </Layer>
    </Stage>
  )
}

Please update copyright notice in license

According to https://opensource.org/licenses/MIT, the copyright notice in the license should be in the following format:

Copyright YEAR COPYRIGHT HOLDER

But the copyright notice in the license file states only the year.
I think it is important to have a full copyright notice in the license in order to avoid potential licensing problems for users of use-image.

Usage in loops

How would I use this in some kind of loop? I have an array of objects each with their own image and I want to make sure the image is loaded before drawing it to the konva canvas. I don't want a load of useImage statements, plus I don't know how many there will be to load. Any ideas? Thanks

question about loading many images

hey! im just looking for a bit of help, how would you recommend to load an arbitrary amount of images (could be 5, could be 100+), and considering they're image files and not URL's (i.e not using a URL to link to them, theyre files in my create-react-app project).

I was thinking it would be best to show a loading screen (dont even load in the stage/konva) until all of them are loaded

Base64 string to useImage

Can I directly convert a base64 string of an image to a usable image using useImage?
This is what I am trying to do while creating a konva image component to use later in dom.

  const UseKonvaImage = ({ xPos = 50, yPos = 550, dragged, clicked, draggable, imageBase64 }) => { 
  const [image, status] = useImage(imageBase64);
  console.log("component Use Konva Image", imageBase64, status)
  return (
    <KonvaImage
      name="Test"
      image={image}
      x={xPos}
      y={yPos}
      draggable={draggable}
      onDragEnd={dragged}
      onClick={clicked}
    />
  );
};

can not use it with typescript

const [image] = useImage('...');
return <Image image={image} />

the typescript warning:
Type 'HTMLImageElement | undefined' is not assignable to type 'ImageBitmapSource'.
Type 'undefined' is not assignable to type 'ImageBitmapSource'.ts(2322)
Image.d.ts(4, 5): The expected type comes from property 'image' which is declared here on type 'IntrinsicAttributes & ImageConfig & KonvaNodeEvents & ClassAttributes & { children?: ReactNode; }'

React.useState is not a function

| 
   8 | module.exports = function useImage(url, crossOrigin) {
>  9 |   var res = React.useState(defaultState);
  10 |   var image = res[0].image;
  11 |   var status = res[0].status;
  12 |   var setState = res[1];

Issue in Safari

When trying to add an svg into the stage, the added image is whether all white or all black.. tried it in various safari versions. 1st img in chrome, 2nd in safari 14.1 (in this example the image is the grid in the background
chrome
safari14

)

undefined image when serving images

Hi, I am using this hooks to load image, however when I load my image using this hooks it gives me undefined response, my image is located in public folder and I am using next.js to do this

My code looks like this
Code 1

const [image] = useImage('/add.svg');
<Image image={image} />

Code 2

const [image] = useImage('/add.svg', 'Anonymous');
<Image image={image} />

In nextjs docs, it says, to access static files I just need to append / before the filename but the hooks return an undefined response.

React Component debugger

image

Network Response

image

Plans for developing use-fonts?

The biggest usage for asynchronous loading is image and text. (i believe).
Are there any plans for supporting for loading fonts? (it's painful to use)

Image not loaded

Anyone else some issues where the image is not been loaded correctly?

Struggling with this, as it does not always seem to happen. Am I missing something? Thanks!

import { Image, Rect } from 'react-konva';
import useImage from 'use-image';

import moon from '../../../assets/grid/moon.svg';

export function MoonItem({ width, height, rotation }) {
  const [image] = useImage(plant);
  return (
    <>
      <Image
        image={image}
        x={width / 2}
        y={height / 2}
      />
    </>
  );
}

Performance Sucks (flickers)

Trouble

When use useImage render multiple images, It sucks as bellow last pic.

  const [image] = useImage(url);
 return <Image width={w} height={h} ref={imgRef} image={image}></Image>
canvas_preview_640.mp4

Resolution

 const [imageFrame, setImage] = useState(new globalThis.Image());
// imageFrame.src = 'xxx'
// layer.draw();
 return <Image width={w} height={h} ref={imgRef} image={image}></Image>

So ,i wonder why we need a new instance? just In order to avoid manual draw layer?

  React.useLayoutEffect(
    function () {
      if (!url) return;
      var img = document.createElement('img');
    [url, crossOrigin, referrerpolicy]
  );

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.