mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 09:09:47 +00:00
Implement webp and jpeg exporting
This commit is contained in:
parent
ab88ca6df6
commit
ea71adf308
|
@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
Built using Godot 4.1.1
|
Built using Godot 4.1.1
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
- Export to webp and jpeg file formats. Webp is currently only for static images and does not support animations.
|
||||||
- Added some missing shortcuts for buttons. [#900](https://github.com/Orama-Interactive/Pixelorama/pull/900)
|
- Added some missing shortcuts for buttons. [#900](https://github.com/Orama-Interactive/Pixelorama/pull/900)
|
||||||
- The brush increment/decrement shortcuts can now be changed. [#900](https://github.com/Orama-Interactive/Pixelorama/pull/900)
|
- The brush increment/decrement shortcuts can now be changed. [#900](https://github.com/Orama-Interactive/Pixelorama/pull/900)
|
||||||
- 3D layers now support torus shapes. [#900](https://github.com/Orama-Interactive/Pixelorama/pull/900)
|
- 3D layers now support torus shapes. [#900](https://github.com/Orama-Interactive/Pixelorama/pull/900)
|
||||||
|
|
|
@ -4,7 +4,7 @@ enum ExportTab { IMAGE = 0, SPRITESHEET = 1 }
|
||||||
enum Orientation { ROWS = 0, COLUMNS = 1 }
|
enum Orientation { ROWS = 0, COLUMNS = 1 }
|
||||||
enum AnimationDirection { FORWARD = 0, BACKWARDS = 1, PING_PONG = 2 }
|
enum AnimationDirection { FORWARD = 0, BACKWARDS = 1, PING_PONG = 2 }
|
||||||
## See file_format_string, file_format_description, and ExportDialog.gd
|
## See file_format_string, file_format_description, and ExportDialog.gd
|
||||||
enum FileFormat { PNG = 0, GIF = 1, APNG = 2 }
|
enum FileFormat { PNG, WEBP, JPEG, GIF, APNG }
|
||||||
|
|
||||||
## List of animated formats
|
## List of animated formats
|
||||||
var animated_formats := [FileFormat.GIF, FileFormat.APNG]
|
var animated_formats := [FileFormat.GIF, FileFormat.APNG]
|
||||||
|
@ -255,13 +255,33 @@ func export_processed_images(
|
||||||
var succeeded := true
|
var succeeded := true
|
||||||
for i in range(processed_images.size()):
|
for i in range(processed_images.size()):
|
||||||
if OS.has_feature("web"):
|
if OS.has_feature("web"):
|
||||||
JavaScriptBridge.download_buffer(
|
if project.file_format == FileFormat.PNG:
|
||||||
processed_images[i].save_png_to_buffer(),
|
JavaScriptBridge.download_buffer(
|
||||||
export_paths[i].get_file(),
|
processed_images[i].save_png_to_buffer(),
|
||||||
"image/png"
|
export_paths[i].get_file(),
|
||||||
)
|
"image/png"
|
||||||
|
)
|
||||||
|
elif project.file_format == FileFormat.WEBP:
|
||||||
|
JavaScriptBridge.download_buffer(
|
||||||
|
processed_images[i].save_webp_to_buffer(),
|
||||||
|
export_paths[i].get_file(),
|
||||||
|
"image/webp"
|
||||||
|
)
|
||||||
|
elif project.file_format == FileFormat.JPEG:
|
||||||
|
JavaScriptBridge.download_buffer(
|
||||||
|
processed_images[i].save_jpg_to_buffer(),
|
||||||
|
export_paths[i].get_file(),
|
||||||
|
"image/jpeg"
|
||||||
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
var err := processed_images[i].save_png(export_paths[i])
|
var err: Error
|
||||||
|
if project.file_format == FileFormat.PNG:
|
||||||
|
err = processed_images[i].save_png(export_paths[i])
|
||||||
|
elif project.file_format == FileFormat.WEBP:
|
||||||
|
err = processed_images[i].save_webp(export_paths[i])
|
||||||
|
elif project.file_format == FileFormat.JPEG:
|
||||||
|
err = processed_images[i].save_jpg(export_paths[i])
|
||||||
if err != OK:
|
if err != OK:
|
||||||
Global.error_dialog.set_text(
|
Global.error_dialog.set_text(
|
||||||
tr("File failed to save. Error code %s (%s)") % [err, error_string(err)]
|
tr("File failed to save. Error code %s (%s)") % [err, error_string(err)]
|
||||||
|
@ -341,6 +361,10 @@ func file_format_string(format_enum: int) -> String:
|
||||||
match format_enum:
|
match format_enum:
|
||||||
FileFormat.PNG:
|
FileFormat.PNG:
|
||||||
return ".png"
|
return ".png"
|
||||||
|
FileFormat.WEBP:
|
||||||
|
return ".webp"
|
||||||
|
FileFormat.JPEG:
|
||||||
|
return ".jpg"
|
||||||
FileFormat.GIF:
|
FileFormat.GIF:
|
||||||
return ".gif"
|
return ".gif"
|
||||||
FileFormat.APNG:
|
FileFormat.APNG:
|
||||||
|
@ -358,6 +382,10 @@ func file_format_description(format_enum: int) -> String:
|
||||||
# (if they are not given, they will generate themselves based on the enum key name)
|
# (if they are not given, they will generate themselves based on the enum key name)
|
||||||
FileFormat.PNG:
|
FileFormat.PNG:
|
||||||
return "PNG Image"
|
return "PNG Image"
|
||||||
|
FileFormat.WEBP:
|
||||||
|
return "WEBP Image"
|
||||||
|
FileFormat.JPEG:
|
||||||
|
return "JPEG Image"
|
||||||
FileFormat.GIF:
|
FileFormat.GIF:
|
||||||
return "GIF Image"
|
return "GIF Image"
|
||||||
FileFormat.APNG:
|
FileFormat.APNG:
|
||||||
|
@ -385,7 +413,7 @@ func _create_export_path(multifile: bool, project: Project, frame := 0) -> Strin
|
||||||
project, frame - 1
|
project, frame - 1
|
||||||
)
|
)
|
||||||
# Check if exported frame is in frame tag
|
# Check if exported frame is in frame tag
|
||||||
if frame_tag_and_start_id != null:
|
if not frame_tag_and_start_id.is_empty():
|
||||||
var frame_tag: String = frame_tag_and_start_id[0]
|
var frame_tag: String = frame_tag_and_start_id[0]
|
||||||
var start_id: int = frame_tag_and_start_id[1]
|
var start_id: int = frame_tag_and_start_id[1]
|
||||||
# Remove unallowed characters in frame tag directory
|
# Remove unallowed characters in frame tag directory
|
||||||
|
@ -411,7 +439,7 @@ func _create_export_path(multifile: bool, project: Project, frame := 0) -> Strin
|
||||||
func _get_proccessed_image_animation_tag_and_start_id(
|
func _get_proccessed_image_animation_tag_and_start_id(
|
||||||
project: Project, processed_image_id: int
|
project: Project, processed_image_id: int
|
||||||
) -> Array:
|
) -> Array:
|
||||||
var result_animation_tag_and_start_id = null
|
var result_animation_tag_and_start_id := []
|
||||||
for animation_tag in project.animation_tags:
|
for animation_tag in project.animation_tags:
|
||||||
# Check if processed image is in frame tag and assign frame tag and start id if yes
|
# Check if processed image is in frame tag and assign frame tag and start id if yes
|
||||||
# Then stop
|
# Then stop
|
||||||
|
|
|
@ -4,11 +4,17 @@ extends ConfirmationDialog
|
||||||
signal resume_export_function
|
signal resume_export_function
|
||||||
|
|
||||||
var preview_current_frame := 0
|
var preview_current_frame := 0
|
||||||
var preview_frames := []
|
var preview_frames: Array[Texture2D] = []
|
||||||
|
|
||||||
## Allow custom exporters to be added
|
# Allow custom exporters to be added
|
||||||
var image_exports := [Export.FileFormat.PNG, Export.FileFormat.GIF, Export.FileFormat.APNG]
|
var image_exports: Array[Export.FileFormat] = [
|
||||||
var spritesheet_exports := [Export.FileFormat.PNG]
|
Export.FileFormat.PNG,
|
||||||
|
Export.FileFormat.WEBP,
|
||||||
|
Export.FileFormat.JPEG,
|
||||||
|
Export.FileFormat.GIF,
|
||||||
|
Export.FileFormat.APNG
|
||||||
|
]
|
||||||
|
var spritesheet_exports := [Export.FileFormat.PNG, Export.FileFormat.WEBP, Export.FileFormat.JPEG]
|
||||||
|
|
||||||
@onready var tabs: TabBar = $VBoxContainer/TabBar
|
@onready var tabs: TabBar = $VBoxContainer/TabBar
|
||||||
@onready var checker: ColorRect = $"%TransparentChecker"
|
@onready var checker: ColorRect = $"%TransparentChecker"
|
||||||
|
|
Loading…
Reference in a new issue