def self.load png, metadata_only = false
png = png.dup
signature = png.slice! 0, 8
raise ArgumentError, 'Invalid PNG signature' unless signature == SIGNATURE
ihdr = read_chunk 'IHDR', png
bit_depth, color_type, width, height = read_IHDR ihdr, metadata_only
return [width, height, bit_depth] if metadata_only
canvas = PNG::Canvas.new width, height
type = png.slice(4, 4).unpack('a4').first
read_chunk type, png if type == 'iCCP'
read_IDAT read_chunk('IDAT', png), bit_depth, color_type, canvas
read_chunk 'IEND', png
canvas
end