1000ch / grunt-image

Optimize PNG, JPEG, GIF, SVG images with grunt task.
http://bit.ly/we-should-optimize-images
MIT License
204 stars 20 forks source link

xxx.jpg is not optimized #18

Closed webberig closed 8 years ago

webberig commented 9 years ago

Hi,

I'm trying to get grunt-image working in a project, but when I run grunt image, the task goes over all the files, but none of the files are actually being manipulated:

✗ web/img/media/photos/9_thumb.jpg is not optimized before=after=16.72 kB reduced=0 B(0%)

I tried this in 2 different configurations (Windows & Linux). This is my configuration:

image: {
        options: {
            pngquant: true,
            optipng: true,
            advpng: true,
            zopflipng: true,
            pngcrush: true,
            pngout: true,
            mozjpeg: true,
            jpegRecompress: true,
            jpegoptim: true,
            gifsicle: true,
            svgo: true
        },

        all: {                
            files: [{
                expand: true,
                cwd: 'web/img/',
                src: ['**/*.{png,jpg,gif,svg}'],
                dest: 'web/img/'
            }]
        }
    }
webberig commented 9 years ago

I've been trying to figure out what's going wrong. It appears the optimizers are returning errors: jpeg-recompress:

Command failed: /Users/mathieu/Projects/cupsandplates/node_modules/grunt-image/node_modules/jpeg-recompress-bin/vendor/jpeg-recompress --progressive --strip --quality medium --min 40 --max 80 /var/folders/tl/cncg336511b24qz74qhdpkqh0000gn/T/476e03cf-5e79-4474-8d10-820d4ec161d0.jpg /var/folders/tl/cncg336511b24qz74qhdpkqh0000gn/T/476e03cf-5e79-4474-8d10-820d4ec161d0.jpg
unrecognized flag --progressive

mozjpeg:

Command failed: /Users/mathieu/Projects/cupsandplates/node_modules/grunt-image/node_modules/mozjpeg/vendor/cjpeg -optimize -progressive -outfile /var/folders/tl/cncg336511b24qz74qhdpkqh0000gn/T/a4777044-7903-48fb-9c0c-fa51b0e1bdf3.jpg /var/folders/tl/cncg336511b24qz74qhdpkqh0000gn/T/a4777044-7903-48fb-9c0c-fa51b0e1bdf3.jpg
unknown option 'outfile /var/folders/tl/cncg336511b24qz74qhdpkqh0000gn/T/a4777044-7903-48fb-9c0c-fa51b0e1bdf3.jpg'

I appears those libraries have updated their CLI...

1000ch commented 9 years ago

@webberig Thank you for reporting. Would you tell me using grunt-image version?

webberig commented 9 years ago

Sure: Node: 0.12.7 grunt @0.4.5 grunt-image@1.0.5 ├── advpng-bin@2.0.2 ├── async@1.4.2 ├── chalk@1.1.0 ├── filesize@3.1.3 ├── gifsicle@3.0.1 ├── jpeg-recompress-bin@3.0.1 ├── jpegoptim-bin@2.0.1 ├── mkdirp@0.5.1 ├── mozjpeg@4.0.1 ├── optipng-bin@3.0.2 ├── pngcrush-bin@3.0.0 ├── pngout-bin@2.0.1 ├── pngquant-bin@3.0.0 ├── svgo@0.5.5 ├── tempfile@1.1.1 └── zopflipng-bin@3.0.1

1000ch commented 9 years ago

I published 1.0.6 which contains fix options for jpeg-recompress. The -outfile option for mozjpeg seems to be correct... Try again with 1.0.6? Please tell me if you get a problem.

webberig commented 9 years ago

Sorry, same result... I am now trying this on a Macbook.. I still get the error in mozjpeg:

Error: Command failed: /Users/mathieu/Projects/cupsandplates/node_modules/grunt-image/node_modules/mozjpeg/vendor/cjpeg -optimize -progressive -outfile /var/folders/tl/cncg336511b24qz74qhdpkqh0000gn/T/13329e07-62df-4e50-a56d-c6bd62d72a7c.jpg /var/folders/tl/cncg336511b24qz74qhdpkqh0000gn/T/13329e07-62df-4e50-a56d-c6bd62d72a7c.jpg
   /Users/mathieu/Projects/cupsandplates/node_modules/grunt-image/node_modules/mozjpeg/vendor/cjpeg: unknown option 'outfile /var/folders/tl/cncg336511b24qz74qhdpkqh0000gn/T/13329e07-62df-4e50-a56d-c6bd62d72a7c.jpg'
   usage: /Users/mathieu/Projects/cupsandplates/node_modules/grunt-image/node_modules/mozjpeg/vendor/cjpeg [switches] [inputfile]
   Switches (names may be abbreviated):
     -quality N[,...]   Compression quality (0..100; 5-95 is useful range)
     -grayscale     Create monochrome JPEG file
     -rgb           Create RGB JPEG file
     -optimize      Optimize Huffman table (smaller file, but slow compression, enabled by default)
     -progressive   Create progressive JPEG file (enabled by default)
     -baseline      Create baseline JPEG file (disable progressive coding)
     -targa         Input file is Targa format (usually not needed)
     -revert        Revert to standard defaults (instead of mozjpeg defaults)
     -fastcrush     Disable progressive scan optimization
     -dc-scan-opt   DC scan optimization mode
                    - 0 One scan for all components
                    - 1 One scan per component (default)
                    - 2 Optimize between one scan for all components and one scan for 1st component
                        plus one scan for remaining components
     -notrellis     Disable trellis optimization
     -trellis-dc    Enable trellis optimization of DC coefficients (default)
     -notrellis-dc  Disable trellis optimization of DC coefficients
     -tune-psnr     Tune trellis optimization for PSNR
     -tune-hvs-psnr Tune trellis optimization for PSNR-HVS (default)
     -tune-ssim     Tune trellis optimization for SSIM
     -tune-ms-ssim  Tune trellis optimization for MS-SSIM
   Switches for advanced users:
     -noovershoot   Disable black-on-white deringing via overshoot
     -arithmetic    Use arithmetic coding
     -dct int       Use integer DCT method (default)
     -dct fast      Use fast integer DCT (less accurate)
     -dct float     Use floating-point DCT method
     -quant-table N Use predefined quantization table N:
                    - 0 JPEG Annex K
                    - 1 Flat
                    - 2 Custom, tuned for MS-SSIM
                    - 3 ImageMagick table by N. Robidoux
                    - 4 Custom, tuned for PSNR-HVS
                    - 5 Table from paper by Klein, Silverstein and Carney
     -restart N     Set restart interval in rows, or in blocks with B
     -smooth N      Smooth dithered input (N=1..100 is strength)
     -maxmemory N   Maximum memory to use (in kbytes)
     -outfile name  Specify name for output file
     -memdst        Compress to memory instead of file (useful for benchmarking)
     -verbose  or  -debug   Emit debug output
     -version       Print version information and exit
   Switches for wizards:
     -qtables file  Use quantization tables given in file
     -qslots N[,...]    Set component quantization tables
     -sample HxV[,...]  Set component sampling factors
     -scans file    Create multi-scan JPEG per script file

