How to use the sharp.prototype function in sharp

To help you get started, we’ve selected a few sharp 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 vseventer / sharp-cli / test / mocks / sharp.js View on Github external
// Strict mode.
'use strict'

// Package modules.
const sharp = require('sharp')
const sinon = require('sinon')

// Configure.
const methods = Object.getOwnPropertyNames(sharp.prototype)

// Patch methods, add reset and restore handlers.
methods.forEach((name) => sinon.spy(sharp.prototype, name))
sharp.prototype.reset = () => {
  methods.forEach((name) => sharp.prototype[name].resetHistory())
}
sharp.prototype.restore = () => {
  methods.forEach((name) => sharp.prototype[name].restore())
}

// Exports.
module.exports = sharp
github vseventer / sharp-cli / test / mocks / sharp.js View on Github external
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

// Strict mode.
'use strict'

// Package modules.
const sharp = require('sharp')
const sinon = require('sinon')

// Configure.
const methods = Object.getOwnPropertyNames(sharp.prototype)

// Patch methods, add reset and restore handlers.
methods.forEach((name) => sinon.spy(sharp.prototype, name))
sharp.prototype.reset = () => {
  methods.forEach((name) => sharp.prototype[name].resetHistory())
}
sharp.prototype.restore = () => {
  methods.forEach((name) => sharp.prototype[name].restore())
}

// Exports.
module.exports = sharp
github vseventer / sharp-cli / test / mocks / sharp.js View on Github external
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

// Strict mode.
'use strict'

// Package modules.
const sharp = require('sharp')
const sinon = require('sinon')

// Configure.
const methods = Object.getOwnPropertyNames(sharp.prototype)

// Patch methods, add reset and restore handlers.
methods.forEach((name) => sinon.spy(sharp.prototype, name))
sharp.prototype.reset = () => {
  methods.forEach((name) => sharp.prototype[name].resetHistory())
}
sharp.prototype.restore = () => {
  methods.forEach((name) => sharp.prototype[name].restore())
}

// Exports.
module.exports = sharp
github superfly / fly / packages / core / src / bridge / fly / image.ts View on Github external
import { registerBridge } from "../"
import { ivm } from "../../"
import { transferInto } from "../../utils/buffer"

import log from "../../log"

import * as sharp from "sharp"
import { Bridge } from "../bridge"
import { Runtime } from "../../runtime"

type imageOperation = (...args: any[]) => sharp.Sharp

const allowedOperations: Map = new Map([
  ["resize", sharp.prototype.resize],
  ["scale", scale],
  ["crop", crop],
  ["embed", sharp.prototype.embed],
  ["background", sharp.prototype.background],
  ["withoutEnlargement", sharp.prototype.withoutEnlargement],
  ["withMetadata", sharp.prototype.withMetadata],

  ["overlayWith", sharp.prototype.overlayWith],
  ["negate", sharp.prototype.negate],
  ["max", sharp.prototype.max],
  ["extend", sharp.prototype.extend],
  ["flatten", sharp.prototype.flatten],

  // output
  ["png", sharp.prototype.png],
  ["webp", sharp.prototype.webp],
github superfly / fly / packages / core / src / bridge / fly / image.ts View on Github external
import * as sharp from "sharp"
import { Bridge } from "../bridge"
import { Runtime } from "../../runtime"

type imageOperation = (...args: any[]) => sharp.Sharp

const allowedOperations: Map = new Map([
  ["resize", sharp.prototype.resize],
  ["scale", scale],
  ["crop", crop],
  ["embed", sharp.prototype.embed],
  ["background", sharp.prototype.background],
  ["withoutEnlargement", sharp.prototype.withoutEnlargement],
  ["withMetadata", sharp.prototype.withMetadata],

  ["overlayWith", sharp.prototype.overlayWith],
  ["negate", sharp.prototype.negate],
  ["max", sharp.prototype.max],
  ["extend", sharp.prototype.extend],
  ["flatten", sharp.prototype.flatten],

  // output
  ["png", sharp.prototype.png],
  ["webp", sharp.prototype.webp],
  ["jpeg", sharp.prototype.jpeg]
])

const metadataFields = [
  "format",
  "width",
  "height",
  "number",
github vseventer / sharp-cli / test / mocks / sharp.js View on Github external
  methods.forEach((name) => sharp.prototype[name].resetHistory())
}

sharp

High performance Node.js image processing, the fastest module to resize JPEG, PNG, WebP, GIF, AVIF and TIFF images

Apache-2.0
Latest version published 1 month ago

Package Health Score

94 / 100
Full package analysis