Skip to content

Commit

Permalink
fix: no gif encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
LaoLittle committed Jul 4, 2022
1 parent bb3d5e5 commit 01e4331
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/main/kotlin/General.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import net.mamoe.mirai.message.data.MessageSource.Key.quote
import net.mamoe.mirai.message.nextMessageOrNull
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
import org.jetbrains.skia.*
import org.laolittle.plugin.gif.GifLibrary
import java.nio.file.Path
import kotlin.io.path.readBytes
import org.jetbrains.skia.Image as SkImage
Expand Down Expand Up @@ -102,4 +103,13 @@ fun Canvas.drawImageRectLinear(image: SkImage, dst: Rect, paint: Paint?) =

fun Canvas.drawImageRectLinear(image: SkImage, dst: Rect) = drawImageRectLinear(image, dst, null)

suspend fun Image.getBytes(): ByteArray = httpClient.get(queryUrl())
suspend fun Image.getBytes(): ByteArray = httpClient.get(queryUrl())

val gifSupported by lazy {
try {
GifLibrary.load()
true
} catch (e: UnsatisfiedLinkError) {
false
}
}
3 changes: 2 additions & 1 deletion src/main/kotlin/meme/BlackWhite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.jetbrains.skia.*
import org.laolittle.plugin.Fonts
import org.laolittle.plugin.bytes
import org.laolittle.plugin.draw.DrawMeme
import org.laolittle.plugin.draw.gifSupported
import org.laolittle.plugin.gif.GifEncoder
import org.laolittle.plugin.gif.GifSetting
import org.laolittle.plugin.usedBy
Expand Down Expand Up @@ -117,7 +118,7 @@ suspend fun blackWhite(text: String, image: ByteArray, _filter: String): ByteArr
}

codec.use {
return if (codec.encodedImageFormat == EncodedImageFormat.GIF) {
return if (gifSupported && codec.encodedImageFormat == EncodedImageFormat.GIF) {
val bitmaps = Array(codec.frameCount) {
//DrawMeme.async { // multi-thread will make jvm crash
Bitmap().apply {
Expand Down

0 comments on commit 01e4331

Please sign in to comment.