Identify images with layers and transparency

We require to implement a validation to prevent users from attempting to upload images with transparency and layers (PNGs, TIFF, etc.) in our application based on C# and MVC5.
How can I identify image files with layers and transparency?
Could you send me some code snippets regarding this issue? Thanks!

@jimmy.rojas,

I have observed your requirements and suggest you to please try using following sample code on your end.

string filePath = "Flower.png"; // specify your path
using (PngImage image = (PngImage)Image.Load(filePath))
{
float opacity = image.ImageOpacity; // opacity = 0,470798
Console.WriteLine(opacity);
if (opacity == 0)
{
// The image is fully transparent.
}
}

Thanks for your reply.

How can I detect if the png file contains layers or is it a plain png image?

@jimmy.rojas,

Can you please share source file so that we may further investigate to help you out.

Hi,

I don’t have any source file. I was asking for a code snippet to identify if a .png file has layers.

For instance, for detecting if a PDF file contains any layers:

Document document = new Document(path + “MyFile.pdf”);

foreach (Page page in document.Pages)
{
List<Aspose.Pdf.Layer> layers = page.Layers;
if (layers != null) {

}

}

I was looking for something similar for .png image files.

@jimmy.rojas,

I like to inform that .png does not support layers, thats why i requested you to share your sample .png file so that we may investigate further on our end.

PNG images contains layers indeed. I’m attaching a sample made with Fireworks. PNG with layers.png (38.2 KB)
We need to identify if a PNG file contains layers or not (plain PNG).

The original size is 180 KB. I don’t know if It was attached correctly because the size is smaller after uploading the file.

Fyi. I think it’s not uploading the file correctly. I downloaded the file and looked like a plain PNG.

PNG with layers.png (38.2 KB)

@jimmy.rojas,

This is just a PNG with transparency. Can you please share PNG image which contain layers. Some image viewers like GIMP show images as if they have layers, but actually they don’t. Such editors have a uniform GUI for all types of supported images.

This is what I tried to say in my previous email. When I attached the original PNG image through this forum, it got converted into a plain PNG automatically. I tried a couple of times with the same result. Let me know if there is another way to share my PNG image. Can I send you the files by email?

@jimmy.rojas,

You may please share file via dropxbox and inform us here.

@jimmy.rojas,

We have internally investigated the requirements. We have never encountered a PNG with layers and mostly sure that this is not supported feature for this format. It seems that probably there is some misunderstanding of terms here as PNG does not support layers.

Type a message

It’s very common to create PNG images with layers using Fireworks or Photoshop. We’re having issues when we handle such files. That’s why I was asking for a way to detect if a PNG file contains layers to request the users to upload plain PNG images instead.

layerpanel.png (15.5 KB)

@jimmy.rojas,

Can you please share PNG image which contains layers. We will investigate this on our end to help you out. As my colleague already informed you that we never encountered such PNG with layers. You may please share via Dropbox and inform us here.

I cannot use Dropbox or any cloud File Storage/Sharing because all of them are blocked due to the security policy of my job. I can send you the png file sample by email if you give me an email address.

@jimmy.rojas,

Can you please zip the file and upload zip here.

PNG with layers.zip (176.5 KB)

There you go!

@jimmy.rojas,

I regret to inform that i dont see any layers in PNG file shared by you. Can you please tell me if you are using Fireworks.

@jimmy.rojas,

We have created an issue with ID IMAGINGNET-3593 in our issue tracking system to further investigate the support for layered PNG file ( possibly Adobe fireworks PNG files). We will share the good news with you as soon as the feature will be available in API.

Hello,

Any update on this?