sksamuel / scrimage

JVM - Java, Kotlin, Scala image processing library
https://sksamuel.github.io/scrimage
Apache License 2.0
1.08k stars 140 forks source link

strange error in some cases #293

Open zoff99 opened 5 months ago

zoff99 commented 5 months ago

something broke, i am not sure what

shrink_image_file:compressToFile:EE003:Image parsing failed for PNG. If the format is `webp` ensure you have a webp reader on your classpath, such as the `scrimage-webp` module. Tried the following ImageReader implementations:
com.sksamuel.scrimage.webp.WebpImageReader@37cc846a failed due to java.io.IOException: [Decoding of /tmp/input16582128566075645218webp failed., Status: 3(BITSTREAM_ERROR)]
com.sksamuel.scrimage.ImageParseException: Image parsing failed for PNG. If the format is `webp` ensure you have a webp reader on your classpath, such as the `scrimage-webp` module. Tried the following ImageReader implementations:
com.sksamuel.scrimage.webp.WebpImageReader@37cc846a failed due to java.io.IOException: [Decoding of /tmp/input16582128566075645218webp failed., Status: 3(BITSTREAM_ERROR)]
    at com.sksamuel.scrimage.nio.ImageReaders.read(ImageReaders.java:66)
    at com.sksamuel.scrimage.nio.ImageReaders.read(ImageReaders.java:37)
    at com.sksamuel.scrimage.nio.ImmutableImageLoader.load(ImmutableImageLoader.java:139)
    at com.sksamuel.scrimage.nio.ImmutableImageLoader.fromFile(ImmutableImageLoader.java:106)
    at com.zoffcc.applications.trifa.HelperGeneric.shrink_image_file(HelperGeneric.kt:366)
    at com.zoffcc.applications.trifa.MainActivity$Companion.add_ngc_outgoing_file(MainActivity.kt:3788)
    at ChatAppKt$GroupApp$1$1.invoke$lambda$24$lambda$23$lambda$11$lambda$10(ChatApp.kt:467)
    at androidx.compose.ui.AwtWindowDropTarget$dragTargetListener$4.invoke(ExternalDrag.desktop.kt:243)
    at androidx.compose.ui.AwtWindowDropTarget$dragTargetListener$4.invoke(ExternalDrag.desktop.kt:233)
    at androidx.compose.ui.AwtWindowDragTargetListener.drop(ExternalDrag.desktop.kt:450)
    at java.desktop/java.awt.dnd.DropTarget.drop(DropTarget.java:455)
    at java.desktop/sun.awt.dnd.SunDropTargetContextPeer.processDropMessage(SunDropTargetContextPeer.java:548)
    at java.desktop/sun.awt.X11.XDropTargetContextPeer.processDropMessage(XDropTargetContextPeer.java:185)
    at java.desktop/sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchDropEvent(SunDropTargetContextPeer.java:864)
    at java.desktop/sun.awt.dnd.SunDropTargetContextPeer$EventDispatcher.dispatchEvent(SunDropTargetContextPeer.java:788)
    at java.desktop/sun.awt.dnd.SunDropTargetEvent.dispatch(SunDropTargetEvent.java:48)
    at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4861)
    at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2324)
    at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2780)
    at java.desktop/java.awt.Component.dispatchEvent(Component.java:4828)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:775)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:720)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:714)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:98)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:747)
    at java.desktop/java.awt.EventQueue$5.run(EventQueue.java:745)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:744)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
sksamuel commented 3 months ago

Do you have the source image?

zoff99 commented 3 months ago

its not the image, for some reason when i run that multiplatform app via "./gradlew run" it works and when i package it it also works. but when i run the java commandline freehand it produces this error. i don't know really where to begin looking

sonianvs commented 2 months ago

Hi there,

I've a similar issue after adding the scrimage-webp module to our dependencies, which starts to be frustrating as I can't find the origin, but I'll explain what I've found in case it helps (and you can help me, 🙏🏻 ):

Before: We had both scrimage-core and scrimage-formats-extra dependencies and we are loading images with the following line of code: ImmutableImage.loader.fromStream(is). To put you more in context, I'm using Scala language and I run it locally with sbt, but I package it to a jar to deploy the code in an AWS lambda.

Change made: We wanted to add the scrimage-webp dependency so we could support that kind of image files. So I added that module to the dependencies.

After:

I have 2 different behaviours:

1. If I add the scrimage-webp dependency on top of the list (before the other two mentioned above):

I can upload webp image files and it runs successfully but then I have the error with jpg files:

Captura de pantalla 2024-09-16 a les 13 43 57

2. If I add the scrimage-webp dependency at the bottom of the list (after the other two mentioned above):

I can upload any kind of image files and it runs successfully but then I have the error with webp files (as before adding the webp module):

Captura de pantalla 2024-09-16 a les 13 54 39

It looks like a dependency issue, but I can't find the origin. For more details: I'm using the latest versions for the scrimage dependencies (4.2.0) and the runtime is Java 11.

Any ideas?

zoff99 commented 1 week ago

@sksamuel can we debug this together please? this would be really great. i am pretty sure its a path thats set wrong under some conditions.

zoff99 commented 1 week ago

i have made a minimal KMP example to show the issue. can you check it out please?

git clone https://github.com/zoff99/testbed_debug
TERM=dumb ./gradlew run
# input file exists?: true <-- it logs that the input file exists
# CTRL-C

it will happily use build/compose/tmp/prepareAppResources/background.jpg and create /tmp/aa.webp

now when you package it and run it with java

./manual_run.sh build
# input file exists?: true <-- it logs that the input file exists

you can see it has the exception. but i can not figure out why it happens. the resouces path and the input file are there. can you please have a look?

input file exists?: true
output file: /tmp/aa.webp
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
com.sksamuel.scrimage.ImageParseException: Image parsing failed for JPEG. If the format is `webp` ensure you have a webp reader on your classpath, such as the `scrimage-webp` module. Tried the following ImageReader implementations:
com.sksamuel.scrimage.webp.WebpImageReader@3ad86bad failed due to java.io.IOException: [Decoding of /tmp/input71681690817620127webp failed., Status: 3(BITSTREAM_ERROR)]
    at com.sksamuel.scrimage.nio.ImageReaders.read(ImageReaders.java:66)
    at com.sksamuel.scrimage.nio.ImageReaders.read(ImageReaders.java:37)
    at com.sksamuel.scrimage.nio.ImmutableImageLoader.load(ImmutableImageLoader.java:139)
    at com.sksamuel.scrimage.nio.ImmutableImageLoader.fromFile(ImmutableImageLoader.java:106)
    at MainKt.shrink_image_file(Main.kt:71)

thank you.

zoff99 commented 1 day ago

@sksamuel hope you are still around