imazen / imageflow

High-performance image manipulation for web servers. Includes imageflow_server, imageflow_tool, and libimageflow
https://docs.imageflow.io/
GNU Affero General Public License v3.0
4.17k stars 141 forks source link

Getting "Error 9: Wrong input color space on transform" transforming jpeg #512

Closed aheintz closed 4 years ago

aheintz commented 4 years ago

Transforming the image below returns an error (using the dotnet library), and I cannot really figure out why:

Imageflow.Bindings.ImageflowException: ImageMalformed: Error 9: Wrong input color space on transform (ObjectCreationError) at
imageflow_core/src/codecs/color_transform_cache.rs:126:197
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core/src/codecs/color_transform_cache.rs#L126
imageflow_core/src/codecs/color_transform_cache.rs:196:152
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core/src/codecs/color_transform_cache.rs#L196
imageflow_core/src/codecs/mozjpeg_decoder.rs:342:35
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core/src/codecs/mozjpeg_decoder.rs#L342
imageflow_core/src/flow/nodes/codecs_and_pointer.rs:208:65
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core/src/flow/nodes/codecs_and_pointer.rs#L208
imageflow_core/src/flow/execution_engine.rs:488:114
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core/src/flow/execution_engine.rs#L488
imageflow_core/src/context.rs:284:59
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core/src/context.rs#L284
imageflow_core/src/context_methods.rs:50:68
https://github.com/imazen/imageflow/blob/1a7e1eecd8f04cab4413b48c2bf8bd5bbf140f5d/imageflow_core/src/context_methods.rs#L50
Active node:
NodeDebugInfo {
    stable_id: 1,
    params: Json(
        Decode {
            io_id: 0,
            commands: None,
        },
    ),
    index: NodeIndex(1),
}

   at Imageflow.Bindings.JobContext.AssertReady()
   at Imageflow.Bindings.JobContext.SendJsonBytes(String method, Byte[] utf8Json)
   at Imageflow.Bindings.JobContext.Execute[T](T message)
   at Imageflow.Fluent.ImageJob.FinishAsync(JobExecutionOptions executionOptions, SecurityOptions securityOptions, CancellationToken cancellationToken)
   at Imageflow.Fluent.FinishJobBuilder.InProcessAndDisposeAsync()
   at ImageScalingService.Controllers.ImageScalingController.GetImage(Int32 clientId, String requestedImageGuid, Boolean downloadContent, ResizeInstructions resizeInstructions) in /Users/heintz/Projects/storm/ImageScalingService/ImageScalingService/src/Controllers/ImageScalingController.cs:line 450

The image: https://media.cdn.storm.io/62/fa457334-0cd4-4839-ad6d-1808f921f5e6

lilith commented 4 years ago

This looks like an sRGB image with a CMYK color profile attached. Clearly that doesn't make sense, so Imageflow throws this error.

To ignore the error, use &ignore_icc_errors=true in the command string.

aheintz commented 4 years ago

Thanks for the response. I agree that it doesn't make sense. Unfortunately, &ignore_icc_errors=true doesn't make any difference (I'm using the .net dotnet library if that makes any difference, and are indeed using the ResizerCommands method).

I resolved my problem by using ImageMagick to correct the color profile if ImageFlow fails. It doesn't seem to be a terribly uncommon problem, I'm having quite a few images with this "error".

Using ignoreicc=true works, but that doesn't feel right (emphasis on "feel", since I honestly don't know). I'm using 1.4.10-rc50 btw.

lilith commented 4 years ago

I tested ignore_icc_errors with that image and it worked. Could you share the full C# code you are using?

On Thu, Sep 17, 2020, 9:45 AM Anders Heintz notifications@github.com wrote:

