function _createGif(
            arrayBuffer,
            pImg,
            successCallback,
            failureCallback,
            finishCallback
          ) {
            var gifReader = new _omggif.default.GifReader(arrayBuffer);
            pImg.width = pImg.canvas.width = gifReader.width;
            pImg.height = pImg.canvas.height = gifReader.height;
            var frames = [];
            var numFrames = gifReader.numFrames();
            var framePixels = new Uint8ClampedArray(pImg.width * pImg.height * 4);
            if (numFrames > 1) {
              var loadGIFFrameIntoImage = function loadGIFFrameIntoImage(
                frameNum,
                gifReader
              ) {
                try {
                  gifReader.decodeAndBlitFrameRGBA(frameNum, framePixels);
                } catch (e) {
                  _main.default._friendlyFileLoadError(8, pImg.src);
                  if (typeof failureCallback === 'function') {
                    failureCallback(e);
                  } else {
                    console.error(e);
                  }
                }
              };
              for (var j = 0; j < numFrames; j++) {
                var frameInfo = gifReader.frameInfo(j);
                var prevFrameData = pImg.drawingContext.getImageData(
                  0,
                  0,
                  pImg.width,
                  pImg.height
                );

                framePixels = prevFrameData.data.slice();
                loadGIFFrameIntoImage(j, gifReader);
                var imageData = new ImageData(framePixels, pImg.width, pImg.height);
                pImg.drawingContext.putImageData(imageData, 0, 0);
                var frameDelay = frameInfo.delay;
                // To maintain the default of 10FPS when frameInfo.delay equals to 0
                if (frameDelay === 0) {
                  frameDelay = 10;
                }
                frames.push({
                  image: pImg.drawingContext.getImageData(0, 0, pImg.width, pImg.height),
                  delay: frameDelay * 10 //GIF stores delay in one-hundredth of a second, shift to ms
                });

                // Some GIFs are encoded so that they expect the previous frame
                // to be under the current frame. This can occur at a sub-frame level
                //
                // Values :    0 -   No disposal specified. The decoder is
                //                   not required to take any action.
                //             1 -   Do not dispose. The graphic is to be left
                //                   in place.
                //             2 -   Restore to background color. The area used by the
                //                   graphic must be restored to the background color.
                //             3 -   Restore to previous. The decoder is required to
                //                   restore the area overwritten by the graphic with
                //                   what was there prior to rendering the graphic.
                //          4-7 -    To be defined.
                if (frameInfo.disposal === 2) {
                  // Restore background color
                  pImg.drawingContext.clearRect(
                    frameInfo.x,
                    frameInfo.y,
                    frameInfo.width,
                    frameInfo.height
                  );
                } else if (frameInfo.disposal === 3) {
                  // Restore previous
                  pImg.drawingContext.putImageData(
                    prevFrameData,
                    0,
                    0,
                    frameInfo.x,
                    frameInfo.y,
                    frameInfo.width,
                    frameInfo.height
                  );
                }
              }

              //Uses Netscape block encoding
              //to repeat forever, this will be 0
              //to repeat just once, this will be null
              //to repeat N times (1<N), should contain integer for loop number
              //this is changed to more usable values for us
              //to repeat forever, loopCount = null
              //everything else is just the number of loops
              var loopLimit = gifReader.loopCount();
              if (loopLimit === null) {
                loopLimit = 1;
              } else if (loopLimit === 0) {
                loopLimit = null;
              }

              // we used the pImg for painting and saving during load
              // so we have to reset it to the first frame
              pImg.drawingContext.putImageData(frames[0].image, 0, 0);

              pImg.gifProperties = {
                displayIndex: 0,
                loopLimit: loopLimit,
                loopCount: 0,
                frames: frames,
                numFrames: numFrames,
                playing: true,
                timeDisplayed: 0,
                lastChangeTime: 0
              };
            }

            if (typeof successCallback === 'function') {
              successCallback(pImg);
            }
            finishCallback();
          }
Helper function for loading GIF-based images