Code Monkey home page Code Monkey logo

grunt-smushit's Introduction

grunt-smushit Build Status

Grunt plugin to remove unnecessary bytes of PNG and JPG using reSmush.it

reSmush.it is a FREE alternative to Yahoo Smush.it (deprecated on March 2015). This tool provides a online way to optimize pictures size via a documented webservice.

Read more about reSmush.it

Prefer Gulp? gulp-smushit

Getting Started

This plugin requires Grunt 0.4.x

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-smushit --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-smushit');

The "smushit" task

Overview

In your project's Gruntfile, add a section named smushit to the data object passed into grunt.initConfig().

grunt.initConfig({
  smushit: {
    mygroup: {
      src: ['tests/img/**/*.png','tests/img/**/*.jpg'],
      dest: 'tests/img/min'
    }
  }
});

Options

options.service

Type: String Default value: null Call another service instead of Yahoo Smushit

options.verbose

Type: boolean Default value: true Show image compressing rate log

Usage Examples

Output Folder

Move your files to a target folder (should not be into the same).

grunt.initConfig({
  smushit: {

    // catch all files from a single folder
    group1: {
      src: 'tests/img',
      dest: 'tests/opt_img'
    },

    // filter by filetype
    group2: {
      src: ['tests/img/**/*.png','tests/img/**/*.jpg'],
      dest: 'tests/img/min'
    },

    // set each file
    group3:{
        src: ['tests/img/logo.png','tests/img/whatever.png'],
        dest: 'tests/img/min'
    }

  }
});

Replace files

Be safe to replace all of your old files with this option.

grunt.initConfig({
  smushit: {

    // a single directory
    group1: {
      src: 'tests/img'
    },

    // filter by filetype
    group2: {
      src: ['tests/img/**/*.png','tests/img/**/*.jpg']
    },

    //replace recursive
    group3: {
      src: ['tests/img/logo.png','tests/img/tellme.jpg']
    }

  }
});

Work with a nested folder

Recursively walk into folders and smushit files

grunt.initConfig({
  smushit: {

    // catch all files from a nested folder
    group1: {
      src: 'tests/nested/img',
      dest: 'tests/opt_img'
    },

    // filter files in a nested folder by filetype
    group2: {
      src: ['tests/nested/img/**/*.png','tests/nested/img/**/*.jpg'],
      dest: 'tests/opt_img'
    },

    // retrieve files in a nested folder by file name
    group3: {
      src: ['tests/nested/img/**/southpark.png','tests/nested/img/**/southpark.jpg'],
      dest: 'tests/opt_img'
    },
  }
});

Provide multiple source

Smushit one folder, or many of them

grunt.initConfig({
  smushit: {

    // catch all files from a nested folder
    group1: {
      src: ['tests/img1', 'tests/img2'],
      dest: 'tests/opt_img'
    },

    // filter files in a folder by filetype
    group2: {
      src: ['tests/img1/**/*.png','tests/img2/**/*.jpg'],
      dest: 'tests/opt_img'
    },

    // retrieve files in a folder by file name
    group3: {
      src: ['tests/img1/**/southpark.png','tests/img2/**/southpark.jpg'],
      dest: 'tests/opt_img'
    },
  }
});

Use of cwd

Provide your base directory

grunt.initConfig({
  smushit: {

    // src folder is 'tests/img' and dest is 'tests/opt_img'
    group1: {
      cwd: 'tests'
      expand: true,
      src: 'img',
      dest: 'tests/opt_img'
    },

    // multiple src folders: src folder is ['tests/img1', 'tests/img2'] and dest is 'tests/img/min'
    group2: {
      cwd: 'tests'
      expand: true,
      src: ['img1/**/*.png','img2/**/*.jpg'],
      dest: 'tests/img/min'
    },
  }
});

Your own service

There is an option that you can set your own image optimizer service. Its a good alternative if you don't want to wait for smush.it web service latency.

grunt.initConfig({
  smushit: {
    options: {
      service: 'http://myimgopt.com/exec'
    },
    mygroup: {
      src: ['tests/img/**/*.png','tests/img/**/*.jpg'],
      dest: 'tests/img/min'
    }
  }
});

Contributing

$ git clone git://github.com/heldr/grunt-smushit.git
$ cd grunt-smushit
$ npm install
$ npm test

NOTE: Be sure to keep up to date the plugin tests and jshint code quality.

