Giter Site home page Giter Site logo

austinpoon / gl-react-image Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gre/gl-react-image

0.0 0.0 0.0 383 KB

Universal gl-react Image that implements resizeMode in OpenGL

Home Page: https://gl-react-image.surge.sh

HTML 9.14% JavaScript 83.17% CSS 7.69%

gl-react-image's Introduction

gl-react-image

Universal gl-react module that implements resizeMode prop in OpenGL.

-> Example App <-

The library is called gl-react-image but barely anything can be the source, it can be a video, a canvas, another stack of effects,... (anything that gl-react support as a texture)

yarn add gl-react-image
import GLImage from "gl-react-image";
import {Surface} from "gl-react-dom";// or "gl-react-native" or "gl-react-expo" or ..

<Surface ...>
  <GLImage
    source="http://i.imgur.com/tCatS2c.jpg"
    resizeMode="stretch"
  />
</Surface>

GLImage Props

  • source (required): the texture input. It can be an image URL or anything gl-react supports for textures.
  • resizeMode: "cover" | "stretch" | "contain" : This implement the exact same React Native Image resizeMode prop in OpenGL.
  • center and zoom props can be used with resizeMode=cover to define the cover crop position:
    • center, an [x,y] array, defines the gravity of the crop (x and y are in [0, 1] bound).
    • zoom should be a value in ] 0 , 1 ] bound. 1 means no zoom, more value is close to 0, more the zoom is important.
  • width and height: only provide if you also want a resize. (this is feeded to the gl-react Node width/height)

Example

-> Example App <-

<GLImage
  source="http://i.imgur.com/tCatS2c.jpg"
  resizeMode="stretch"
/>

alternative syntax is to use only source via a { uri, width, height } object.

<GLImage
  source="http://i.imgur.com/tCatS2c.jpg"
  resizeMode="stretch"
/>
<GLImage
  source="http://i.imgur.com/tCatS2c.jpg"
  resizeMode="contain"
/>
<GLImage
  source="http://i.imgur.com/tCatS2c.jpg"
  resizeMode="cover"
/>
<GLImage
  source="http://i.imgur.com/tCatS2c.jpg"
  resizeMode="cover"
  zoom={0.5}
/>
<GLImage
  source="http://i.imgur.com/tCatS2c.jpg"
  resizeMode="cover"
  zoom={0.44}
  center={[ 1, 0.55 ]}
/>

Web usage example

import React from "react";
import {render} from "react-dom";
import {Surface} from "gl-react-dom";
import GLImage from "gl-react-image";

render(
  <Surface width={300} height={300}>
    <GLImage
      source="http://i.imgur.com/tCatS2c.jpg"
    />
  </Surface>
  , document.body
))

React Native usage example

import React from "react";
import {Image, View} from "react-native";
import {Surface} from "gl-react-dom";
import GLImage from "gl-react-image";

export default class Example extends Component {
  static propTypes = {
    src: PropTypes.string.isRequired,
  };
  render () {
    return (
      <Surface style={{ width: 300, height: 300 }}>
        <GLImage
          source={src}
        />
      </Surface>
    );
  }
}

gl-react-image's People

Contributors

gre avatar

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.