Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

asset-resizer

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

asset-resizer

Resize assets as part of build workflow.

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

asset-resizer

downloads types: Typescript build

A minimal package to easily automate image asset resizing as a part of a build process. Uses sharp.

Getting Started

Install asset-resizer with:

npm i asset-resizer --save-dev

Then add assetresizer.config.js to your root directory, specifying what assets should be resized and where. Alternatively, you may specify a custom config file.

See example config.

// assetresizer.config.js
// alt: module.exports = {
export default {
  baseUrl: ".",
  inputDir: "assets",
  outputDir: "build",
  flatten: true,
  assets: [
    {
      file: "icon.png",
      output: [
        {
          file: "icon512.png",
          width: 512,
        },
        {
          file: "icon32.png",
          width: 32,
        },
        //...
      ],
    },
    //...
  ],
};

Command Line Usage

Run:

asset-resizer parse
asset-resizer parse --config=custom.config.js

Validate config file:

asset-resizer config
asset-resizer config --config=custom.config.js

Add these lines to your package.json to integrate into your build workflow.

Programmatic Usage

Alternatively, you can use this package programmatically. See examples.

TypeScript / ESModule
import { parseAllAssets, AssetResizerConfig } from "asset-resizer";

const config: AssetResizerConfig = {
  baseUrl: ".",
  inputDir: "assets",
  outputDir: "build",
  flatten: true,
  assets: [
    //...
  ],
};

parseAllAssets(config).then(() => {
  console.log("done");
});
CommonJS
const { parseAllAssets } = require("asset-resizer");

parseAllAssets({
  baseUrl: ".",
  inputDir: "assets",
  outputDir: "build",
  flatten: true,
  assets: [
    //...
  ],
}).then(() => {
  console.log("done");
});

Configuration Options

AssetResizerConfig

OptionTypeDescriptionDefault
baseUrlstringBase url to run resizer from.
inputDirstringDirectory of input filesassets
outputDirstringDirectory to build output filesbuild
assetsArray<AssetResizerAsset>Array of source assets

AssetResizerAsset

OptionTypeDescription
filestringPath to source asset relative to inputDir
outputArray<AssetResizerOutput>Array of output files to create

AssetResizerOutput

OptionTypeDescription
filestringName of file to create. Extension may be one of: jpg, png, webp, avif, tiff, gif, dzi, v.
widthnumber?Width, in pixels, of the target output file. One of width or copy must be present.
heightnumber?(optional) Height, in pixels, of the target output file. If not specified, uses width.
copyboolean?Optionally copy the file instead of resizing. One of width or copy must be present.
fitstring?One of cover, contain, fill, inside, outside. Defaults to cover. See sharp documentation for details.

Development

First run npm i, then npm link to link the cli bin asset-resizer to the development directory.

Building

npm run build

Tests

  • npm run test will run Jest.
  • npm run test:cli will run command from package.json.

Keywords

FAQs

Package last updated on 27 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc