Giter VIP home page Giter VIP logo

kmagick's Introduction

Hi there ๐Ÿ‘‹ I'm Cherry

I'm a software engineer who's very passionate about Rust. I have experience in systems programming, Android app development, web technologies, and some game design using Unity.

In my personal time:

  • ๐Ÿ”ญ Iโ€™m currently working on assorted projects
  • ๐Ÿ’ฌ Ask me about anything Rust
  • ๐Ÿ˜ƒ For fun, I like:
    • watching anime
    • making music (FL Studio)
    • reading about science/physics/finance stuff/manga/light novels
    • working with computer hardware
    • learning psychology/self-improvement
  • ๐Ÿ’ป For inquiries, please see below on how to contact me.

๐Ÿ”— You can view my github site/blog here

Tools / Languages

Rust Kotlin Ruby Go Python C Sharp Java HTML5 JavaScript CoffeeScript CSS3 Sass PHP SQLite MySQL MongoDB PowerShell Bash JSON Markdown

Windows Linux Windows Terminal Linux Terminal IntelliJ IDEA CLion Visual Studio Code Android Studio Android Android Room Git Subversion GitHub GitHub Actions GitHub Pages Docker JNI Unity Blender Apache NGINX Fastify Node.js jQuery AngularJS React MUI Joomla phpMyAdmin Django Qt Microsoft Office TeamViewer Discord

Contact

  • StackOverflow: Kobato
  • Discord: /molotov/cherry/ (remove all forward slashes) or join my server.
    • If I don't accept your request, you might want to contact me on server instead; I get spam requests and don't always know when a request is legitimate; even if adding me directly fails, joining and pinging me in my server always works.

GitHub Stats

MolotovCherry's stats MolotovCherry's top language stats

kmagick's People

Contributors

molotovcherry avatar web-flow avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kmagick's Issues

Fix name attribute in jmethod

How else will we rename the attribute?

Not very urgent since I'm not using it. The jni macro was made as a general jni binding lib though. It'll have to be fixed eventually

UnableToReadFont

          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)

Originally posted by @MolotovCherry in #1 (comment)

Convert image api

JPEG convert to BMP.
looking for a good image format envelope library

java.lang.UnsatisfiedLinkError: dlopen failed: library "libkmagick.so" not found

Cannot config the project, I followed all steps but I still getting this error when I try to call Magick.initialize(). It wuould be great if you can have a full example project on how to setup it. I assume I miss some configs because I have all those .so files in jniLibs folder as you described in /example folder.

java.lang.UnsatisfiedLinkError: dlopen failed: library "libkmagick.so" not found
at java.lang.Runtime.loadLibrary0(Runtime.java:1077)
at java.lang.Runtime.loadLibrary0(Runtime.java:998)
at java.lang.System.loadLibrary(System.java:1661)
at com.cherryleafroad.kmagick.Magick.(Magick.kt:15)
at com.test.snap.feature.edit_guest.view.TestActivity.testMagick(TestActivity.kt:217)
at com.test.snap.feature.edit_guest.view.TestActivity.onCreate(TestActivity.kt:43)
at android.app.Activity.performCreate(Activity.java:8290)
at android.app.Activity.performCreate(Activity.java:8270)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1329)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4085)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

[BUG] Write Images failed in some devices

When I try to convert JPG to PDF, it throws an exception in some devices

E kmagick::magick_wand: MagickWand::writeImages() threw an exception: MagickError("failed to write images")

D UnableToCreateTemporaryFile 'magick-_CwoAApjRQXS-O121m7hoaSZ8mdSsJ7y': Read-only file system @ error/blob.c/InjectImageBlob/2772

val wand = MagickWand()
wand.readImage(imagePath)
wand.transformImageColorspace(ColorspaceType.CMYKColorspace)
wand.writeImage("path/xxx.pdf")

Help! translate cmdline to kotlin api

Hi, could you please help me to translate bellow cmdline command to kotlin api?

convert ori.jpg -resize 50x100% -geometry x684 -rotate 90 tmp.rgb

below is kotlin code

val wand = MagickWand()

wand.readImage(path)

val width = wand.getImageWidth()
val height = wand.getImageHeight()
wand.resizeImage(width / 2, height, FilterType.BartlettFilter)

// missing geometry code here

val pixel = PixelWand()
pixel.color = "transparent"
wand.rotateImage(pixel, 90.00)

