excellenteasy / grunt-image-resize

Unmaintained. If you'd like to take this over please let us know. Resizing images made easy - thanks to imagemagick.
MIT License
57 stars 46 forks source link

Fatal error: Cannot read property 'width' of undefined #9

Closed DavidKk closed 10 years ago

DavidKk commented 10 years ago

MAC AIR OS 10.8.4

Fatal error: Cannot read property 'width' of undefined

image

image

boennemann commented 10 years ago

Thanks for reporting David,

are you using the latest version of this plugin? We released 0.3.0 about a week ago and it should fix this issue (with imagemagick).

DavidKk commented 10 years ago

thx ^_^

johowie commented 10 years ago

I'm getting same error after processing the 10th image of a directory of 4000 images.

OS: OSX 10.9 imagemagick 6.8.7-0 grunt-image-resize: 0.3.0

here's grunt config:

image_resize: {
        options: {
            width: 100,
            height: 100,
            overwrite: true
        },
        organisms: {
            files: [{
                expand: true,
                src: ['../photos_src/organisms2/**/*.jpg'],
                dest: '../../photos/organisms/'
            }]

        }
    },
normanrz commented 10 years ago

Could you please run grunt image_resize:organisms --stack?

johowie commented 10 years ago

here's the output as requested $ grunt image_resize:organisms --stack

Running "image_resize:organisms" (image_resize) task

Image ../photos_src/organisms2/Genus_Acarnus^Species_bergquistae.jpg resized to ../../photos/photos_src/organisms2/Genus_Acarnus^Species_bergquistae.jpg Image ../photos_src/organisms2/Genus^Isolderopa^iangallowayi.jpg resized to ../../photos/photos_src/organisms2/Genus^Isolderopa^iangallowayi.jpg Image ../photos_src/organisms2/Genus_Acarnus^Species_caledoniensis.jpg resized to ../../photos/photos_src/organisms2/Genus_Acarnus^Species_caledoniensis.jpg Image ../photos_src/organisms2/Genus_Acanthostrongylophora^Species_ashmorica.jpg resized to ../../photos/photos_src/organisms2/Genus_Acanthostrongylophora^Species_ashmorica.jpg Image ../photos_src/organisms2/Encyocrypta^aureco^Raven.jpg resized to ../../photos/photos_src/organisms2/Encyocrypta^aureco^Raven.jpg Image ../photos_src/organisms2/Genus_Amblypodia^Species_cyronthe.jpg resized to ../../photos/photos_src/organisms2/Genus_Amblypodia^Species_cyronthe.jpg Image ../photos_src/organisms2/Encyocrypta^grandis^Raven.jpg resized to ../../photos/photos_src/organisms2/Encyocrypta^grandis^Raven.jpg Image ../photos_src/organisms2/Encyocrypta^aureco.jpg resized to ../../photos/photos_src/organisms2/Encyocrypta^aureco.jpg Image ../photos_src/organisms2/Encyocrypta_65.jpg resized to ../../photos/photos_src/organisms2/Encyocrypta_65.jpg Image ../photos_src/organisms2/Genus_Aegisocoris^Species_kormilevi.jpg resized to ../../photos/photos_src/organisms2/Genus_Aegisocoris^Species_kormilevi.jpg Fatal error: Cannot read property 'width' of undefined TypeError: Cannot read property 'width' of undefined at gm.module.exports (/Users/user/Documents/projectName/node_modules/grunt-image-resize/tasks/image_resize.js:73:44) at gm.EventEmitter.emit (events.js:106:17) at gm.Object.keys.forEach.proto.(anonymous function) (/Users/user/Documents/projectName/node_modules/grunt-image-resize/node_modules/gm/lib/getters.js:70:16) at cb (/Users/user/Documents/projectName/node_modules/grunt-image-resize/node_modules/gm/lib/command.js:264:16) at ChildProcess.module.exports.proto._spawn.proc.on.onExit (/Users/user/Documents/projectName/node_modules/grunt-image-resize/node_modules/gm/lib/command.js:246:9) at ChildProcess.EventEmitter.emit (events.js:99:17) at maybeClose (child_process.js:638:16) at Process._handle.onexit (child_process.js:680:5)

