|
1 | 1 | # react-native-img-buffer-save |
2 | 2 |
|
3 | | -react native img buffer save |
| 3 | +A fast and lightweight React Native library built with JSI that allows you to save images directly to the device's gallery. Supports saving images from `Uint8Array` or `ArrayBuffer` buffers. |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
7 | | -```sh |
| 7 | +### Using Yarn |
| 8 | + |
| 9 | +```bash |
| 10 | +yarn add react-native-img-buffer-save |
| 11 | +``` |
| 12 | + |
| 13 | +### Using NPM |
| 14 | + |
| 15 | +```bash |
8 | 16 | npm install react-native-img-buffer-save |
9 | 17 | ``` |
10 | 18 |
|
11 | | -## Usage |
| 19 | +### iOS Specific |
| 20 | + |
| 21 | +After installation, don't forget to install CocoaPods dependencies: |
12 | 22 |
|
| 23 | +```bash |
| 24 | +cd ios && pod install |
| 25 | +``` |
13 | 26 |
|
14 | | -```js |
15 | | -import { multiply } from 'react-native-img-buffer-save'; |
| 27 | +## Usage Example |
16 | 28 |
|
17 | | -// ... |
| 29 | +```tsx |
| 30 | +import { View, Text, TouchableOpacity, StyleSheet } from 'react-native'; |
| 31 | +import { saveImageToGallery } from 'react-native-img-buffer-save'; |
18 | 32 |
|
19 | | -const result = multiply(3, 7); |
| 33 | +export default function App() { |
| 34 | + const saveImg = () => { |
| 35 | + const imgBytes = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); // some image; |
| 36 | + |
| 37 | + saveImageToGallery(img); // Accepts Uint8Array |
| 38 | + // or |
| 39 | + saveImageToGallery(img.buffer); // Accepts ArrayBuffer |
| 40 | + }; |
| 41 | + |
| 42 | + return ( |
| 43 | + <View style={styles.container}> |
| 44 | + <TouchableOpacity onPress={saveImg}> |
| 45 | + <Text>Save IMG to gallery</Text> |
| 46 | + </TouchableOpacity> |
| 47 | + </View> |
| 48 | + ); |
| 49 | +} |
| 50 | + |
| 51 | +const styles = StyleSheet.create({ |
| 52 | + container: { |
| 53 | + flex: 1, |
| 54 | + justifyContent: 'center', |
| 55 | + alignItems: 'center', |
| 56 | + }, |
| 57 | +}); |
20 | 58 | ``` |
21 | 59 |
|
| 60 | +## Notes |
| 61 | +- The library leverages JSI for high performance and low overhead. |
| 62 | +- Supports saving images from both `Uint8Array` and `ArrayBuffer`. |
| 63 | +- Currently works with both Android and iOS platforms. |
| 64 | + |
| 65 | +--- |
22 | 66 |
|
23 | | -## Contributing |
| 67 | +Feel free to open issues or contribute! |
24 | 68 |
|
25 | | -See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. |
26 | 69 |
|
27 | 70 | ## License |
28 | 71 |
|
|
0 commit comments