npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@pontusab/react-native-image-manipulator

v1.0.6

Published

An API to modify images stored in app scope.

Downloads

33

Readme

An API to modify images stored on the local file system.

Installation

  1. yarn add https://github.com/pontusab/react-native-image-manipulator
  2. pod 'react-native-image-manipulator', :path => './node_modules/react-native-image-manipulator/ios'
  3. pod install

API

import * as ImageManipulator from 'react-native-image-manipulator';

ImageManipulator.manipulateAsync(uri, actions, saveOptions)

Manipulate the image provided via uri. Available modifications are rotating, flipping (mirroring), resizing and cropping. Each invocation results in a new file. With one invocation you can provide a set of actions to perform over the image. Overwriting the source file would not have an effect in displaying the result as images are cached.

Arguments

  • uri (string) -- URI of the file to manipulate. Should be on the local file system.

  • actions (array) --

    An array of objects representing manipulation options. Each object should have only one of the following keys that corresponds to specific transformation:

    • resize (object) -- An object of shape { width, height }. Values correspond to the result image dimensions. If you specify only one value, the other will be calculated automatically to preserve image ratio.
    • rotate (number) -- Degrees to rotate the image. Rotation is clockwise when the value is positive and counter-clockwise when negative.
    • flip (string) -- ImageManipulator.FlipType.{Vertical, Horizontal}. Only one flip per transformation is available. If you want to flip according to both axes then provide two separate transformations.
    • crop (object) -- An object of shape { originX, originY, width, height }. Fields specify top-left corner and dimensions of a crop rectangle.
  • saveOptions (object) -- A map defining how modified image should be saved:

    • compress (number) -- A value in range 0.0 - 1.0 specifying compression level of the result image. 1 means no compression (highest quality) and 0 the highest compression (lowest quality).
    • format (string) -- ImageManipulator.SaveFormat.{JPEG, PNG}. Specifies what type of compression should be used and what is the result file extension. SaveFormat.PNG compression is lossless but slower, SaveFormat.JPEG is faster but the image has visible artifacts. Defaults to SaveFormat.JPEG.
    • base64 (boolean) -- Whether to also include the image data in Base64 format.

Returns

Returns { uri, width, height } where uri is a URI to the modified image (useable as the source for an Image/Video element), width, height specify the dimensions of the image. It can contain also base64 - it is included if the base64 saveOption was truthy, and is a string containing the JPEG/PNG (depending on format) data of the image in Base64--prepend that with 'data:image/xxx;base64,' to get a data URI, which you can use as the source for an Image element for example (where xxx is 'jpeg' or 'png').

Basic Example

This will first rotate the image 90 degrees clockwise, then flip the rotated image vertically and save it as a PNG.

import React from 'react';
import { Button, View, Image } from 'react-native';
import { Asset } from 'expo-asset';
import * as ImageManipulator from 'react-native-image-manipulator';

export default class ImageManipulatorSample extends React.Component {
  state = {
    ready: false,
    image: null,
  };

  componentDidMount() {
    (async () => {
      const image = Asset.fromModule(require('./assets/snack-icon.png'));
      await image.downloadAsync();
      this.setState({
        ready: true,
        image,
      });
    })();
  }

  render() {
    return (
      <View style={{ flex: 1, justifyContent: 'center' }}>
        {this.state.ready && this._renderImage()}
        <Button title="Rotate and Flip" onPress={this._rotate90andFlip} />
      </View>
    );
  }

  _rotate90andFlip = async () => {
    const manipResult = await ImageManipulator.manipulateAsync(
      this.state.image.localUri || this.state.image.uri,
      [{ rotate: 90 }, { flip: ImageManipulator.FlipType.Vertical }],
      { compress: 1, format: ImageManipulator.SaveFormat.PNG }
    );
    this.setState({ image: manipResult });
  };

  _renderImage = () => {
    return (
      <View style={{ marginVertical: 20, alignItems: 'center', justifyContent: 'center' }}>
        <Image
          source={{ uri: this.state.image.localUri || this.state.image.uri }}
          style={{ width: 300, height: 300, resizeMode: 'contain' }}
        />
      </View>
    );
  };
}