Thanks for the response. I agree that it doesn't make sense. Unfortunately, &ignore_icc_errors=true doesn't make any difference (I'm using the .net dotnet library if that makes any difference, and are indeed using the ResizerCommands method).

I resolved my problem by using ImageMagick to correct the color profile if ImageFlow fails. It doesn't seem to be a terribly uncommon problem, I'm having quite a few images with this "error".

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow/issues/512#issuecomment-694323145, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH4Y5BR5TLTV4P3YEDTSGIVKNANCNFSM4ROVP7GQ .

aheintz commented 4 years ago

Thanks for your quick reply!

This is the code I'm using and generates the same stacktrace as above.

                var client = httpClientFactory.CreateClient();
                var stream = await client.GetStreamAsync("https://media.cdn.storm.io/62/fa457334-0cd4-4839-ad6d-1808f921f5e6");
                await b.Decode(stream, false)
                    .ResizerCommands("width=200&ignore_icc_errors=true")
                    .EncodeToStream(output, false, new MozJpegEncoder(90))
                    .Finish()
                    .WithSecurityOptions(new SecurityOptions
                    {
                        MaxFrameSize = new FrameSizeLimit(30000, 30000, 200),
                        MaxDecodeSize = new FrameSizeLimit(30000, 30000, 200),
                        MaxEncodeSize = new FrameSizeLimit(30000, 30000, 200)
                    })
                    .InProcessAndDisposeAsync();
lilith commented 4 years ago

Use b.BuildCommandString instead. You're decoding the image before applying the ignore_icc_errors command.

On Thu, Sep 17, 2020, 10:18 AM Anders Heintz notifications@github.com wrote:

Thanks for your quick reply!

This is the code I'm using and generates the same stacktrace as above.

            var client = httpClientFactory.CreateClient();
            var stream = await client.GetStreamAsync("https://media.cdn.storm.io/62/fa457334-0cd4-4839-ad6d-1808f921f5e6");
            await b.Decode(stream, false)
                .ResizerCommands("width=200&ignore_icc_errors=true")
                .EncodeToStream(output, false, new MozJpegEncoder(90))
                .Finish()
                .WithSecurityOptions(new SecurityOptions
                {
                    MaxFrameSize = new FrameSizeLimit(30000, 30000, 200),
                    MaxDecodeSize = new FrameSizeLimit(30000, 30000, 200),
                    MaxEncodeSize = new FrameSizeLimit(30000, 30000, 200)
                })
                .InProcessAndDisposeAsync();

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow/issues/512#issuecomment-694341907, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH4RN5QY33YK5JU5I53SGIZFBANCNFSM4ROVP7GQ .

aheintz commented 4 years ago

Oh, that worked like a charm! Thanks for your help, saved my night! 😄

patrickmichalina commented 3 years ago

@lilith how can we apply this to the node package?

lilith commented 3 years ago

What code are you currently using?

On Mon, Dec 14, 2020, 12:08 PM Patrick Michalina notifications@github.com wrote:

@lilith https://github.com/lilith how can we apply this to the node package?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/imazen/imageflow/issues/512#issuecomment-744647356, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA2LH43PAO6EGIT24I62WDSUZPBVANCNFSM4ROVP7GQ .

patrickmichalina commented 3 years ago

This sort of flow is how we are doing it:

    const streams = this.prepareStreamsForProcess(asset, hash)

    const inStream = new FromStream(streams.input)
    const outStream = new FromStream(streams.output)

    return new Steps(inStream)
      .constrainWithin(query.width, query.height)
      .encode(outStream, this.getFormat(query.format, query.quality))
      .execute()

All of a sudden getting a bunch of these errors "Wrong input color space on transform" and wondering how to possibly mute this like noted in the thread here.

patrickmichalina commented 3 years ago

/home/runner/.cargo/git/checkouts/imageflow-ce6f29762d899395/1a7e1ee/imageflow_core/src/codecs/color_transform_cache.rs:126:197

anshulrgoyal commented 3 years ago

@patrickmichalina I will check if we support these options in the nodejs package, if not I will add it.

patrickmichalina commented 3 years ago

@anshulrgoyal much appreciated!

anshulrgoyal commented 3 years ago

@patrickmichalina We have added a new DecodeOptions type to the imageflow node which passed as the second argument to the decode method and Step class constructor. I will release the update package within a few minutes and it will be available in a few hours.

anshulrgoyal commented 3 years ago

@patrickmichalina The package is live and I have added an example in read me.

patrickmichalina commented 3 years ago

Fantastic thank you very much appreciated for the quick update. This will fix our production tool