Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new private vips package #64845

Merged
merged 18 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 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 @@ -91,6 +91,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) -->
35 changes: 35 additions & 0 deletions packages/vips/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"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",
"dependencies": {
"wasm-vips": "^0.0.10"
},
"publishConfig": {
"access": "public"
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
}
}
Loading
Loading