Files

25 lines
909 B
GDScript

extends SceneTree
## Renders an SVG to a square PNG, used to package the icon for Linux.
##
## Usage: godot --headless -s render_icon.gd -- <input.svg> <output.png> <size>
func _initialize() -> void:
var args: PackedStringArray = OS.get_cmdline_user_args()
if args.size() != 3:
printerr("Usage: godot --headless -s render_icon.gd -- <input.svg> <output.png> <size>")
quit(1)
return
var svg: String = FileAccess.get_file_as_string(args[0])
var source: Image = Image.new()
# Load at 1x to read the SVG's own size, then scale so the result is <size> pixels
var error: int = source.load_svg_from_string(svg)
if error == OK:
var image: Image = Image.new()
error = image.load_svg_from_string(svg, float(args[2]) / source.get_width())
if error == OK:
error = image.save_png(args[1])
if error != OK:
printerr("Could not render %s to %s (error %d)" % [args[0], args[1], error])
quit(error)