1. --!movie
  2.  
  3. global $
  4.  
  5. ----------------------------------------
  6. -- converts filmstrip image with alpha channel to animated WebP with alpha channel
  7. ----------------------------------------
  8. on startMovie
  9.  
  10.     -- CONFIG
  11.     DUR = 50 -- 50 ms = 20 fps
  12.  
  13.     -- libs
  14.     $.import("console").show()
  15.  
  16.     -- load strip BMP (with alpha channel and 29 frames of 100x100px) into image
  17.     m = new(#bitmap)
  18.     m.importFileInto($.PATH&"web_heart_strip_32bit_alpha.bmp", [#trimWhiteSpace: FALSE])
  19.     webHeart = m.image
  20.     webHeartMask = webHeart.extractAlpha().createMask()
  21.  
  22.     -- create an instance of the AWEBP lib
  23.     awebp = $.include($.PATH&"awebp.ls").new()
  24.  
  25.     ms = the milliseconds
  26.  
  27.     -- initialize AWEBP (i.e. start creation of new WebP file)
  28.     awebp.init(0) -- 0 = loop forever
  29.  
  30.     -- add frames in a loop
  31.     w = 100
  32.     h = 100
  33.     r = rect(0, 0, w, h)
  34.  
  35.     frameImg = image(w, h, 32)
  36.     frameImg.setAlpha(0)
  37.     frameImg.useAlpha = 1
  38.  
  39.     cnt = webHeart.width / w
  40.     repeat with i = 1 to cnt
  41.         -- extract next frame from strip
  42.         frameImg.fill(frameImg.rect, rgb(255,255,255))
  43.         frameImg.setAlpha(0)
  44.         frameImg.copyPixels(webHeart, r, r.offset((i-1)*w, 0), [#maskImage:webHeartMask])
  45.  
  46.         -- add frame
  47.         awebp.addFrame(frameImg, DUR)
  48.     end repeat
  49.  
  50.     ms = the milliseconds-ms
  51.  
  52.     -- save the WebP file
  53.     awebp.writeFile($.PATH&"animation_web_heart.webp")
  54.  
  55.     out("Done. Animated WebP file was generated in "&ms&" milliseconds.")
  56. end
  57.  
[raw code]