How to use the jpeg-js.encode function in jpeg-js

To help you get started, we’ve selected a few jpeg-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neuroanatomy / BrainBox / xt / app.js View on Github external
case 'axi':i=ya*brain.dim[1]*brain.dim[0]+ y*brain.dim[0]+x; break;
		}
		val=255*(brain.data[i]-brain.min)/(brain.max-brain.min);
		frameData[4*j+0] = val; // red
		frameData[4*j+1] = val; // green
		frameData[4*j+2] = val; // blue
		frameData[4*j+3] = 0xFF; // alpha - ignored in JPEGs
		j++;
	}

	var rawImageData = {
	  data: frameData,
	  width: brain_W,
	  height: brain_H
	};
	return jpeg.encode(rawImageData,99);
}
github oliver-moran / jimp / index.js View on Github external
filterType: this._filterType,
              colorType: (this._rgba) ? 6 : 2,
              inputHasAlpha: true
            });
            
            if (this._rgba) png.data = new Buffer(this.bitmap.data);
            else png.data = compositeBitmapOverBackground(this).data; // when PNG doesn't support alpha
            
            StreamToBuffer(png.pack(), function (err, buffer) {
                return cb.call(that, null, buffer);
            });
            break;

        case Jimp.MIME_JPEG:
            // composite onto a new image so that the background shows through alpha channels
            var jpeg = JPEG.encode(compositeBitmapOverBackground(this), this._quality);
            return cb.call(this, null, jpeg.data);

        case Jimp.MIME_BMP:
            // composite onto a new image so that the background shows through alpha channels
            var bmp = BMP.encode(compositeBitmapOverBackground(this));
            return cb.call(this, null, bmp.data);

        default:
            return cb.call(this, "Unsupported MIME type: " + mime);
    }

    return this;
};
github neuroanatomy / BrainBox / controller / atlasMakerServer / atlasMakerServer.js View on Github external
frameData[4*j + 0] = 255*val; // red
                        frameData[4*j + 1] = 255*val; // green
                        frameData[4*j + 2] = 255*val; // blue
                    }
                    frameData[4*j + 3] = 0xFF; // alpha - ignored in JPEGs
                    j += 1;
                }
            }

            var rawImageData = {
              data: frameData,
              width: brainWidth,
              height: brainHeight
            };

            return jpeg.encode(rawImageData, 99);
        },
github neuroanatomy / BrainBox / controller / atlasmakerServer / atlasmakerServer.js View on Github external
frameData[4*j + 0] = 255*val; // red
                        frameData[4*j + 1] = 255*val; // green
                        frameData[4*j + 2] = 255*val; // blue
                    }
                    frameData[4*j + 3] = 0xFF; // alpha - ignored in JPEGs
                    j += 1;
                }
            }

            var rawImageData = {
              data: frameData,
              width: brainWidth,
              height: brainHeight
            };

            return jpeg.encode(rawImageData, 99);
        },
github unbornchikken / NOOOCL / test / imageTests.js View on Github external
.then(function () {
                                    assert(out.ptr ? true : false);
                                    assert.equal(out.rowPitch, inputImage.width * 4);
                                    assert.equal(ref.address(out.ptr), ref.address(outputData));

                                    var outputImage = {
                                        width: inputImage.width,
                                        height: inputImage.height,
                                        data: outputData
                                    };

                                    var jpegData = jpeg.encode(outputImage, 85);

                                    return fs.writeFileAsync(path.join(cd, "out.jpg"), jpegData.data, "binary").finally(
                                        function () {
                                            return queue.waitable().enqueueUnmapMemory(dst, out.ptr).promise;
                                        });
                                });
                        });
github image-js / image-js / src / image / core / export.js View on Github external
function encodeJpeg(image, options = {}) {
  const data = {
    width: image.width,
    height: image.height,
    data: image.getRGBAData()
  };
  return realEncodeJpeg(data, options.quality).data;
}
github GoogleChrome / lighthouse / lighthouse-core / audits / screenshot-thumbnails.js View on Github external
} else {
        analyzedFrames.forEach(frame => {
          if (frame.getTimeStamp() <= targetTimestamp) {
            frameForTimestamp = frame;
          }
        });
      }

      let base64Data;
      const cachedThumbnail = cachedThumbnails.get(frameForTimestamp);
      if (cachedThumbnail) {
        base64Data = cachedThumbnail;
      } else {
        const imageData = frameForTimestamp.getParsedImage();
        const thumbnailImageData = ScreenshotThumbnails.scaleImageToThumbnail(imageData);
        base64Data = jpeg.encode(thumbnailImageData, 90).data.toString('base64');
        cachedThumbnails.set(frameForTimestamp, base64Data);
      }
      thumbnails.push({
        timing: Math.round(targetTimestamp - speedline.beginning),
        timestamp: targetTimestamp * 1000,
        data: `data:image/jpeg;base64,${base64Data}`,
      });
    }

    return {
      score: 1,
      details: {
        type: 'filmstrip',
        scale: timelineEnd,
        items: thumbnails,
      },
github joshmarinacci / node-pureimage / src / pureimage.js View on Github external
return new Promise((res,rej)=> {
        if(!img.hasOwnProperty('data') || !img.hasOwnProperty('width') || !img.hasOwnProperty('height')) {
            rej(new TypeError('Invalid bitmap image provided'));
        }
        var data = {
            data: img.data,
            width: img.width,
            height: img.height
        };
        outstream.on('error', (err) => rej(err));
        outstream.write(JPEG.encode(data, 50).data, () => {
            outstream.end();
            res();
        });
    });
};
github propelml / propel / src / im.ts View on Github external
function jpegSaveHandler(filename: string, image): void {
  const fs = nodeRequire("fs");
  const {data} = JPEG.encode(image);
  fs.writeFileSync(filename, data);
  return;
}

jpeg-js

A pure javascript JPEG encoder and decoder

BSD-3-Clause
Latest version published 2 years ago

Package Health Score

77 / 100
Full package analysis

Popular jpeg-js functions