WebP画像をレンダリングする
-
21-12-2019 - |
質問
PNGを表すBYTEARRAYを持っていますが、これをWebPに変換したいです。次のコードがあります。私のコードでcom.sksamuel.scrimage.imageを使用して、システムライブラリーのwebp_jniをロードします。
val image = Image(content) //content of PNG of type Array[Byte]
extension match {
case "webp" => Ok(
libwebp.WebPEncodeRGB(
image.write,
image.width,
image.height,
image.width * 3,
80F)
).as("image/webp")
case _ => Ok(image.write).as("image/png")
}
.
PNGイメージをリクエストした場合、すべてがうまく機能しますが、WebPイメージを要求するときは次のようになります。
# SIGSEGV (0xb) at pc=0x00007fc008287377, pid=14883, tid=140461610465024
#
# JRE version: Java(TM) SE Runtime Environment (8.0_05-b13) (build 1.8.0_05-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.5-b02 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C [libwebp.so.5+0x33377] WebPPictureAlloc+0x407
.
私はストライド入力image.width、image.widthの他の値を試しました。オリジナルのようなものは何もない。
解決
プロジェクトを webp-amageio ライブラリを使用するように切り替えました。次のような方法。
val image = Image(content) //content of PNG of type Array[Byte]
extension match {
case "webp" => {
val out = new ByteArrayOutputStream()
ImageIO.write(resizedImage.awt, "webp", out)
Ok(out.toByteArray).as("image/webp")
case _ => Ok(image.write).as("image/png")
}
. 所属していません StackOverflow