Pregunta

Tengo un bytearray que representa un PNG, pero quiero convertirlo en WebP.tengo el siguiente código.Hago uso de com.sksamuel.scrimage.image en mi código y cargue la biblioteca del sistema 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")
}

Si solicito la imagen PNG, todo funciona bien, pero al solicitar la imagen de WebP, obtengo lo siguiente.

#  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

Probé otros valores para la imagen de entrada de punta. Al ancho, imagen. Redondeado a los múltiplos de 4, imagen. Aunque redondeado a múltiplos de 3. En este caso, no se estrella, pero la imagen es muy ruidosa y se ve.nada como el original.

¿Fue útil?

Solución

Cambié mi proyecto para usar el webp-imageio biblioteca y pude implementarlo enla siguiente manera.

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top