Skip to content

Commit 70c98d5

Browse files
committed
feat: add GIF support to MediaBlock and ShowBlock
1 parent e618ce7 commit 70c98d5

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

js/blocks/MediaBlocks.js

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -948,26 +948,27 @@ function setupMediaBlocks(activity) {
948948
});
949949
}
950950

951-
/**
952-
* Validates and processes the media file.
953-
* @param {string} filePath - The path to the media file.
954-
* @returns {boolean} - True if the file is valid, false otherwise.
955-
*/
956-
validateMedia(filePath) {
957-
const validExtensions = ["png", "jpg", "jpeg", "gif"];
958-
const fileExtension = filePath.split(".").pop().toLowerCase();
959-
return validExtensions.includes(fileExtension);
960-
}
951+
// Override the loadThumbnail method to handle GIFs
952+
loadThumbnail(imagePath) {
953+
const that = this;
954+
const image = new Image();
955+
956+
image.onload = () => {
957+
const bitmap = new createjs.Bitmap(image);
958+
if (imagePath.endsWith(".gif")) {
959+
// Handle GIF playback using a library like gif.js or similar
960+
const gif = new SuperGif({ gif: image });
961+
gif.load(() => {
962+
that.value = gif.get_canvas().toDataURL();
963+
that.blocks.updateBlockText(thisBlock);
964+
});
965+
} else {
966+
that.value = imagePath;
967+
that.blocks.updateBlockText(thisBlock);
968+
}
969+
};
961970

962-
/**
963-
* Handles the media file import.
964-
* @param {string} filePath - The path to the media file.
965-
*/
966-
importMedia(filePath) {
967-
if (!this.validateMedia(filePath)) {
968-
throw new Error(_("Invalid media file type. Supported types are: PNG, JPG, GIF."));
969-
}
970-
// Logic to handle the media file import (e.g., display or process the file)
971+
image.src = imagePath;
971972
}
972973
}
973974

0 commit comments

Comments
 (0)