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

@chouicgames/react-native-images-to-native-images

v1.0.4

Published

Convert svg file to png/jpg/pdf/vector drawable

Downloads

12

Readme

react-native-images-to-native-images

Introduction

This react-native module will help you to convert your images to Png/Jpg/VectorDrawable (for Android)/Pdf (for iOS) in every scale.

Your images must be in svg type if you want to convert them in Png/VectorDrawable/Pdf. If you want to convert in Jpg, your images must be a Jpg (this module will just resize your image for every scale)

To show Vectors Drawables, the module need : @klarna/react-native-vector-drawable in your project dependencies, that's why we will ask you to install with our module. More information on this module here : https://github.com/klarna-incubator/react-native-vector-drawable

Installation

run this command with yarn :

yarn add @chouicgames/react-native-images-to-native-images @klarna/react-native-vector-drawable

init the images folder

Make sure there is not already an 'images' folder in your project root

in your project root run :

yarn generate-images-init

image

This will create a new folder 'images' in your root project, which contains 'Images.ts', 'ImagesTypes.ts' and 5 images, that serve as an example (you can delete them if you don't want the module to convert them into your project images).

Set up

You can look Example/ to try the set-up and usage example.

Open images/Images.ts and change the value of the const "appName" to your app name (we need the name of the folder in YourProject/ios/YourAppName)

export const appName: string = "YourAppName" // <------ change to your app name (in YourProject/ios/YourAppName)

Now you can import your Svg/Jpg images in the folder 'images'.

WARNING : Your images names must be in lower case, without spaces, and without '-'. Only "_" are accepted. You can add numbers.

For example, this name is right : 'my_cool_image12.svg' But this name isn't right : 'My-cool image 12.svg'

If you want to convert in Jpg, your images must be a Jpg (This module will just resize your image for every scale)

For every image in the folder, you have to add the name of 'ImagesTypes.ts' > enum Files. You can replace the default values of default images.

export enum Files {
  // NAMES OF YOUR IMAGES HERE

  // Follow this example :

  IMG0,
  IMG1,
  IMG2,
  IMG3,
  IMG4
}

Then, in 'Images.ts' > Images, add your images informations, by first adding the key of your images : [Files.nameYouAddInImagesTypes.ts] : {}, then adding the differents informations needed :

  • path : "./image_name.svg"
  • source : {uri: "image_name_generated"}
  • android {type: AndroidFileType.Jpg or Png or Vector, width & height if it's Png or Jpg}
  • ios : {type: IosFileType.Jpg or Png or Pdf, width & height if it's Png or Jpg}

height can be of the value "auto".

For PNG on iOS only

  • You can add values for IPad : widthIpad: number, heightIpad: number or "auto".
  • You can also add pathIpad: string, that will generate a different image for IPad only.

Here you choose what type of image your image will be converted to for Android and iOS, so you can convert one image into Png for Android and into Pdf for iOS for example.

export const appName: string = "YourAppName" // <------ change to your app name (in YourProject/ios/YourAppName)

export const Images: FilesInfos = {
  //YOUR IMAGES HERE !

  // Follow this example :

  [Files.IMG0]: {
    path: "./img0.jpg",
    source: { uri: "img0" },
    android: { type: AndroidFileType.Jpeg, width: 200, height: 200 },
    ios: { type: IosFileType.Jpeg, width: 300, height: 300 },
  },
  [Files.IMG1]: {
    path: "./img1.svg",
    source: { uri: "img1" },
    android: { type: AndroidFileType.Vector },
    ios: { type: IosFileType.Pdf },
  },
  [Files.IMG2]: {
    path: "./img2.svg",
    source: { uri: "img2" },
    android: { type: AndroidFileType.Png, width: 500, height: 500 },
    ios: { type: IosFileType.Png, width: 450, height: 450 },
  },
  [Files.IMG3]: {
    path: "./img3.svg",
    source: { uri: "img3" },
    android: { type: AndroidFileType.Png, width: 450, height: "auto" },
    ios: {
      type: IosFileType.Png,
      width: 375,
      height: 375,
      widthIPad: 250,
      heightIPad: 250,
    },
  },
  [Files.IMG4]: {
    path: "./img4.svg",
    source: { uri: "img4" },
    android: { type: AndroidFileType.Png, width: 375, height: 375 },
    ios: {
      type: IosFileType.Png,
      width: 375,
      height: 375,
      widthIPad: 400,
      heightIPad: "auto",
      pathIpad: "./img3.svg",
    },
  },
}

You can now run :

yarn generate-images

And the module will convert all your images in the right type, in every scale !

Usage

import React from "react"
import { ScrollView, View } from "react-native"

import { NativeImage } from "@chouicgames/react-native-images-to-native-images"
import Images, { Files } from "./images/Images"

const App = () => {
  const imagesSize = {
    width: "100%",
    height: 200,
    borderColor: "black",
    borderWidth: 4,
  }

  return (
    <ScrollView>
      <View>
        <NativeImage file={Images[Files.IMG0]} style={imagesSize} />
        <View style={{ borderColor: "black", borderWidth: 4 }}>
          <NativeImage file={Images[Files.IMG1]} style={imagesSize} />
        </View>
        <NativeImage file={Images[Files.IMG2]} style={imagesSize} />
        <NativeImage file={Images[Files.IMG3]} style={imagesSize} />
        <NativeImage file={Images[Files.IMG4]} style={imagesSize} />
      </View>
    </ScrollView>
  )
}

export default App

In this example, IMG1 is a Vector Drawable, which doesn't support border props. More informations for Vector Drawable here : https://github.com/klarna-incubator/react-native-vector-drawable

Props

| Prop | Description | Default | | ------------------ | -------------------------------------------------------- | ------- | | file | Name of your image in 'images/types.ts'. follow this example : Files.YourImage | None | | style | Support style like a normal image in react-native. Add width and height if your image is a Pdf/Vector Drawable or it won't show in your application. | width & height for Png/Jpg call in images/Images.ts |

AnimatedNativeImage

You can also use AnimatedNativeImage, it work exactly like Animated.Image.

import AnimatedNativeImages from "@chouicgames/react-native-images-to-native-images/src/AnimatedNativeImage"

<AnimatedNativeImages file={Images[Files.IMG4]} style={styles.image} />