Coder Social home page Coder Social logo

meta's Introduction

imagemin

Minify images seamlessly





Install

npm install imagemin

Usage

import imagemin from 'imagemin';
import imageminJpegtran from 'imagemin-jpegtran';
import imageminPngquant from 'imagemin-pngquant';

const files = await imagemin(['images/*.{jpg,png}'], {
	destination: 'build/images',
	plugins: [
		imageminJpegtran(),
		imageminPngquant({
			quality: [0.6, 0.8]
		})
	]
});

console.log(files);
//=> [{data: <Uint8Array 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]

API

imagemin(input, options?)

Returns Promise<object[]> in the format {data: Uint8Array, sourcePath: string, destinationPath: string}.

input

Type: string[]

File paths or glob patterns.

options

Type: object

destination

Type: string

Set the destination folder to where your files will be written. If no destination is specified, no files will be written.

plugins

Type: Array

The plugins to use.

glob

Type: boolean
Default: true

Enable globbing when matching file paths.

imagemin.buffer(data, options?)

Returns Promise<Uint8Array>.

data

Type: Uint8Array

The image data to optimize.

options

Type: object

plugins

Type: Array

Plugins to use.

Related

meta's People

Contributors

kevva avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

meta's Issues

Use AVA

Would be nice to use AVA on all our repos instead of Mocha, as it makes it a lot easier to do async tests.

Should do #15 first, or at the same time, as AVA requires Node.js 4.

State of imagemin 2023-04

After scanning issues & playing around a bit with:

  • imagemin-pnquant & pngquant-bin
  • imagemin-webp & webp-bin
  • bin-wrapper & bin-build

It appears to me that most of the GH issues fall into one of these categories:

  1. Outdated dependencies causing security warnings and requiring users to add yarn resolutions or npm overrides.
  2. OS-specific installation or build failures, often triggered during npm install due to the *-bin packages doing postinstalls.
  3. Requests to be able to use locally installed binaries

Of course there is also the issue of the bundled binaries not being up-to-date, and sometimes even different from the bundled source tar (pngquant-bin includes pngquant 2.2.12 as source and pngquant 2.2.16 pre-built on Linux). And the issue of many micro-dependencies stifling innovation on the end-user packages (imagemin-pngquant -> pngquant-bin -> bin-wrapper -> bin-build etc)

IMO the best way forward is:

  1. Not depending on packages outside of the imagemin organization that appear to be abandoned (although their repo's are not archived [yet], looking at bin-wrapper, bin-check bin-build & other deps formerly managed by kevva).
  2. Not doing automatic post-installs which default to fetching a dependency over the network. Some of the issues:
    • They can be disabled using --ignore-scripts
    • They can fail due to DNS issues or network configurations with whitelists where the source URL's are not allowed
    • They allow no flexibility in embedding the *-bin packages in other packages (ie exposing some kind of minimal JS API)
    • The download URL could be made to point to a malicious executable (unlikely but still)
  3. Defaulting to using the binary in PATH when available, and allowing a configuration option (eg executablePath) to override it. If both fail, then, and only then fetch binaries from remote (allowing a custom URL too for mirrors) and build from source as last resort. This partially moves the burden of maintaining binaries for every distro in the imagemin-* repo's. Yes, there could be incompatibilities in the version locally installed and the version tested against in the imagemin-* repo's. Still this can easily be solved by logging the version and a warning if compatibility may be partially compromised

Move repos

Move all imagemin affiliated repos to this organization.

gif2webp bin

I see github.com/imagemin is hosting many bin-wrapper for images (nice module btw).
I was wondering if you thought of adding gif2webp bin ? (since you already have cwebp).

I feel it is better that a github organization like github.com/imagemin host this repo (I would gladly PR to it if you need).

ES2015ify

We should ES2015ify all our repos and require Node.js 4. Also bump all dependencies while we're at it. We've already done many repos, but I think there's still some left.

Example: imagemin/zopflipng-bin@87f9f45

Anyone wanna take this on?

// @shinnn @1000ch

resize and crop

Hi first: bigbig thanks to everyone who made imagemin.

Is imagemin only about compression or would you consider adding a imagemin-resize and imagemin-crop plugin?

Tagline

Currently: "Minify images seamlessly"

I think we need something more memorable.

Suggestions:

  • Optimized for happiness
  • Makes everything better
  • For a faster web
  • Minifies images like there's no tomorrow
  • Why Have Cotton When You Can Have Imagemin?
  • You've Got Bloated Images. We've Got Imagemin.
  • Minifies images so you don't have to
  • Tense, Nervous, Minifying Images?
  • Behold the Power of Imagemin

Require Node.js 6?

I've been looking into updating several packages to reduce the amount of duplication in a typical imagemin installation, right now it's a bit all over the place.

I noticed some of the packages far down the tree are already requiring Node.js 6, e.g. import-lazy, is-jpg and semver-regex.

Should imagemin + plugins move to Node.js 6 as the min. required version?

I'm happy to put the leg work in for this.

Server

Create a imagemin server that takes some JSON with an URL and some options and optimizes the image. Should probably have some upload functionality too.

npm organisation

npm organisations are now free for open-source, so I made one for us: https://www.npmjs.com/org/imagemin

It turns out only the original publisher can add packages to the org, so I couldn't add most of our packages.

@kevva @shinnn @1000ch Can you please run this command so we can have all our packages in the npm org?

npm access grant read-write imagemin:developers imagemin;npm access grant read-write imagemin:developers imagemin-cli;npm access grant read-write imagemin:developers imagemin-pngquant;npm access grant read-write imagemin:developers imagemin-guetzli;npm access grant read-write imagemin:developers guetzli-bin;npm access grant read-write imagemin:developers mozjpeg-bin;npm access grant read-write imagemin:developers imagemin-svgo;npm access grant read-write imagemin:developers imagemin-pngcrush;npm access grant read-write imagemin:developers pngcrush-bin;npm access grant read-write imagemin:developers zopflipng-bin;npm access grant read-write imagemin:developers imagemin-optipng;npm access grant read-write imagemin:developers imagemin-gifsicle;npm access grant read-write imagemin:developers gifsicle-bin;npm access grant read-write imagemin:developers imagemin-mozjpeg;npm access grant read-write imagemin:developers imagemin-jpegtran;npm access grant read-write imagemin:developers cwebp-bin;npm access grant read-write imagemin:developers imagemin-zopfli;npm access grant read-write imagemin:developers imagemin-jpeg-recompress;npm access grant read-write imagemin:developers imagemin-webp;npm access grant read-write imagemin:developers imagemin-jpegoptim;npm access grant read-write imagemin:developers jpegoptim-bin;npm access grant read-write imagemin:developers imagemin-pngout;npm access grant read-write imagemin:developers jpeg-recompress-bin;npm access grant read-write imagemin:developers advpng-bin;npm access grant read-write imagemin:developers imagemin-advpng;npm access grant read-write imagemin:developers pngout-bin

Comment here when done.

imagemin packages widely depend on unmaintained npm packages

Lots of packages in this organization depend on some of the following npm packages:

Based on the last commit date, last npm version publish date, and lack of activity on PRs and issues, I believe these packages are unmaintained. Dependencies are very out of date and PRs are not merged: kevva/bin-build#20, kevva/bin-check#4, and kevva/exec-buffer#10.

These packages have almost a million downloads per week, largely because imagemin packages depend on them.

The packages are fairly simple. Would it be possible to fork them into this organization so they are maintained?

Bundle the source

I think we should switch to bundle the source in the package. That way we don't have to download the source from a potentially untrusted source or a source that might be down.

See: imagemin/pngquant-bin#80

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.