-module(png). -compile(export_all). -record(png_info, {width, height, bitDepth, colourType, compression, filter, interlace}). getSize(TempSize) -> io:format("getSize(~p)~n",[binary_to_list(TempSize)]), getSize(binary_to_list(TempSize),0, 65536*256). getSize([], Acc, Mult) -> erlang:trunc(Acc); getSize([Temp|Size], Acc, Mult) -> getSize(Size,Acc+(Temp*Mult), Mult/256). sizeOfPNG(Filename) -> A=getPngGeometry(Filename), {element(2,A), element(3,A)}. getPngGeometry(Filename) -> {ok, FileRef}=file:open(Filename, [read, raw, binary]), Status = file:read(FileRef,8), {ok,Sign} = Status, case Sign of <<137,80,78,71,13,10,26,10>> -> {ok,TempSize} = file:read(FileRef,4), {ok,IHeader} = file:read(FileRef,4), case IHeader of <<"IHDR">> -> io:format("IHDR matches~n",[]), Size = getSize(TempSize), io:format("Size = ~p~n",[Size]), {ok,Chunk} = file:read(FileRef,Size), <> = Chunk, file:close(FileRef), #png_info{width=Width, height=Height, bitDepth=BitDepth, colourType=ColourType, compression=Compression, filter=Filter, interlace=Interlace}; _ -> file:close(FileRef), no_IHDR_block end; _ -> file:close(FileRef), not_a_PNG_file end.