1
0
Fork 0
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:
Emmanouil Papadeas 2023-09-05 00:10:40 +03:00
parent ab88ca6df6
commit ea71adf308
3 changed files with 48 additions and 13 deletions

View file

@ -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
### 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)
- 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)

View file

@ -4,7 +4,7 @@ enum ExportTab { IMAGE = 0, SPRITESHEET = 1 }
enum Orientation { ROWS = 0, COLUMNS = 1 }
enum AnimationDirection { FORWARD = 0, BACKWARDS = 1, PING_PONG = 2 }
## 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
var animated_formats := [FileFormat.GIF, FileFormat.APNG]
@ -255,13 +255,33 @@ func export_processed_images(
var succeeded := true
for i in range(processed_images.size()):
if OS.has_feature("web"):
JavaScriptBridge.download_buffer(
processed_images[i].save_png_to_buffer(),
export_paths[i].get_file(),
"image/png"
)
if project.file_format == FileFormat.PNG:
JavaScriptBridge.download_buffer(
processed_images[i].save_png_to_buffer(),
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:
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:
Global.error_dialog.set_text(
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:
FileFormat.PNG:
return ".png"
FileFormat.WEBP:
return ".webp"
FileFormat.JPEG:
return ".jpg"
FileFormat.GIF:
return ".gif"
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)
FileFormat.PNG:
return "PNG Image"
FileFormat.WEBP:
return "WEBP Image"
FileFormat.JPEG:
return "JPEG Image"
FileFormat.GIF:
return "GIF Image"
FileFormat.APNG:
@ -385,7 +413,7 @@ func _create_export_path(multifile: bool, project: Project, frame := 0) -> Strin
project, frame - 1
)
# 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 start_id: int = frame_tag_and_start_id[1]
# 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(
project: Project, processed_image_id: int
) -> Array:
var result_animation_tag_and_start_id = null
var result_animation_tag_and_start_id := []
for animation_tag in project.animation_tags:
# Check if processed image is in frame tag and assign frame tag and start id if yes
# Then stop

View file

@ -4,11 +4,17 @@ extends ConfirmationDialog
signal resume_export_function
var preview_current_frame := 0
var preview_frames := []
var preview_frames: Array[Texture2D] = []
## Allow custom exporters to be added
var image_exports := [Export.FileFormat.PNG, Export.FileFormat.GIF, Export.FileFormat.APNG]
var spritesheet_exports := [Export.FileFormat.PNG]
# Allow custom exporters to be added
var image_exports: Array[Export.FileFormat] = [
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 checker: ColorRect = $"%TransparentChecker"