Skip to content

Commit

Permalink
Add new private vips package
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Aug 28, 2024
1 parent e1e10ab commit 53e3547
Show file tree
Hide file tree
Showing 17 changed files with 1,061 additions and 0 deletions.
37 changes: 37 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@wordpress/undo-manager": "file:packages/undo-manager",
"@wordpress/url": "file:packages/url",
"@wordpress/viewport": "file:packages/viewport",
"@wordpress/vips": "file:packages/vips",
"@wordpress/warning": "file:packages/warning",
"@wordpress/widgets": "file:packages/widgets",
"@wordpress/wordcount": "file:packages/wordcount",
Expand Down
1 change: 1 addition & 0 deletions packages/vips/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
7 changes: 7 additions & 0 deletions packages/vips/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->

## Unreleased

### New Features

- Initial public release.
98 changes: 98 additions & 0 deletions packages/vips/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# `@wordpress/vips`

Helper package to interact with [`wasm-vips`](https://github.com/kleisauke/wasm-vips).

## Installation

Install the module

```bash
npm install @wordpress/vips --save
```

## API Reference

<!-- START TOKEN(Autogenerated API docs) -->

### cancelOperations

Cancels all ongoing image operations for a given item ID.

The onProgress callbacks check for an IDs existence in this list, killing the process if it's absent.

_Parameters_

- _id_ `ItemId`: Item ID.

_Returns_

- boolean Whether any operation was cancelled.

### compressImage

Compresses an existing image using vips.

_Parameters_

- _id_ `ItemId`: Item ID.
- _buffer_ `ArrayBuffer`: Original file buffer.
- _type_ `string`: Mime type.
- _quality_ Desired quality.
- _interlaced_ Whether to use interlaced/progressive mode. Only used if the outputType supports it.

_Returns_

- `Promise< ArrayBuffer >`: Compressed file data.

### convertImageFormat

Converts an image to a different format using vips.

_Parameters_

- _id_ `ItemId`: Item ID.
- _buffer_ `ArrayBuffer`: Original file buffer.
- _inputType_ `string`: Input mime type.
- _outputType_ `string`: Output mime type.
- _quality_ Desired quality.
- _interlaced_ Whether to use interlaced/progressive mode. Only used if the outputType supports it.

### hasTransparency

Determines whether an image has an alpha channel.

_Parameters_

- _buffer_ `ArrayBuffer`: Original file object.

_Returns_

- `Promise< boolean >`: Whether the image has an alpha channel.

### resizeImage

Resizes an image using vips.

_Parameters_

- _id_ `ItemId`: Item ID.
- _buffer_ `ArrayBuffer`: Original file buffer.
- _type_ `string`: Mime type.
- _resize_ `ImageSizeCrop`: Resize options.
- _smartCrop_ Whether to use smart cropping (i.e. saliency-aware).

_Returns_

- `Promise< { buffer: ArrayBuffer; width: number; height: number; originalWidth: number; originalHeight: number; } >`: Processed file data plus the old and new dimensions.

### setLocation

Dynamically sets the location / public path to use for loading the WASM files.

This is required when loading this module in an inline worker, where globals such as **webpack_public_path** are not available.

_Parameters_

- _newLocation_ `string`: Location, typically a base URL such as "<https://example.com/path/to/js/...">.

<!-- END TOKEN(Autogenerated API docs) -->
40 changes: 40 additions & 0 deletions packages/vips/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@wordpress/vips",
"version": "1.0.0-prerelease",
"private": true,
"description": "Utils for working with libvips.",
"author": "The WordPress Contributors",
"license": "GPL-2.0-or-later",
"keywords": [
"wordpress",
"media",
"libvips"
],
"homepage": "https://github.com/WordPress/gutenberg/tree/HEAD/packages/vips/README.md",
"repository": {
"type": "git",
"url": "https://github.com/WordPress/gutenberg.git",
"directory": "packages/vips"
},
"bugs": {
"url": "https://github.com/WordPress/gutenberg/issues"
},
"engines": {
"node": ">=18.12.0",
"npm": ">=8.19.2"
},
"main": "build/index.js",
"module": "build-module/index.js",
"types": "build-types",
"exports": {
".": {
"default": "./src/index.ts"
}
},
"dependencies": {
"wasm-vips": "^0.0.10"
},
"publishConfig": {
"access": "public"
}
}
Loading

0 comments on commit 53e3547

Please sign in to comment.