Gif exporting now works in HTML5

This commit is contained in:
OverloadedOrama 2020-08-07 11:01:27 +03:00
parent f3bce3857a
commit 205e72f356
4 changed files with 27 additions and 8 deletions

View file

@ -179,9 +179,12 @@ func export_processed_images(ignore_overwrites: bool, export_dialog: AcceptDialo
scale_processed_images()
if current_tab == ExportTab.ANIMATION and animation_type == AnimationType.ANIMATED:
if gif_export_thread.is_active():
gif_export_thread.wait_to_finish()
gif_export_thread.start(self, "export_gif", {"export_dialog": export_dialog, "export_paths": export_paths})
if OS.get_name() == "HTML5":
export_gif({"export_dialog": export_dialog, "export_paths": export_paths})
else:
if gif_export_thread.is_active():
gif_export_thread.wait_to_finish()
gif_export_thread.start(self, "export_gif", {"export_dialog": export_dialog, "export_paths": export_paths})
else:
for i in range(processed_images.size()):
if OS.get_name() == "HTML5":
@ -224,11 +227,15 @@ func export_gif(args: Dictionary) -> void:
write_frame_to_gif(processed_images[i], Global.animation_timer.wait_time, exporter, args["export_dialog"])
for i in range(processed_images.size() - 2, 0, -1):
write_frame_to_gif(processed_images[i], Global.animation_timer.wait_time, exporter, args["export_dialog"])
var file: File = File.new()
file.open(args["export_paths"][0], File.WRITE)
file.store_buffer(exporter.export_file_data())
file.close()
if OS.get_name() == "HTML5":
Html5FileExchange.save_gif(exporter.export_file_data(), args["export_paths"][0])
else:
var file: File = File.new()
file.open(args["export_paths"][0], File.WRITE)
file.store_buffer(exporter.export_file_data())
file.close()
args["export_dialog"].toggle_export_progress_popup(false)
Global.notification_label("File(s) exported")

View file

@ -197,6 +197,13 @@ func save_image(image : Image, file_name : String = "export") -> void:
JavaScript.eval("download('%s', %s, 'image/png');" % [file_name, str(png_data)], true)
func save_gif(data, file_name : String = "export") -> void:
if OS.get_name() != "HTML5" or !OS.has_feature('JavaScript'):
return
JavaScript.eval("download('%s', %s, 'image/gif');" % [file_name, str(Array(data))], true)
func load_shader() -> void:
if OS.get_name() != "HTML5" or !OS.has_feature('JavaScript'):
return