MolotovCherry / kmagick

Kotlin ImageMagick bindings to the MagickWand API
MIT License
40 stars 5 forks source link

The `MagickWand.annotateImage` is throwing an exception #1

Closed carloseustaquio closed 2 years ago

carloseustaquio commented 2 years ago

The method is throwing an error by just trying to use it..

E/AndroidRuntime: FATAL EXCEPTION: Thread-4
    Process: com.example.youtubemusicshare, PID: 14748
    com.cherryleafroad.kmagick.MagickWandException: `MagickWand::annotateImage()` threw an exception : unable to annotate image
        at com.cherryleafroad.kmagick.MagickWand.annotateImage(Native Method)
        at com.example.youtubemusicshare.MainActivity.createPostImage(MainActivity.kt:107)
        at com.example.youtubemusicshare.MainActivity.handleGetPostData$lambda-0(MainActivity.kt:69)
        at com.example.youtubemusicshare.MainActivity.$r8$lambda$TQdY_LSuJYvORw4FAJGdesrt8A8(Unknown Source:0)
        at com.example.youtubemusicshare.MainActivity$$ExternalSyntheticLambda0.run(Unknown Source:4)
        at java.lang.Thread.run(Thread.java:920)
I/Process: Sending signal. PID: 14748 SIG: 9

I'm trying to use the exact same code of the example https://github.com/cherryleafroad/kmagick/blob/main/example/src/com/example/cli/Main.kt

        Magick.initialize().use {
            Log.i(TAG, "magick initialized")
            val wand = MagickWand()

            val pw = PixelWand()
            pw.color = "#ff0000"
            wand.newImage(500, 500, pw)

            val dwand = DrawingWand()
            dwand.fontSize = 40.0
            dwand.font = "Times New Roman"

            val colorWand = PixelWand()
            colorWand.color = "black"
            dwand.fillColor = colorWand
            wand.annotateImage(DrawingWand(), 1.0,50.0, 1.0, "Sometext")
        }
MolotovCherry commented 2 years ago

Judging by the function in the underlying API bindings, this isn't a fault in my library. What happened is that imagemagick itself is throwing you the error for some reason (who knows).

Can you please run MagickWand.getException() to find out what it is? You'll get back a nice data class with an exception type and message. You can look up the code in ExceptionType to see which one it is and how to solve it.

I'll add some documentation on the main page to make it clear how to retrieve exception details.

P.S. Your last line:

wand.annotateImage(DrawingWand(), 1.0,50.0, 1.0, "Sometext")

Shouldn't that be?

wand.annotateImage(dwand, 1.0,50.0, 1.0, "Sometext")
MolotovCherry commented 2 years ago

Any update? I'm curious how it went for you.

I'm going to close this for now since from my end it looks resolved (and no reply as of yet). Feel free to still reply to this issue with any thoughts, questions, or problems. If needed, we can re-open it.

MolotovCherry commented 2 years ago

Just want to update you. The reason it fails is because the font isn't available. (The Exception message I showed above will tell you that as well)

carloseustaquio commented 2 years ago

Hey @cherryleafroad, thank you so much for the support! I did a workaround using the native Android Canvas, and it worked well... The project where I`m using this lib is paused right now, but I'll probably be trying the solution you proposed in the future.

MolotovCherry commented 2 years ago

I've updated a lot of the examples and instructions to make it clearer how to handle and check the errors when they do occur. That should help you in the future :)