Did you compare the versions of the binaries ? Do they match yours ?

ThomasChan commented 8 years ago

Hi, i got same problem: ✗ ../../static/img/about/001-1.png is not optimized before=after=140.93 KB reduced=0 B(0%)

here's my grunt config: grunt.iniConfig({ image: { options: { pngquant: true, optipng: true, zopflipng: true, advpng: true, jpegRecompress: true, jpegoptim: true, mozjpeg: true, gifsicle: true, svgo: true }, dynamic: { files: [{ expand: true, cwd: '../../static/img/', src: ['**/*.{png,jpg}'], dest: '../../static/img/' }] } } })

Node: 0.10.16 grunt @0.4.5 ├─┬ grunt-image@1.2.2 │ ├── advpng-bin@3.0.0 │ ├── async@1.5.2 │ ├── chalk@1.1.1 │ ├── filesize@3.2.1 │ ├── gifsicle@3.0.3 │ ├── jpeg-recompress-bin@3.0.1 │ ├── jpegoptim-bin@3.0.0 │ ├── mkdirp@0.5.1 │ ├── mozjpeg@4.1.1 │ ├── optipng-bin@3.1.0 │ ├── pngquant-bin@3.1.0 │ ├── svgo@0.6.1 │ ├── tempfile@1.1.1 │ └── zopflipng-bin@3.0.1

what do i do to run this success?

Taber64 commented 8 years ago

I'm also running into the same issues when it comes to optimizing jpgs.

images/fkc_sellpage_02.jpg is not optimized before=after=51.08 KB reduced=0 B(0%) grunt-cli v0.1.13 grunt v0.4.5

Taber64 commented 8 years ago

Just created a new directory and installed grunt-image fresh. Seems all the jpg installs are breaking

mozjpeg@4.1.1 postinstall /Users/taber/imageResize/node_modules/mozjpeg node lib/install.js

⚠ The /Users/taber/imageResize/node_modules/mozjpeg/vendor/cjpeg binary doesn't seem to work correctly ⚠ mozjpeg pre-build test failed ℹ compiling from source ✖ Error: autoreconf -fiv && ./configure --disable-shared --prefix="/Users/taber/imageResize/node_modules/mozjpeg/vendor" --bindir="/Users/taber/imageResize/node_modules/mozjpeg/vendor" --libdir="/Users/taber/imageResize/node_modules/mozjpeg/vendor" && make --jobs=8 && make install --jobs=8 Command failed: autoreconf -fiv /bin/sh: autoreconf: command not found

at ChildProcess.exithandler (child_process.js:202:12)
at emitTwo (events.js:100:13)
at ChildProcess.emit (events.js:185:7)
at maybeClose (internal/child_process.js:827:16)
at Socket.<anonymous> (internal/child_process.js:319:11)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at Pipe._onclose (net.js:475:12)

jpegoptim-bin@3.0.0 postinstall /Users/taber/imageResize/node_modules/jpegoptim-bin node lib/install.js

⚠ The /Users/taber/imageResize/node_modules/jpegoptim-bin/vendor/jpegoptim binary doesn't seem to work correctly ⚠ jpegoptim pre-build test failed ℹ compiling from source ✖ Error: ./configure --prefix="/Users/taber/imageResize/node_modules/jpegoptim-bin/vendor" --bindir="/Users/taber/imageResize/node_modules/jpegoptim-bin/vendor" && make install Command failed: ./configure --prefix="/Users/taber/imageResize/node_modules/jpegoptim-bin/vendor" --bindir="/Users/taber/imageResize/node_modules/jpegoptim-bin/vendor"

at ChildProcess.exithandler (child_process.js:202:12)
at emitTwo (events.js:100:13)
at ChildProcess.emit (events.js:185:7)
at maybeClose (internal/child_process.js:827:16)
at Socket.<anonymous> (internal/child_process.js:319:11)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at Pipe._onclose (net.js:475:12)
Taber64 commented 8 years ago

Resolved my issue by installing Homebrew http://brew.sh/ and running 'brew install jpeg'

1000ch commented 8 years ago

grunt-image does not overwrite the image file if not reduced than before. If all images are not optimized, then grunt-image does not work well. How about your cases?

hiulit commented 8 years ago

Yeah, after I installed jpeg via brew it "magically" worked, but otherwise it's still not working...