Release History

  • 2015-09-05 v2.0.0 Use resmush.it due Yahoo Smushit deprecation
  • 2014-05-19 v1.3.0 Pass node-smushit options through grunt file
  • 2014-03-30 v1.2.1 Bugfix. Fixes issue 29
  • 2014-03-03   v1.2.0   Use cwd only for source files, following the grunt pattern
  • 2013-07-15   v1.1.0   Support nested folder structure, support for multiple source folders
  • 2013-07-15   v1.1.0   Enable the use of cwd parameter
  • 2013-06-16   v1.0.0   Rewrite task on top of grunt-init-gruntplugin
  • 2013-05-26   v0.4.2   Add support to different service #16

Credits

License

MIT License (c) Helder Santana

grunt-smushit's People

Contributors

evencheng avatar heldr avatar jeffreybarke avatar leecade avatar leobetosouza avatar rubenstolk avatar sboudrias avatar thiagofesta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

grunt-smushit's Issues

Smushing in different folder

So, I've started testing this, but realised that I'd need to name each file individually, rather than being able to just recursively moving/smushing an entire folder.

Is this something you're working on, or not interested in? (If it's not something you're interested in, I'm planning on working on it, since I need it =)

Grunt-smushit not smushing all images and corrupts images

Hi,

I'm having an issue when I try to smush a bunch of png's using this:

destination:{
    src:'path/to/unsmushed/images',
    dest:'different/path/to/smushed/images'
}

Grunt-smushit, successfully smushes a few images (1-5, kinda randomly). But sometimes some files are corrupted.

Increasing the delay parameter of the setTimeout in tasks/smushit.js (line 38) seems to fix this issue, but adds unwanted delay to the end of the smushit task.

Thank you for your help and Grunt plugin !

Option for "quieter" output?