wand.writeImage("tmp.rgb")

I don't sure the code of resize, rotate is correct, bacause when I use Mbrush printer to print the generated tmp.rgb file, but it can't print.

please help me, thank you.

JNI DETECTED ERROR IN APPLICATION: JNI FindClass called with pending exception java.lang.NoSuchMethodError:

Sorry, I just started using your library.
Got some problems, maybe a little stupid.
After I compile it successfully, some functions can be used, and some functions cannot be used.
These are all JNI problems, I hope you can help me if you have time.

 private fun testColor() {
        if (Magick.isInitialized()) {
            val b = MagickWand()
            val path = "${this.externalCacheDir}/test.png"
            b.readImage(path)
            logD(b.getImageAlphaChannel())
            logD(b.getImagePage())
            logD(b.getImageHeight())
            logD(b.getImageResolution())
            logD(b.getImageHistogram().toString())
        }
    }
```java

```log
2022-11-03 18:22:00.406 23521-23521/com.psyduck.mosaicdemo D/TestKmagickActivity: true
2022-11-03 18:22:00.406 23521-23521/com.psyduck.mosaicdemo D/TestKmagickActivity: PageGeometry(width=372, height=368, x=0, y=0)
2022-11-03 18:22:00.406 23521-23521/com.psyduck.mosaicdemo D/TestKmagickActivity: 368
2022-11-03 18:22:00.406 23521-23521/com.psyduck.mosaicdemo D/TestKmagickActivity: Resolution(x=37.79, y=37.79)
2022-11-03 18:22:00.407 23521-23521/com.psyduck.mosaicdemo E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.psyduck.mosaicdemo, PID: 23521
    java.lang.UnsatisfiedLinkError: No implementation found for long com.cherryleafroad.kmagick.MagickWand.getImageColors() (tried Java_com_cherryleafroad_kmagick_MagickWand_getImageColors and Java_com_cherryleafroad_kmagick_MagickWand_getImageColors__)
        at com.cherryleafroad.kmagick.MagickWand.getImageColors(Native Method)
        at com.psyduck.mosaicdemo.kmagick.TestKmagickActivity.testColor(TestKmagickActivity.kt:36)
        at com.psyduck.mosaicdemo.kmagick.TestKmagickActivity.onCreate$lambda-0(TestKmagickActivity.kt:22)
        at com.psyduck.mosaicdemo.kmagick.TestKmagickActivity.$r8$lambda$FJY5eMMKHYdR18_XVPbBFDgbsD0(Unknown Source:0)
        at com.psyduck.mosaicdemo.kmagick.TestKmagickActivity$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
        at android.view.View.performClick(View.java:7506)
        at android.view.View.performClickInternal(View.java:7483)
        at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
        at android.view.View$PerformClick.run(View.java:29335)
        at android.os.Handler.handleCallback(Handler.java:942)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:201)
        at android.os.Looper.loop(Looper.java:288)
        at android.app.ActivityThread.main(ActivityThread.java:7898)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

[BUG] Library "libkmagick.so" not found

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest version
  • I checked the documentation and examples and found no answer
  • I checked that it wasn't user error; it was not an ordinary exception that I could've found out and fixed by running wand.getException()
  • I checked that this isn't an ImageMagick bug itself, and is an actual problem with the bindings
  • I checked to make sure that this issue has not already been filed
  • I'm reporting the issue to the correct repository

Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

  • Android SDK version (if using Android): Android 11.0
  • Product (Android Studio, Flutter, etc): Android Studio
  • Kotlin version: 1.6.21

A 100% working app example would be far more useful than the current sample directory which is just a repeat of the readme instructions.
I've tried changing the name and location of the jni library folder and location of the .so file (libs, jniLibs, jniLibs/arm6-v8a, res, etc...)

Screenshot 2022-05-10 220622

