npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

laravel-mix-simple-image-processing

v1.0.10

Published

A simple Laravel mix plugin to copy/minify/resize images

Downloads

634

Readme

Laravel Mix - Simple Image Processing

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

Installation & Usage

Installation of the npm package:

npm install --save-dev laravel-mix-simple-image-processing

Usage, in your webpack.mix.js:

let mix = require('laravel-mix')

require('laravel-mix-simple-image-processing')

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

Executing the module (the following exemple is for a "development" 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:

| Option | Type | Default value | Description | | --- | --- | --- | --- | | disable | Boolean | false | Wether or not to disable the execution of the plugin, can be used to disable the execution on specific environnements. | | source | String | 'resources/images' | Path to the folder containing the images that will be used as input of the processing functions (images in sub-folders are also included). | | destination | String | 'public/images' | Path to the folder where the images will be saved (with source-like sub-folders). | | processOriginalImage | Boolean | true | Wether or not to copy the original (full-sized) pictures in the destination folder. The full-sized pictures will be optimized in the destination folder. This option is useful if you only want to generate WebP files without copying the original files (by setting it to false). | | webp | Boolean | false | Wether or not to generate WebP images. An image with the WebP format will be generated for each picture processed in the destination folder (including for all thumbnails if thumbnailsWebp is not specified). | | thumbnailsSizes | Array[Int] | [] | A list of maximum-width (in pixel) thumbnail to generate. E.g. [300, 600] would generate 2 thumbnails for each image processed, one with a 300px width and one with a 600px width. The height of the images are calculated proportionally. The plugin will emit a warning for each value superior at the width of the source image. | | thumbnailsSuffix | String | '@' | Suffix to be used for thumbnail names, the thumbnail names are based on the template {img-name}{suffix}{width}.{img-extension}, for example image.jpg could generate a thumbnail named [email protected]. | | thumbnailsWebp | Boolean | false | Wether or not to generate thumbnails with a WebP extension. If not specified, will take the value of the webp parameter. | | thumbnailsWebpOnly | Boolean | false | Wether or not to keep thumbnails with their original extensions (when thumbnailsWebp is true). | | smallerThumbnailsOnly | Boolean | false | Whether or not to resize images to sizes below their native width. | | imageminPngquantOptions | Object | { quality: [0.3, 0.5] } | Options to pass to the imageminPngquant plugin. | | imageminWebpOptions | Object | { quality: 50 } | Options to pass to the imageminWebp plugin. |

Exemples

Basic exemple (copy/optimize images from source to destination folder):

mix.imgs({
    source: 'resources/images/photos',
    destination: 'public/images/photos',
})

Process images in all environnements EXCEPT for 'production':

mix.imgs({
    disable: process.env.NODE_ENV === 'production',
    // ...
})

Generate thumbnails without the full-sized source images:

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

Only generate WebP files (without images with their original extensions):

mix.imgs({
    source: 'resources/images/photos',
    destination: 'public/images/photos',
    processOriginalImage: false, // Do not copy the original (full-sized) images over.
    webp: true,
})

Only generate thumbnails with WebP formats:

mix.imgs({
    source: 'resources/images/photos',
    destination: 'public/images/webp-thumbnails',
    processOriginalImage: false,
    thumbnailsSizes: [300, 600],
    thumbnailsWebp: true,
    thumbnailsWebpOnly: true,
})

Other

This plugin was originally inspired by the laravel-mix-image-resizer (which didn't seem to be maintained).