# laravel-mix-image-multisizer

> A simple laravel mix plugin to copy/minify/resize images

Latest version **0.1.3** (published 2022-10-02) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install laravel-mix-image-multisizer
pnpm add laravel-mix-image-multisizer
yarn add laravel-mix-image-multisizer
bun add laravel-mix-image-multisizer
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2022-10-02 |
| First published | 2022-10-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 27.3 KB |
| Known vulnerabilities | 0 (+6 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Marc Vlendré |
| Maintainers | mcvl02 |
| Keywords | image, picture, processing, copy, resize, minify, optimize |

## Links

- npm: https://www.npmjs.com/package/laravel-mix-image-multisizer
- Repository: https://github.com/McVL02/laravel-mix-image-multisizer
- Homepage: https://github.com/McVL02/laravel-mix-image-multisizer#readme
- Issues: https://github.com/McVL02/laravel-mix-image-multisizer/issues
- npm.io page: https://npm.io/package/laravel-mix-image-multisizer

## Dependencies (4)

- [glob](https://npm.io/package/glob.md) ^8.0.3
- [sharp](https://npm.io/package/sharp.md) ^0.31.1
- [image-size](https://npm.io/package/image-size.md) ^1.0.2
- [@types/sharp](https://npm.io/package/@types/sharp.md) ^0.31.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 0.1.3 (latest) — 2022-10-02
- 0.2.0 — 2022-10-02
- 0.1.2 — 2022-10-02
- 0.1.1 — 2022-10-02
- 0.1.0 — 2022-10-01

## README

# Laravel Mix - image resizer

A simple laravel mix plugin to copy/minify/resize images in your projects.

This package is based of [laravel-mix-simple-image-processing](https://github.com/TristanMouchet/laravel-mix-simple-image-processing), but with updated dependancies and support to have an image not only scaled on width, but also on height. 


## Installation & Usage

Installation of the npm package:

```
npm install laravel-mix-image-multisizer
```

Usage, in your `webpack.mix.js`:

```js
let mix = require('laravel-mix')

require('laravel-mix-image-multisizer')

mix.imgs({
    source: 'resources/images',
    destination: 'public/images',
    // ... other optional parameters
})
```

Executing the module (the following exemple for the "dev" environnement):

```
npm run dev
```

Note: when running `npm run watch` the module is only executed once at the beginning.


## Options
Here is the list of available options when passing an object to the mix.imgs() method:
- [disabled](#disabled)
- [source](#source)
- [destination](#destination)
- [thumbnailsSizes](#thumbnailsSizes)
- [thumbnailsSuffix](#thumbnailsSuffix)
- [thumbnailsOnly](#thumbnailsOnly)
- [smallerThumbnailsOnly](#smallerThumbnailsOnly)
### disabled
Wether to disable the execution of the plugin or not, can be used to disable the execution on specific environnements.
```ts
disabled <boolean>: false
```
### source
Path to the folder containing the images that will be used as input of the processing functions (images in sub-folders are also included).
```ts
source <string>: 'resources/images'
```
### destination
Path to the folder where the images will be saved (with source-like sub-folders).
```ts
destination <string>: 'public/images'
```
### thumbnailsSizes
A list of values (in pixels) related to the sizes of the thumbnails
- 1D list: a list of widths `[w]`. The corresponding heights is calculated proportionally
- 2D list: a list of widths and heights `[w, h]`
```ts
thumbnailsSizes <Array[number] or Array[number, number]>: []
```
### thumbnailsSuffix
Suffix to be used for thumbnail names, the thumbnail names are based on the template `{name}{suffix}{size}.{img-extension}`, for example `image.jpg` could generate a thumbnail named the following names, based on the dimensions of the [thumbnailsSizes](#thumbnailsSizes)
- 1D: `image@300.jpg`
- 2D: `image@300x400.jpg`
```ts
thumbnailsSuffix <string>: '@'
```
### thumbnailsOnly
Wether to copy or not the original (full-sized) pictures to the destination folder. The full-sized pictures will be optimized in the destination folder. This option is useful if you only want to generate thumbnails without copying/optimizing the full-sized pictures.
```ts
thumbnailsOnly <boolean>: true
```
### smallerThumbnailsOnly
Whether to resize images to only sizes below their native width.
```ts
smallerThumbnailsOnly <boolean>: false
```
## Constants
PWA_ICONSTHUMBNAILSIZES:
```js
// Import in your webpack.mix.js file
const PWA_ICONSTHUMBNAILSIZES = require('laravel-mix-image-multisizer').PWA_ICONSTHUMBNAILSIZES;

// Definition
export const PWA_ICONSTHUMBNAILSIZES = [
    [72,72],
    [96,96],
    [128,128],
    [144,144],
    [152,152],
    [192,192],
    [384,384],
    [512,512]
];
```
PWA_SPLASHTHUMBNAILSIZES:
```js
// Import in your webpack.mix.js file
const PWA_ICONSTHUMBNAILSIZES = require('laravel-mix-image-multisizer').PWA_ICONSTHUMBNAILSIZES;

// Definition
export const PWA_ICONSTHUMBNAILSIZES = [
    [640, 1136],
    [750, 1334],
    [828, 1792],
    [1125, 2436],
    [1242, 2208],
    [1242, 2688],
    [1536, 2048],
    [1668, 2224],
    [1668, 2388],
    [2048, 2732]
];
```

## Examples

Basic example (copy/optimize images from source to destination folder):
```js
mix.imgs({
    source: 'resources/images/photos',
    destination: 'public/images/photos',
})
```

Process images in all environnements EXCEPT for 'production':
```js
mix.imgs({
    disable: process.env.NODE_ENV === 'production',
    // ...
})
```

Generate thumbnails without the full-sized source images:
```js
mix.imgs({
    source: 'resources/images/photos',
    destination: 'public/images/photos/thumbnails',
    thumbnailsSizes: [300, 600], // Generate thumbnails with 300px and 600px width.
    thumbnailsOnly: true, // Do not copy the original (full-sized) images over.
})
```

Use exported constants:
```js
const mix = require('laravel-mix');
const PWA_ICONSTHUMBNAILSIZES = require('laravel-mix-image-multisizer').PWA_ICONSTHUMBNAILSIZES;
const PWA_SPLASHTHUMBNAILSIZES = require('laravel-mix-image-multisizer').PWA_SPLASHTHUMBNAILSIZES;

// This set will create 6 square images of different sizes
mix.imgs({
    source: inputpath,
    destination: outputpath,
    thumbnailsSizes: PWA_ICONSTHUMBNAILSIZES,
});

// This set will create 6 images with different width and heights
mix.imgs({
    source: inputpath,
    destination: outputpath,
    thumbnailsSizes: PWA_SPLASHTHUMBNAILSIZES,
});
```

---
_Source: https://npm.io/package/laravel-mix-image-multisizer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
