1.67.0 • Published 10 days ago

@wix/image-kit v1.67.0

Weekly downloads
-
License
MIT
Repository
-
Last release
10 days ago

Image Kit

Standard library for generating canonical URL's for optimally consuming images at Wix.

Features

  • Maintaining pixel perfect images
  • Ensuring minimum download latency, maximum performance and maximum quality
  • Optimizing images for Retina displays
  • Fetching .webp images where applicable
  • Handling image sharpening when needed
  • Optimizing image upscaling (Wix machine learning) when needed

Example

import { sdk } from '@wix/image-kit';

const img = new Image();

img.src = sdk.getScaleToFillImageUrl('some-image.jpg', 1200, 800, 640, 480, { quality: 90 });

Installation

You have 2 options:

Install package

In public (as open-source, dist only)

You can install the package via npm/yarn

> npm install -s @wix/image-sdk

or:

> yarn add @wix/image-sdk

At Wix (with source)

You can install the package via npm/yarn

> npm install -s @wix/image-kit --registry http://npm.dev.wixpress.com/

or:

> yarn add @wix/image-kit --registry http://npm.dev.wixpress.com/

API

MethodDescription
getScaleToFitImageURL()Scales the designated image to fit in the given target width and height while retaining the original proportions.
getScaleToFillImageURL()Scales the designated image with the exact given target width and height while retaining the original proportions. If the required proportions are different than the original, the image may be cropped to fill the provided width and height, so that only part of the original image might be visible. The position pointing to the place from which to crop the image, if needed, is set by default to the vertical and horizontal center of the image or set to the focalPoint x,y values if presented.
getCropImageURL()Crops the designated image based on the supplied coordinates, starting at the x, y pixel coordinates, along with the width and height options. The image might be scaled according to the target dimensions.

Methods

getScaleToFitImageUrl

getScaleToFillImageUrl(
    relativeUrl,
    sourceWidth,
    sourceHeight,
    targetWidth,
    targetHeight,
    options
)

arguments

namedescriptiontype
relativeUrlthe original image uristring
sourceWidththe original image widthnumber
sourceHeightthe original image heightnumber
targetWidthtarget container widthnumber
targetHeighttarget container heightnumber
optionsadditional image settings [optional]object

options

{
   filters: {
      blur: 15
   },
   unsharpMask: {
      amount: 0.66,
      radius: 1.0,
      threshold: 0.01
   },
   name: 'hello kitty',
   quality: 80,
   upscaleMethod: 'classic',
   watermark: '3856-9876-76890-xzxz',
   isSEOBot: true,
   autoEncode: true,
}
keyvalid valuesdefaulttype
filters.blur0-100-number (%)
unsharpMask.amount0-100.66float
unsharpMask.radius0.1-5001.0float
unsharpMask.amount0-2550.01float
nameany string''string
quality5-9080number
upscaleMethod'auto', 'classic', 'super''auto'string
watermarkwatermark manifest id-string
isSEOBottrue or falsefalseboolean
autoEncodetrue or falsetrueboolean
hasAnimationtrue, false, undefinedfalseboolean;

returns

returns image url [string]

getScaleToFillImageURL

getScaleToFillImageUrl(
    relativeUrl,
    sourceWidth,
    sourceHeight,
    targetWidth,
    targetHeight,
    options
)

arguments

namedescriptiontype
relativeUrlthe original image uristring
sourceWidththe original image widthnumber
sourceHeightthe original image heightnumber
targetWidthtarget container widthnumber
targetHeighttarget container heightnumber
optionsadditional image settings [optional]object

options

