MCPcopy
hub / github.com/HashLips/hashlips_art_engine / saveProjectPreviewGIF

Function saveProjectPreviewGIF

utils/preview_gif.js:26–89  ·  view source on GitHub ↗
(_data)

Source from the content-addressed store, hash-verified

24});
25
26const saveProjectPreviewGIF = async (_data) => {
27 // Extract from preview config
28 const { numberOfImages, order, repeat, quality, delay, imageName } =
29 preview_gif;
30 // Extract from format config
31 const { width, height } = format;
32 // Prepare canvas
33 const previewCanvasWidth = width;
34 const previewCanvasHeight = height;
35
36 if (_data.length < numberOfImages) {
37 console.log(
38 `You do not have enough images to create a gif with ${numberOfImages} images.`
39 );
40 } else {
41 // Shout from the mountain tops
42 console.log(
43 `Preparing a ${previewCanvasWidth}x${previewCanvasHeight} project preview with ${_data.length} images.`
44 );
45 const previewPath = `${buildDir}/${imageName}`;
46
47 ctx.clearRect(0, 0, width, height);
48
49 hashlipsGiffer = new HashlipsGiffer(
50 canvas,
51 ctx,
52 `${previewPath}`,
53 repeat,
54 quality,
55 delay
56 );
57 hashlipsGiffer.start();
58
59 await Promise.all(_data).then((renderObjectArray) => {
60 // Determin the order of the Images before creating the gif
61 if (order == "ASC") {
62 // Do nothing
63 } else if (order == "DESC") {
64 renderObjectArray.reverse();
65 } else if (order == "MIXED") {
66 renderObjectArray = renderObjectArray.sort(() => Math.random() - 0.5);
67 }
68
69 // Reduce the size of the array of Images to the desired amount
70 if (parseInt(numberOfImages) > 0) {
71 renderObjectArray = renderObjectArray.slice(0, numberOfImages);
72 }
73
74 renderObjectArray.forEach((renderObject, index) => {
75 ctx.globalAlpha = 1;
76 ctx.globalCompositeOperation = "source-over";
77 ctx.drawImage(
78 renderObject.loadedImage,
79 0,
80 0,
81 previewCanvasWidth,
82 previewCanvasHeight
83 );

Callers 1

preview_gif.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected