Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image directory problem for imageAsset() #23

Closed
kamal-hossain opened this issue Oct 12, 2021 · 36 comments
Closed

Image directory problem for imageAsset() #23

kamal-hossain opened this issue Oct 12, 2021 · 36 comments

Comments

@kamal-hossain
Copy link
Contributor

I'm trying to print image from my android device.

In this doc it is instructed to store image on this path android/app/src/main/assets. So I have used expo MediaLibrary for download and store the image on android/app/src/main/assets path.

My actual image path is file:///storage/emulated/0/android/app/src/main/assets/1634020369600.png

And I am calling the the print function like that.

printing.initialize().imageAsset('634020369600.png', 200);

This is the error that I am getting:

{
"nativeStackAndroid":[],
"userInfo":null,
"message":"1634020369600.png",
"code":"EUNSPECIFIED",
"line":2760,"
column":45,
"sourceURL":"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false"
}

It will be very much helpful if anyone can solve what I am missing.

@kamal-hossain kamal-hossain changed the title Image directory problem for **imageAsset()** Image directory problem for imageAsset() Oct 12, 2021
@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain hello!
ImageAsset method prints images only from the assests directory. It means you have to put it in manually into android/app/src/main/assets. The path you've got after the download is "files directoty" path, so to make it work we need to add a corresponding method like imageStorage.

Am I write that you are using an expo project?

@kamal-hossain
Copy link
Contributor Author

kamal-hossain commented Oct 12, 2021

@tr3v3r thanks for your quick response.
I have ejected from expo, now I am using pure React Native. I am using expo packages just by the help of unimodules

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

So as I understood you need to print a remote images?

@kamal-hossain
Copy link
Contributor Author

I am unsure how can I use the imageStorage method. Can you please help forward on that?

@kamal-hossain
Copy link
Contributor Author

kamal-hossain commented Oct 12, 2021

Yes I need to print a remote image, but I have found that this package doesn't support remote image print, thats why I am trying to download and print the image.

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain I'm already working on the imageBase64 image method (which is also could help ).
I'll try today also to make PoC regarding remote images and images from file storage.

I'll let you know about the results )

@kamal-hossain
Copy link
Contributor Author

Yes, imageBase64 can also help me for now.
So, I will surely try to look on your solution in remote images.
Can you give me any solution for now, just to at least temporarily fix the issue for printing.

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain yeap give me a couple of hours to test methods for base64.
They've already done but not tested on real device

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain I need your help.
I don't have an android device now and can't verify that the corresponding method works.
I'm going to push the branch with the updates now, so could you please clone the repo switch to this branch and test whether the method works or not?

Everything you need to do is just run project from example folder and press on two buttons
discover -> test print chaninig

image

@kamal-hossain
Copy link
Contributor Author

Sure thing, give me some times. I am on it.

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain thanks!
branch - imageBase64-method

@kamal-hossain
Copy link
Contributor Author

kamal-hossain commented Oct 12, 2021

image

I am trying yarn install but why it is not working? any idea?
Which command I should use to install packages?

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain have you run it inside example folder?
cd example -> yarn -> yarn android

@kamal-hossain
Copy link
Contributor Author

kamal-hossain commented Oct 12, 2021

Yes I did, the yarn command is not working at all.

image

There is no problem with my yarn. yarn working fine in my other projects.

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

That strange - just checked
image

@kamal-hossain
Copy link
Contributor Author

What is your yarn version? This is mine:

image

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

I don't think it connected with yarn ver. (btw mine is 1.22.11)
Could you try to do it with npm?

@kamal-hossain
Copy link
Contributor Author

Ok sure I am trying with npm.

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

Habe you tried to use bash or zsh terminal instead of shall?
image

@kamal-hossain
Copy link
Contributor Author

I have tried with cmd and bash.

@kamal-hossain
Copy link
Contributor Author

sorry I accidentally, closed the issue.

