Page 1 of 1

A way to get image size from a file

Posted: Sat Jun 06, 2020 4:32 pm
by Optera
What?
A function to check dimensions directly from a png during data stage.

Why?
I have icons of different sizes and would like to automatically set icon.size and icon.mipmaps according to png dimensions.
Currently I can get away with smart sorting and deriving that information from the path with lookup tables.

Factorio already loads and checks dimensions of files designated by icon, sprite.filename, asf so there shouldn't be an added security issue exposing the function like

Code: Select all

local width, height = get_sprite_dimensions(filename)

Re: A way to get image size from a file

Posted: Sun Jun 07, 2020 1:38 am
by Rseding91
Factorio only loads an image once when the game starts *after* all data stage has been finished and all final image file paths are provided and deduplicated. If that existed it would have to load it every time that line was executed - and would have to - in the middle of parsing data go check if that image exists on disk, load it, process it into RAM, check the dimensions, and then throw it all out.

That's just never going to happen. That's why the size has to be given through lua.