05/10 22:15:34: Launching 'app' on Pixel 3 API 30.
Install successfully finished in 3 s 667 ms.
$ adb shell am start -n "world.gregs.android.receipt/world.gregs.android.receipt.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Connected to process 27550 on device 'Pixel_3_API_30 [emulator-5554]'.
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/NetworkSecurityConfig: No Network Security Config specified, using platform default
D/libEGL: loaded /vendor/lib/egl/libEGL_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv1_CM_emulation.so
D/libEGL: loaded /vendor/lib/egl/libGLESv2_emulation.so
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: world.gregs.android.receipt, PID: 27550
    java.lang.UnsatisfiedLinkError: dlopen failed: library "libkmagick.so" not found
        at java.lang.Runtime.loadLibrary0(Runtime.java:1087)
        at java.lang.Runtime.loadLibrary0(Runtime.java:1008)
        at java.lang.System.loadLibrary(System.java:1664)
        at com.cherryleafroad.kmagick.Magick.<clinit>(Magick.kt:12)
        at world.gregs.android.receipt.MainActivity.onCreate(MainActivity.kt:40)
        at android.app.Activity.performCreate(Activity.java:8000)
        at android.app.Activity.performCreate(Activity.java:7984)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3422)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I/Process: Sending signal. PID: 27550 SIG: 9

App crashes on invoking 'wand.getImagePixelColor(...)'

I can import the package but when i start using its methods app just crashes.

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}


android {
    compileSdkVersion 31
    buildToolsVersion "30.0.1"

    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
    sourceSets {
        main {
                jniLibs.srcDirs = ['libs']
            }
        }
}

repositories {
    mavenCentral()
    jcenter()
    mavenLocal()

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    compile 'com.facebook.react:react-native:+'
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
    implementation 'com.orhanobut:hawk:2.0.1'
   
    implementation 'com.github.bumptech.glide:glide:4.13.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.13.0'

}
import com.cherryleafroad.kmagick.*

fun doTheMagick() {
    // close resources when finished
    Magick.initialize().use {
        val wand = MagickWand()

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

        wand.getImagePixelColor(100, 100)?.let {
            //srgb(255,0,0)
            Log.d(TAG,it.color)
        }

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

        val colorWand = PixelWand()
        colorWand.color = "black"
        dwand.fillColor = colorWand
        wand.annotateImage(dwand, 0.0,50.0, 0.0, "Some text")

        // get bytes of image, then read it back in
        val blob = wand.writeImageBlob("png")
        wand.readImageBlob(blob)
        
       // ALWAYS make sure to handle your exceptions! Something may always go wrong
        try {
            // this will obviously fail
            wand.readImage("oops!")
        } catch (e: MagickWandException) {
            // handle it here
            val exc = wand.getException()
            Lod.d(TAG,"Got a MagickWandException: ${e.message}")
            Log.d(TAG,"Extra exception details: ${exc.exceptionType}: ${exc.message}")
        }
        
        // But what if the library itself panics? (this is what we call a crash)
        // then a RuntimeException will be thrown instead
        // A RuntimeException can theoretically occur on ANY library function call
        // however the chances of that actually happening are very low
        // try {
            // pretend that the following fn exists and causes a panic, so throws a RuntimeException
            // wand.panic()
        // } catch (e: RuntimeException) {
            // Log.d(TAG,"Something bad happened: ${e.message}")
        // }

        wand.writeImage("D:/out.png")
    }
}

image

Is it possible to run kmagic in multiple coroutines?

below is my code:

coroutineScope {
    texts.forEachIndexed { index, text ->
        launch {
            withContext(Dispatcher.IO) {
                transformAndSaveToTmpRgb(context, text, index)
            }
        }
    }
}

fun String.transformAndSaveToTmpRgb(
    context: Context,
    rootPath: String,
    nameOfTmpRgb: String
) {
    // generate tmp.rgb file
    Thread {
        context.getMagick().use {
            val wand = MagickWand()
            wand.readImage(this)

            var width = wand.getImageWidth()
            val height = wand.getImageHeight()

            val scaleHeight = 684f / height
            width = ((width / 5f) * scaleHeight).toLong()
            wand.resizeImage(width, 684, FilterType.BartlettFilter)

            val pixel = PixelWand()
            pixel.color = "transparent"
            wand.rotateImage(pixel, 90.00)

            wand.writeImage(rootPath + File.separator + "tmp${nameOfTmpRgb}.rgb")
        }
    }

}

when I run above code, it will raise error, and app crash:
--> kmagick::magick_wand: Failed to get handle for MagickWand::writeImage(): Field handle is null

but when I remove launch statement, it will work.

coroutineScope {
    texts.forEachIndexed { index, text ->
        withContext(Dispatcher.IO) {
            transformAndSaveToTmpRgb(context, text, index)
        }
    }
}

it looks very weird.

The `MagickWand.annotateImage` is throwing an exception

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")
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.