{
   filters: {
      blur: 15
   },
   unsharpMask: {
      amount: 0.66,
      radius: 1.0,
      threshold: 0.01
   },
   focalPoint: {
      x: 50,
      y: 50
   },
   name: 'hello kitty',
   quality: 80,
   upscaleMethod: 'classic'
   watermark: '3856-9876-76890-xzxz',
   isSEOBot: true,
   autoEncode: true
}
keyvalid valuesdefaulttype
filters.blur0-100-number (%)
unsharpMask.amount0-100.66float
unsharpMask.radius0.1-5001.0float
unsharpMask.amount0-2550.01float
focalPoint.x0-100-number (%)
focalPoint.y0-100-number (%)
nameany string''string
quality5-9080number
upscaleMethod'auto', 'classic', 'super''auto'string
watermarkwatermark manifest id-string
isSEOBottrue or falsefalseboolean
autoEncodetrue or falsetrueboolean
hasAnimationtrue, false, undefinedfalseboolean;

returns

returns image url [string]

getCropImageURL

getCropImageUrl(
    relativeUrl,
    sourceWidth,
    sourceHeight,
    cropX,
    cropY,
    cropWidth,
    cropHeight,
    targetWidth,
    targetHeight,
    options
)

arguments

namedescriptiontype
relativeUrlthe original image uristring
sourceWidththe original image widthnumber
sourceHeightthe original image heightnumber
cropXthe X pixel coordinate to start cropping fromnumber
cropYthe Y pixel coordinate to start cropping fromnumber
cropWidththe width constraintnumber
cropHeightthe height constraintnumber
targetWidthtarget container widthnumber
targetHeighttarget container heightnumber
optionsadditional image settings [optional]object
hasAnimationtrue, false, undefinedfalseboolean;

options

{
   filters: {
      blur: 15
   },
   unsharpMask: {
      amount: 0.66,
      radius: 1.0,
      threshold: 0.01
   },
   focalPoint: {
      x: 50,
      y: 50
   },
   name: 'hello kitty',
   quality: 80,
   upscaleMethod: 'classic',
   watermark: '3856-9876-76890-xzxz',
   isSEOBot: true,
   autoncode: true
}
keyvalid valuesdefaulttype
filters.blur0-100-number (%)
unsharpMask.amount0-100.66float
unsharpMask.radius0.1-5001.0float
unsharpMask.amount0-2550.01float
nameany string''string
quality5-9080number
upscaleMethod'auto', 'classic', 'super''auto'string
watermarkwatermark manifest id-string
isSEOBottrue or falsefalseboolean

returns

returns image url [string]

1.67.0

10 days ago

1.66.0

11 days ago

1.65.0

18 days ago

1.64.0

1 month ago

1.63.0

2 months ago

1.62.0

2 months ago

1.61.0

2 months ago

1.60.0

2 months ago

1.59.0

3 months ago

1.58.0

3 months ago

1.57.0

3 months ago

1.56.0

3 months ago

1.55.0

3 months ago

1.54.0

3 months ago

1.53.0

3 months ago

1.52.0

3 months ago

1.51.0

3 months ago

1.50.0

4 months ago

1.49.0

4 months ago

1.48.0

4 months ago

1.47.0

4 months ago

1.46.0

5 months ago

1.45.0

5 months ago

1.44.0

5 months ago

1.43.0

5 months ago

1.36.0

10 months ago

1.37.0

9 months ago

1.34.0

11 months ago

1.35.0

10 months ago

1.38.0

7 months ago

1.39.0

7 months ago

1.40.0

7 months ago

1.42.0

6 months ago

1.41.0

6 months ago

1.33.0

11 months ago

1.32.0

1 year ago

1.30.0

1 year ago

1.31.0

1 year ago

1.29.0

1 year ago

1.28.0

1 year ago

1.27.0

1 year ago

1.26.0

2 years ago

1.25.0

2 years ago

1.24.0

2 years ago

1.23.0

2 years ago

1.22.0

2 years ago

1.21.0

2 years ago

1.20.0

2 years ago

1.19.0

2 years ago

1.18.0

2 years ago

1.17.0

2 years ago

1.16.0

2 years ago

1.15.0

2 years ago

1.14.0

2 years ago