From 9b8b188fc0f3c89d6ea4b9d36edd25af3710fad1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michae=CC=88l=20Villeneuve?= Date: Thu, 25 Jan 2018 09:12:45 +0100 Subject: [PATCH] Switching Android img format from PNG to JPEG --- README.md | 10 +++++----- .../java/com/reactlibrary/RNImgToBase64Module.java | 2 +- package.json | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 16a08fb..58aec19 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# react-native-convert-image-to-base64 +# react-native-image-base64 This repo is a working rewrite of [this](https://github.com/xfumihiro/react-native-image-to-base64) abandonned library. It provides a very simple way to convert an image to a base64 string. @@ -9,18 +9,18 @@ Indeed working with big images on Android might cause very high memory usage. ## Getting started -`npm install react-native-convert-image-to-base64 --save` +`npm install react-native-image-base64 --save` or -`yarn add react-native-convert-image-to-base64` +`yarn add react-native-image-base64` ## Installation -`$ react-native link react-native-convert-image-to-base64` +`$ react-native link react-native-image-base64` ## Usage ```javascript -import ImgToBase64 from 'react-native-convert-image-to-base64'; +import ImgToBase64 from 'react-native-image-base64'; ImgToBase64.getBase64String('file://youfileurl', (err, base64string) => doSomethingWith(base64string)); ``` diff --git a/android/src/main/java/com/reactlibrary/RNImgToBase64Module.java b/android/src/main/java/com/reactlibrary/RNImgToBase64Module.java index c58c80d..7a7b8b7 100644 --- a/android/src/main/java/com/reactlibrary/RNImgToBase64Module.java +++ b/android/src/main/java/com/reactlibrary/RNImgToBase64Module.java @@ -46,7 +46,7 @@ public void getBase64String(String uri, Callback callback) { private String bitmapToBase64(Bitmap bitmap) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); + bitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); return Base64.encodeToString(byteArray, Base64.DEFAULT); } diff --git a/package.json b/package.json index 72a17ab..b73ef48 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "react-native-convert-image-to-base64", - "version": "0.1.0", + "name": "react-native-image-base64", + "version": "0.1.1", "description": "Convert image to base64", "main": "index.js", "scripts": {