@kamal-hossain kamal-hossain reopened this Oct 12, 2021
@kamal-hossain
Copy link
Contributor Author

Can you tell me what changes you have made for base64 printing in your current published?
Then I can do it on my project directly without example project, due to yarn issue.

And I have tried with npm, it doesn't work.

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain you can simply use the link to branch version directly in package.json of your project like
// package.json

"dependencies': {
...
 "react-native-esc-pos-printer": "git://github.com/tr3v3r/react-native-esc-pos-printer.git#imageBase64-method"
...
}

And then just use

  .imageBase64(base64Image, 75)

@kamal-hossain
Copy link
Contributor Author

I have changed package.json file and called this.
The weird thing is the function is not printing the base64 image, and neither its showing any error in catch block.

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain Understood.
Could you please try to print this image
like so .imageBase64(base64Image, 75)

And also it would be nice if you could check that all needed updates included in you node_modules/react-native-esc-pos-printer lib.

Check please if android/src/main/java/com/reactnativeescposprinter/EscPosPrinterModule.java includes this code

 case PrintingCommands.COMMAND_ADD_IMAGE_BASE_64:
        String uriString = params.getString(0);
        final String pureBase64Encoded = uriString.substring(uriString.indexOf(",") + 1);
        byte[] decodedString = Base64.decode(pureBase64Encoded, Base64.DEFAULT);
        Bitmap bitmap = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        int inputWidth = params.getInt(1);

        handlePrintImage(bitmap, inputWidth);
        break;

Also could you please share the image you've tried to print?
Thanks

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain just found a real device - print image from base64 works as expected with the asset from this link

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

Have you tried to play with the width?

@kamal-hossain
Copy link
Contributor Author

Yes I did! And it is working totally fine! I have printed the actual size. Thanks alot!

So, now I have to convert all the images to base64, do you know any react native package for converting images to base64? Otherwise I will have to convert them from backend and get them, which is a lengthy process.

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

actually, rn-fetch-blob for example allows you to download an image and save it as base64. I suppose the manager you are using also could provide such functionality.

Anyway I'll try tomorrow investigate a bit about printing from remote url

@kamal-hossain
Copy link
Contributor Author

kamal-hossain commented Oct 12, 2021

Thanks @tr3v3r this will be very much helpful, and I think this is a very important feature.
Will you publish the base64 update on npm? Or we should use this:

"dependencies: {
...
 "react-native-esc-pos-printer": "git://github.com/tr3v3r/react-native-esc-pos-printer.git#imageBase64-method"
...
}

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain Thanks to you too for the help!
Just released a new version to npm.
https://www.npmjs.com/package/react-native-esc-pos-printer

docs also updated
https://github.com/tr3v3r/react-native-esc-pos-printer/blob/main/docs/PRINTING.md#base64-image

@kamal-hossain
Copy link
Contributor Author

Unpacked Size is 150 MB in npm. Will the effect the real app size at play store?

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 12, 2021

@kamal-hossain no final app size will be fine) we’ve already used it in production for iOS and Android

@kamal-hossain
Copy link
Contributor Author

@tr3v3r
Have you done anything for Remote image?

@tr3v3r
Copy link
Owner

tr3v3r commented Oct 29, 2021

@kamal-hossain hi!
Just released a new version (1.4.0) with support printing remote images and from a local sources.
Check the docs here

printing.initialize()
    .image(require('./store.png'), {
        width: 75,
        halftone: 'EPOS2_HALFTONE_THRESHOLD',
      })
    .image({ uri: base64Image }, { width: 75 })
    .image(
      {
        uri:
          'https://raw.githubusercontent.com/tr3v3r/react-native-esc-pos-printer/main/ios/store.png',
      },
      { width: 75 }
    )
    .cut()
    .send();

@tr3v3r tr3v3r closed this as completed Oct 29, 2021
@kamal-hossain
Copy link
Contributor Author

@tr3v3r
Thank you very much this is a very useful feature. I will check this out soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants