react-native-image-resizer
react-native-image-resizer copied to clipboard
Output base 64
Hi guys,
Can we output image as base64
thanks,
also input from base64 would be super nice.
@baskan Input from base64 already works.
Any ideas if base64 output is possible, still?
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
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.
Any progress assumptions on this enchancement, perhaps?
I'm not actively needing this feature so not working on this. Happy to accept PR for this though :)
damn it, i only started playing with this project because I misread the docs and thought this was implemented :(
@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" ?
@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?
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.
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.
Yes, I think it's perfectly ok to do this change only on the JavaScript interface :)
if someone can do the same for iOS that would be good!
@4ian any plans to integrate this PR and/or implement the iOS side?
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.
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 Contact me if you are still interested in the implementation.
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;
}
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.
This issue has been automatically closed. Thank you for your contributions.