SixLabors / ImageSharp

:camera: A modern, cross-platform, 2D Graphics library for .NET
https://sixlabors.com/products/imagesharp/
Other
7.41k stars 852 forks source link

Read/Write Custom Png Chunk #251

Open boban100janovski opened 7 years ago

boban100janovski commented 7 years ago

Prerequisites

Description

I have a classic .net app where i read/write custom png chunk information (using the Pngcs lib), but now i need to do the same on a .net core application. I saw the source for "PngDecoderCore.cs" and it has a "ReadChunk" method, when i load a Png with "tEXt" chunks it succesufully reads them.

Is it possible to create a WriteChunk method to create a custom chunk, then also a ReadChunk method witch takes an Id parameter for the chunk and return the information.

Maybe i can help out with the "WriteChunk" method.

Thanks

System Configuration

Windows 10 64bit

JimBobSquarePants commented 7 years ago

Hi @boban984

Yeah I guess it should be possible, we'd probably have to pass the chunks as extra params to the encoder.If you'd fancy lending a hand that would be great! 👍

Cheers

James

dlemstra commented 7 years ago

I think we should add that extra chunk to the IPngEncoderOptions to write it to the file. And when it is read it should be added to the MetaData of the Image. Maybe use an extension method? I hope I have some time this week to finally work on the refactoring of the options.

boban100janovski commented 7 years ago

Great that you are open to the idea, i will start implementing the read/write of the custom chunk. I will add it to the Encoder options for writing and then make it part of the MetaData, i guess this shouldn't take me more than a week.

If you guys have any advice or things to look out for before, pls tell me. Thanks

dlemstra commented 7 years ago

@boban984 It might be wise to wait till made those changes :) The public API is very likely to change.

vpenades commented 6 years ago

As an API suggestion:

Custom PNG chunks can be very large, I've seen some applications that use a custom chunk to store the actual data in a PNG container that uses the PNG image as the thunbnail of the actual content.

So, since these chunks can only be useful for those that specifically want to load them, I would suggest to set a programmable filter in PNGDecoder, so only the chunk tags that are in the filter are copied to the MetaData structure.

In fact, consider PNG as a general container with a preview thumbnail.

JimBobSquarePants commented 6 years ago

I'll have to have a good read of the spec again to determine what is what.

JD1337 commented 4 years ago

Great that you are open to the idea, i will start implementing the read/write of the custom chunk. I will add it to the Encoder options for writing and then make it part of the MetaData, i guess this shouldn't take me more than a week.

If you guys have any advice or things to look out for before, pls tell me. Thanks

Did you end up making any progress for this? Was looking for this exact thing now and came across this.

JimBobSquarePants commented 4 years ago

@JD1337 No, it's marked as a future milestone as it's low priority and we have limited resources. Happy to review and accept any potential PRs though.