aheckmann / gm

GraphicsMagick for node
http://aheckmann.github.com/gm/
6.95k stars 614 forks source link

Command failed: Invalid Parameter - -crop #779

Open MoeexT opened 5 years ago

MoeexT commented 5 years ago

New to node.js. Use gm for the first time. Encountered two problems:

  1. Could not execute GraphicsMagick/ImageMagick: gm "convert" "C:\Users\...\.jpg" "-crop" "2442x1853+0+0" "C:\Users\...\_1.jpg" this most likely means the gm/convert binaries can't be found. I solved this problem by using const gm = require('gm').subClass({imageMagick: true}); instead of const gm = require('gm');
  2. Then -> Command failed: Invalid Parameter - -crop, I searched for almost all solutions on stackOverflow and github issues. Still not solved until now.

Here is the code:

local_file.forEach((file) => {
        // file -> 'C:\Users\Administrator\桌面\photo-1551888419-c41351800459.jpg'
        let filename = file.split('\\')[file.split('\\').length-1].split('.')[0]
        let extension_name = file.split('\\')[file.split('\\').length-1].split('.')[1]
        let new_image = save_dir+filename+'_1.'+extension_name
        console.log(file)
        gm(file).crop(info.width, info.height, info.x, info.y).write(new_image, (err) => {
          console.log(new_image)
          console.error(err.message)
        })
      })

I installed "gm" by npm install -g gm. And "ImageMagick-7.0.8-Q16" is installed correctly. (with 'convert' option selected). Thanks!

synicalsyntax commented 5 years ago

For your second error about the Invalid Parameter, ran into a similar problem as well, and realized that it's because gm doesn't support ImageMagick v7 yet because "The "magick" command is the new primary command of the Shell API, replacing the old "convert" command."; there's a PR #774 open to fix it. Meanwhile, you'll have to downgrade to ImageMagick v6 and make sure to uninstall imageMagick v7 before trying again.