react-native-image-resizer icon indicating copy to clipboard operation
react-native-image-resizer copied to clipboard

Output base 64

Open mongveasna opened this issue 8 years ago • 19 comments

Hi guys,

Can we output image as base64

thanks,

mongveasna avatar Dec 04 '17 08:12 mongveasna

also input from base64 would be super nice.

baskan avatar Mar 07 '18 13:03 baskan

@baskan Input from base64 already works.

mistenkt avatar Mar 12 '18 13:03 mistenkt

Any ideas if base64 output is possible, still?

greenais avatar Mar 21 '18 19:03 greenais

I think this feature would be essential as we need to depend on other modules like react-native-fs in order to convert to base64. But that should be provided out of the box

ghost avatar Apr 03 '18 08:04 ghost

And this (to my understanding) shouldn't be too hard to implement - as soon as we have result image object somewhere inside before dropping it to fs - just image.encode(base64) and expose result through API... I'm not native coder at all, so it's just my assumptions, but from JS side I'm ready to help/test adding this.

greenais avatar Apr 03 '18 08:04 greenais

Any progress assumptions on this enchancement, perhaps?

greenais avatar May 01 '18 15:05 greenais

I'm not actively needing this feature so not working on this. Happy to accept PR for this though :)

4ian avatar May 01 '18 15:05 4ian

damn it, i only started playing with this project because I misread the docs and thought this was implemented :(

pstanton avatar May 03 '18 04:05 pstanton

@4ian how would you like to design the API to achieve this? The implementation is not difficult on android. Just not sure what your preference is...

for input: could stuff "base64" into "outputPath" parameter, or add a new parameter ...

for output: I would include "base64" field and omit both "path" and "uri" but you could also omit "path" and return the base64 with prefix in "uri" OR omit "uri" and return base64 in "path" ?

pstanton avatar May 03 '18 04:05 pstanton

@4ian I implemented it locally (on 1.0.0) only to realise that master has some changes so i'll have to merge a bit. But ... I found it easy to implement by having ImageResizer receive the response map as a parameter and populate it directly rather than returning a File (or base64 String). This allowed me to fork logic without changing the return type AND to populate the response with more attributes (such as resultant width/height). Does this sound like a change that would accept?

pstanton avatar May 03 '18 07:05 pstanton

I would accept such a change, but I think we should transition to have as parameters an object options, so it's easier to add optional options in the future :) (instead of having this long list of parameters for which some are nullable).

This will be a breaking change but it's no problem (will just release this as version 2.0.0) and it will be much better for the future.

to populate the response with more attributes (such as resultant width/height).

No problem for doing this too.

4ian avatar May 03 '18 12:05 4ian

Ok i'll apply my modifications to a fork of master tomorrow and you can review.

Parameters as options makes sense for the javascript layer - would you continue that on in the java/ObjC world? (ie use a map) I'll not make this change since it is not required to achieve what I'm doing and impacts more of your codebase, but agree it is a good idea.

pstanton avatar May 03 '18 12:05 pstanton

Yes, I think it's perfectly ok to do this change only on the JavaScript interface :)

4ian avatar May 03 '18 12:05 4ian

if someone can do the same for iOS that would be good!

pstanton avatar May 08 '18 02:05 pstanton

@4ian any plans to integrate this PR and/or implement the iOS side?

pstanton avatar Jun 05 '18 00:06 pstanton

I'm not actively using the module right now so I don't have any plan to do it myself :/ I would like to keep feature parity between Android and IOS, so having the iOS side implemented would awesome though.

4ian avatar Jun 06 '18 08:06 4ian

if anyone would like to implement the same as my patch above for iOS we would be willing to pay for your time. contact me if interested.

pstanton avatar Jul 28 '18 04:07 pstanton

@pstanton Contact me if you are still interested in the implementation.

alexandrzavalii avatar Feb 12 '19 21:02 alexandrzavalii

As this answer points out, you can use react-native-fs to convert the outputted image to Base64.

handleBase64 = async (path) => {
  const resizedImage = await ImageResizer.createResizedImage(path, 200, 80, 'JPEG', 80, 0, RNFS.DocumentDirectoryPath);
  const base64 = await RNFS.readFile(resizedImage.uri, 'base64');
  return base64;
}

alexanderkho avatar Oct 19 '20 22:10 alexanderkho

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 01 '22 19:09 stale[bot]

This issue has been automatically closed. Thank you for your contributions.

stale[bot] avatar Sep 09 '22 04:09 stale[bot]