question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get size on fast image?

See original GitHub issue

Is it possible to get the size of a fast image the same way to get size via React Native’s Image.getSize()?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:19
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

35reactions
NoMaxLandcommented, May 2, 2018

@bemaverick it work from version 4.0.8 for me, maybe you need an update ?

@nica0012 You should use state to reload component who display your FastImage :

e.g :

import React, { Component } from "react";
import { Dimensions } from "react-native";
import FastImage from "react-native-fast-image";

const { width } = Dimensions.get("window");

export default class YourFastImage extends Component {
  constructor(props) {
    super(props);
    this.state = {
      calcImgHeight: 0,
    };
  }
  render() {
    const { calcImgHeight } = this.state;
    return (
      <FastImage
        style={{ width: width, height: calcImgHeight }}
        source={{
          uri: "https://unsplash.it/400/400?image=1",
        }}
        resizeMode={FastImage.resizeMode.contain}
        onLoad={evt =>
          this.setState({
            calcImgHeight:
              evt.nativeEvent.height / evt.nativeEvent.width * width, // By this, you keep the image ratio
          })}
      />
    );
  }
}

12reactions
woodpavcommented, Jun 15, 2019

@DylanVann I think an API involving a static FastImage.getSize or a callback on FastImage.preload would be useful.

My usecase is using FastImage inside of react-native-image-zoom. To use the onLoad callback I would have to use a wrapping component that doesnt render the ImageZoom component until the onLoad callback fires. This means I have to rerender the FastImage component after I get the image size. Here’s my current solution using Image.getSize.

https://gist.github.com/woodpav/1707e59feff35502ab9801bf84447c16

Read more comments on GitHub >

github_iconTop Results From Across the Web

fast-image-size - npm
Simple stand alone module to just extract the image size from image file without using special image libraries.. Latest version: 0.1.3, ...
Read more >
python - Get Image size WITHOUT loading image into memory
I compared the speed imagesize. get, magic. from_file, and PIL image to get the actual image size by timeit. The results showed that...
Read more >
File: README — Documentation for fastimage (1.6.6)
Your app needs to find the size or type of an image. ... FastImage does this minimal fetch for image types GIF, JPEG,...
Read more >
fast-image-size | Yarn - Package Manager
Simple stand alone module to just extract the image size from image file without using special image libraries. get image size, image size,...
Read more >
Top 5 react-native-fast-image Code Examples - Snyk
To help you get started, we've selected a few react-native-fast-image examples, ... BORDER_GREY, height: size, width: size, borderRadius: rad, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found