1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Resize image on exporting PNG

Also fixed issue when exporting a spritesheet, spritesheet_rows wasn't being updated if the user didn't change the value of the spinbox
This commit is contained in:
OverloadedOrama 2019-12-29 22:04:44 +02:00
parent eeaa691d36
commit 1a6f6c1cc9
2 changed files with 53 additions and 7 deletions

View file

@ -27,6 +27,40 @@ text = "Export current frame"
items = [ "Export current frame", null, false, 0, null, "Export all frames as multiple files", null, false, 1, null, "Export all frames as a spritesheet (single file)", null, false, 2, null ]
selected = 0
[node name="Resize" type="HBoxContainer" parent="."]
margin_right = 40.0
margin_bottom = 40.0
[node name="Label" type="Label" parent="Resize"]
margin_top = 13.0
margin_right = 46.0
margin_bottom = 27.0
text = "Resize:"
[node name="ResizeValue" type="SpinBox" parent="Resize"]
margin_left = 50.0
margin_right = 124.0
margin_bottom = 40.0
min_value = 10.0
max_value = 1000.0
step = 10.0
value = 100.0
suffix = "%"
[node name="Label2" type="Label" parent="Resize"]
margin_left = 128.0
margin_top = 13.0
margin_right = 215.0
margin_bottom = 27.0
text = "Interpolation:"
[node name="Interpolation" type="OptionButton" parent="Resize"]
margin_right = 41.0
margin_bottom = 20.0
text = "Item 0"
items = [ "Nearest", null, false, 0, null, "Bilinear", null, false, 1, null, "Cubic", null, false, 2, null, "Trilinear", null, false, 3, null, "Lanczos", null, true, 4, null ]
selected = 0
[node name="Spritesheet" type="HBoxContainer" parent="."]
visible = false
margin_left = 8.0
@ -35,19 +69,20 @@ margin_right = 507.0
margin_bottom = 312.0
[node name="Label" type="Label" parent="Spritesheet"]
margin_left = 200.0
margin_top = 145.0
margin_right = 300.0
margin_right = 60.0
margin_bottom = 159.0
text = "Columns:"
[node name="VerticalFrames" type="SpinBox" parent="Spritesheet"]
margin_left = 304.0
margin_right = 378.0
margin_left = 64.0
margin_right = 138.0
margin_bottom = 304.0
mouse_default_cursor_shape = 2
min_value = 1.0
value = 1.0
[connection signal="file_selected" from="." to="." method="_on_ExportSprites_file_selected"]
[connection signal="item_selected" from="ExportOption" to="." method="_on_ExportOption_item_selected"]
[connection signal="value_changed" from="Resize/ResizeValue" to="." method="_on_ResizeValue_value_changed"]
[connection signal="item_selected" from="Resize/Interpolation" to="." method="_on_Interpolation_item_selected"]
[connection signal="value_changed" from="Spritesheet/VerticalFrames" to="." method="_on_VerticalFrames_value_changed"]

View file

@ -2,6 +2,8 @@ extends FileDialog
var current_export_path := ""
var export_option := 0
var resize := 100
var interpolation = Image.INTERPOLATE_NEAREST
var spritesheet_rows = 1
var spritesheet_columns = 1
@ -23,9 +25,14 @@ func _on_ExportOption_item_selected(ID : int) -> void:
else:
spritesheet_container.visible = false
func _on_ResizeValue_value_changed(value) -> void:
resize = value
func _on_Interpolation_item_selected(ID : int) -> void:
interpolation = ID
func _on_VerticalFrames_value_changed(value) -> void:
value = min(value, Global.canvases.size())
spritesheet_rows = ceil(Global.canvases.size() / value)
spritesheet_columns = value
var vertical_frames : SpinBox = Global.find_node_by_name(self, "VerticalFrames")
@ -68,11 +75,15 @@ func save_sprite(canvas : Canvas, path : String) -> void:
canvas.blend_rect(whole_image, img, Rect2(canvas.position, canvas.size), Vector2.ZERO)
layer[0].lock()
if resize != 100:
whole_image.resize(whole_image.get_size().x * resize / 100, whole_image.get_size().y * resize / 100, interpolation)
var err = whole_image.save_png(path)
if err != OK:
OS.alert("Can't save file")
func save_spritesheet() -> void:
spritesheet_rows = ceil(Global.canvases.size() / spritesheet_columns)
var width = Global.canvas.size.x * spritesheet_rows
var height = Global.canvas.size.y * spritesheet_columns
@ -105,8 +116,8 @@ func save_spritesheet() -> void:
canvas.blend_rect(whole_image, img, Rect2(canvas.position, canvas.size), dst)
layer[0].lock()
if resize != 100:
whole_image.resize(width * resize / 100, height * resize / 100, interpolation)
var err = whole_image.save_png(current_export_path)
if err != OK:
OS.alert("Can't save file")