I'd like to be able to configure whether to display the full file list while the task is running. In my case, we have dozens of files that are being compressed, and the deluge of output is not always useful for us. I'd like to see something like this (it doesn't have to be named verbose, but that seemed like a good enough name for the example):

...
  smushit: {
    options: {
      verbose: false
    },
    mygroup: {
      src: ['tests/img/**/*.png','tests/img/**/*.jpg'],
      dest: 'tests/img/min'
    }
  }
...

Wrong output directory created when using current directory pattern (./) in src

When using src patterns such as ./img instead of img, an extraneous g/ directory is created in the dest dir. I don't see why one src pattern is to be preferred over the other; both are valid paths and both should work.

This is essentially a duplicate of #28 that @dmcass opened. There is substance here, however his fix was incorrect. Instead of hardcoding a + 1 (cc764d9), it seems better to always path.normalize filepath in the same way that fileDir is normalized.

Won't generate compressed images

Hi,

Im new to node stuff but still im trying to use this grunt plugin.
When i run grunt it seams to run my original images folder, returning lines like this:

[grunt-smushit] New optimized file: images/dist/temp/themeGallery-02.jpg
[smushit] smushit completed: total 1, saving 0

When i check the destination folder grunt as recreated the folder structure but didn't create any image.

Am i missing something?

Regards.

Update to be grunt 0.4.x compatible

When I try to utilize the smushit task with grunt 0.4.0a, it fails:

Running "smushit:destination" (smushit) task
Warning: Cannot call method 'kindOf' of undefined Use --force to continue.

Aborted due to warnings.

Here's my [simplified] "Gruntfile.js" configuration:

module.exports = function(grunt) {
  grunt.initConfig({
    clean: {
      all: ['out/']
    },
    smushit: {
      destination: {
        src: ['in/*.png', 'in/*.jpg'],
        dest: 'out/'
      }
    }
  });

  // Load supplemental libraries
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-smushit');

  // Default task
  grunt.registerTask('default', ['clean', 'smushit']);
};

Single file replacement

Create test cases and support this task config:

grunt.initConfig({
  smushit: {

    // a single directory
    group1: {
      src: 'tests/img'
    },

    // filter by filetype
    group2: {
      src: ['tests/img/**/*.png','tests/img/**/*.jpg']
    },

    //replace recursive
    group3: {
      src: ['tests/img/logo.png','tests/img/tellme.jpg']
    }

  }
});

Combined move/smushit

An option with one/many input files (possibly a folder), with an output folder. This is to keep the source images unsmushed while working with them.

Tries to compress .svn-base files

I'm probably doing something wrong, but also this may be a bug.

Here's my config:

smushit: {
        group1: {
            cwd: '',
            expand: true,
            src: ['images/**/*.png'],
            dest: 'dist/images',
            ext: '.png'
        },
    },

The output is:

Running "smushit:group1" (smushit) task
[smushit] start smash dist/images/icons/.svn/prop-base/apple-touch-icon-114x114-precomposed.png.svn-base
[smushit] start smash dist/images/icons/.svn/prop-base/apple-touch-icon-144x144-precomposed.png.svn-base
[smushit] start smash dist/images/icons/.svn/prop-base/apple-touch-icon-72x72-precomposed.png.svn-base
[smushit] start smash dist/images/icons/.svn/prop-base/apple-touch-icon-precomposed.png.svn-base
[smushit] start smash dist/images/icons/.svn/text-base/apple-touch-icon-114x114-precomposed.png.svn-base
[smushit] start smash dist/images/icons/.svn/text-base/apple-touch-icon-144x144-precomposed.png.svn-base
[smushit] start smash dist/images/icons/.svn/text-base/apple-touch-icon-72x72-precomposed.png.svn-base
[smushit] start smash dist/images/icons/.svn/text-base/apple-touch-icon-precomposed.png.svn-base
[smushit] start smash dist/images/icons/apple-touch-icon-114x114-precomposed.png
[smushit] start smash dist/images/icons/apple-touch-icon-144x144-precomposed.png
[smushit] start smash dist/images/icons/apple-touch-icon-72x72-precomposed.png
[smushit] start smash dist/images/icons/apple-touch-icon-precomposed.png
[smushit] item: dist/images/icons/.svn/prop-base/apple-touch-icon-144x144-precomposed.png.svn-base error: Cannot determine the type, is this an image?
[smushit] item: dist/images/icons/.svn/prop-base/apple-touch-icon-precomposed.png.svn-base error: Cannot determine the type, is this an image?
[smushit] item: dist/images/icons/.svn/prop-base/apple-touch-icon-72x72-precomposed.png.svn-base error: Cannot determine the type, is this an image?
[smushit] item: dist/images/icons/.svn/prop-base/apple-touch-icon-114x114-precomposed.png.svn-base error: Cannot determine the type, is this an image?
[smushit] item: dist/images/icons/.svn/text-base/apple-touch-icon-114x114-precomposed.png.svn-base error: No savings
[smushit] item: dist/images/icons/.svn/text-base/apple-touch-icon-72x72-precomposed.png.svn-base error: No savings
[smushit] item: dist/images/icons/.svn/text-base/apple-touch-icon-144x144-precomposed.png.svn-base error: No savings
[smushit] item: dist/images/icons/.svn/text-base/apple-touch-icon-precomposed.png.svn-base error: No savings
[smushit] item: dist/images/icons/apple-touch-icon-114x114-precomposed.png saving: 49.17%
[smushit] item: dist/images/icons/apple-touch-icon-precomposed.png saving: 61.62%
[smushit] item: dist/images/icons/apple-touch-icon-72x72-precomposed.png saving: 61.82%
[smushit] item: dist/images/icons/apple-touch-icon-144x144-precomposed.png saving: 60.78%
[smushit] smushit completed: total 12, saving 4

If I use src: ['images/**/*.png', '!images/**.svn*] or something similar, it tells me that the !images path is not found.

Any thoughts?

Create service option

As reported on #16 , a grunt-smushit user must have the option to set your favorite service. The v1 release must cover it using the grunt options object.

grunt.initConfig({
  smushit: {
    options: {
      service: 'http://myimgopt.com/exec'
    },
    mygroup: {
      src: ['tests/img/**/*.png','tests/img/**/*.jpg'],
      dest: 'tests/img/min'
    }
  }
});

Linting tasks/smushit.js...ERROR

That has a problem in smushit.js:

$ grunt build
Running "jshint:files" (jshint) task
Linting tasks/smushit.js...ERROR
[L36:C1] Trailing whitespace.

Refusing to install grunt-smushit as a dependency of itself

grunt/grunt-smushit (master)
$ npm install grunt-smushit
npm WARN install Refusing to install grunt-smushit as a dependency of itself

And:

$ grunt
Running "jshint:files" (jshint) task
Linting tasks/smushit.js...ERROR
[L36:C1] Trailing whitespace.

Why that?Thanks.

Output Folder

Create test cases and support this config:

grunt.initConfig({
  smushit: {

    // catch all files from a single folder
    group1: {
      src: 'tests/img',
      dest: 'tests/opt_img'
    },

    // filter by filetype
    group2: {
      src: ['tests/img/**/*.png','tests/img/**/*.jpg'],
      dest: 'tests/img/min'
    },

    // set each file
    group3:{
        src: ['tests/img/logo.png','tests/img/whatever.png'],
        dest: 'tests/img/min'
    }

  }
});

Recreate folder structure in destination?

I like your task!
Is it possible to recreate the folder structure in the target folder when using:

destination:{
    src:'tests/img',
    dest:'tests/img/min'
},

Thanks in advance!

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

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.