Does Image have a Mask?

I have a few hundred images (mostly icons), and know for a fact that some have masks and others don’t (they show white background when viewed in “Preview”)

I have tried various techniques to try and find all the non-masked images, but to no avail
I can scan the directories and find all the files, load them as pictures

  • hasAlphaChannel // RETURNS TRUE FOR ALL IMAGES
  • dim m as picture=p.mask; if m<>nil then // RETURN FALSE FOR ALL IMAGES

these are all PNG images from 16x16 to 96x96 in size… on disk files, not ImageSets in the IDE

mask(false) could return nil.
Just calling mask may create one.

this is what I have…

		Dim dlg As OpenDialog
		Dim f As FolderItem
		Dim p As picture
		Dim g As graphics
		
		Dim x As Integer
		Dim y As Integer
		Dim i As Integer
		Dim j As Integer
		Dim f2 As FolderItem
		Dim f3 As FolderItem
		Dim f4 As FolderItem
		
		
		Dim t As TextOutputStream
		f=SpecialFolder.Desktop.child("xxx.trace_log")
		If f.exists Then f.delete
		t=TextOutputStream.Create(f)
		
		
		f2=GetFolderItem("")
		For i=1 To f2.Count
				f=f2.TrueItem(i)
				If f.Directory=False Then Continue
				For j=1 To f.Count
						f4=f.TrueItem(j)
						If Right(f4.DisplayName,4)<>".png" Then Continue
						p=picture.Open(f4)
						Dim m As picture=p.mask(False)
						t.writeline f4.parent.DisplayName+"/"+f4.DisplayName+"="+Str(m=Nil)
				Next j
		Next i
		t.close
		MsgBox "done "+Str(f2.count)
		Quit

no need to be elegant… its a Q&D one-off (quick and dirty)

Picture open on Mac does always use NSImage and give image with alpha.
So this will never have a mask.

Q & D with a shell:

mdls -name kMDItemHasAlphaChannel 'PathToPicture.png'

Mask function has a Create parameter:
http://documentation.xojo.com/index.php/Picture.Mask

[quote=365990:@Christian Schmitz]Picture open on Mac does always use NSImage and give image with alpha.
So this will never have a mask.[/quote]
So the question is not whether it has a mask, but whether any of the pixels are transparent.

true…
but using the code I posted above… “M” is always nil so it cannot be examined.

I really don’t want to manually check each image, there are hundreds

Well, if you use my plugins, you could try CGImageSourceMBS on Mac.
There you have properties per image, so you could check kCGImagePropertyHasAlpha key.

and how would that be different from “hasAlphaChannel”

Since it’s Q&D, use an older version that opens images with masks.

Here you go:

[code]dim f as FolderItem = SpecialFolder.Desktop.Child(“test.tiff”)
dim c as new CGImageSourceMBS(f)
dim d as Dictionary = c.PropertiesAtIndex(0)
dim b as Boolean = d.Lookup(c.kCGImagePropertyHasAlpha, false)

MsgBox "alpha: "+str(b)[/code]

So this checks for alpha status for various image types on macOS.

Christian… thanks… but you realize that was a waste of your time, as I do not , nor ever will own MBS.

No worries… I dealt with the images one-by-one… so I’m good… thanks for all the input

And Happy Holidays to all (I don’t care WHAT Prez. Chump says)

I can change that. Happy Christmas!

for the records, another way using the shell and the scriptable image processing system would be sips -g hasAlpha <path> that should be available on most *NIX incl. Darwin.