normanrz commented 10 years ago

I believe that Imagemagick has issues with reading/parsing one of your images. I just made a commit that outputs the original error and tells you which image is affected. Maybe you can try that.

dwilt commented 10 years ago

I'm currently having this issue as well.

thusoy commented 10 years ago

I'm seeing this as well. Suspected large images to be the issue (5600x3600), but it failed also on a smaller resized version (1200x768).

normanrz commented 10 years ago

By any chance, could you send me the image files? If I had some images where the error occurs, it would greatly help me debug.

thusoy commented 10 years ago

Sure, try this one: https://www.dropbox.com/s/xol3qq819cvewx9/_TKH4341.jpg

normanrz commented 10 years ago

I made a test for your image in https://github.com/excellenteasy/grunt-image-resize/tree/issue-9 It passes for me both on Mac OS and Ubuntu. Which version of ImageMagick are you running?

thusoy commented 10 years ago

Windows...

normanrz commented 10 years ago

I wasn't aware this runs on Windows, too. Anyways, I just tried it on a clean Win 8.1 and it passed aswell.

thusoy commented 10 years ago

Hmm, tested my setup on a Ubuntu box, still failing, so I can confirm that it's not a platform issue. Will dig a bit more.

normanrz commented 10 years ago

Have you tried the test suite or do you use your own Gruntfile? Maybe it's not an issue with the file after all.

thusoy commented 10 years ago

Got it working, not an issue with either the plugin or the file, was the ImageMagick install in my case. First time around I didn't have ImageMagick installed (you might want to add in the readme a little note saying you should have that installed and on the PATH), but installing it didn't solve the issue either, nor did relaunching cmd or a reboot. Much bantering back and forth, crashed on Ubuntu for other reasons (gruntfile fail), removed ImageMagick and re-installed, and then it started working.

So to others struggling, make sure ImageMagick is on your PATH and working (test it by typing convert -help and you should get a long list of possible options, and then it should work.

To make it a bit easier to spot stuff like this in the future, you should probably add some error checking to your function calls, this was the line 71 gm(filepath).size call that failed, and the error object was passed to your function (and the size arg was thus undefined), so checking for err before using size could have at least provided us with a ENOENT error, which is thus easier to backtrack to a failing spawn, which again hints towards ImageMagick. :relieved:

normanrz commented 10 years ago

Thanks so much for investigating. The error handling is already in the master branch but not yet on npm. Maybe it's a good time to publish a new version. I added a section to the Readme for setting up ImageMagick.

jeremybarbet commented 10 years ago

I had this issue as well. I succeeded to fix it with install imagemagick and create the $PATH to the folder.

netpoetica commented 10 years ago

I also had this issue, seemed to be fixed following a brew update (mac osx)

netpoetica commented 10 years ago

Interestingly, in another repo of mine I am still getting this issue regardless of the brew update, although it was fixed in another repo (using same version 0.3.0 in both).

ilovett commented 10 years ago

On Linux Mint/Ubuntu... I was getting this error, and I THOUGHT I had imagemagick installed, but it turns out I didn't... I saw the note on it maybe being related to images which are too big, so I set out manually resize it by installing imagemagick command line tool convert

sudo apt-get install imagemagick

Once I had imagemagick installed, that fixed the said problem for the larger size image (6315x4000 pixels)

GaryJones commented 10 years ago

Had the same problem after installing ImageMagick with Homebrew:

brew install imagemagick

Tried re-installing, and got a warning that it was already installed, but not linked.

Uninstalled with:

brew uninstall imagemagick

Then installed again:

brew install imagemagick

And got an error that the brew link step did not complete successfully. Followed the instructions and did:

brew link --overwrite imagemagick

It reported 71 symlinks were created.

Run grunt image_resize and this time it worked successfully.

caiobleggi commented 8 years ago

Thanks @thusoy for solving this on Windows.

Just complementing the solution for who doesn't know to change the imagemagick path on Windows 7+. Be sure to change only the C:/Program Files/ImageMagick-(version) path to your grunt.js folder. (In my case, had many others values on the PATH variable).

:clap::clap::sweat_smile: