1

I'm building a script that automates all my daily needs with one command line execution.

ImageMagick is used to compress / convert images. But after doing that task I want those images to be moved to another directory. Unfortunately I'm working on a windows machine ... my command move C:\Automatik\src\IMG\*.jpg C:\Automatik\dist\IMG\ didn't work via Node.js Command Prompt. It only works in CMD!

I need either a npm package or another command for doing this.

Maybe someone knows how to move files with ImageMagick? The -path-argument didn't work for me...

mogrify -format jpg -quality 85 src/IMG/*.*

Thanks in advance, Daniel

webprogrammer
  • 792
  • 15
  • 26
  • Might want to go have a look at [this](https://stackoverflow.com/questions/8579055/how-i-move-files-on-node-js) – Tachyon Jan 23 '18 at 12:59
  • @thezadmin thx for your reply. All I need is a shorthand command for my scripts-section in package.json. I don't want to write additional code (if that's possible ...). If I got it right I do have to write full code in JS to use `fs` or is there a CLI? – webprogrammer Jan 23 '18 at 13:05
  • As far as I know, since fs is a module within node it can only be called within node itself. – Tachyon Jan 23 '18 at 13:13
  • Thx @thezadmin I came up with the `ImageMagick` solution! – webprogrammer Jan 23 '18 at 13:46
  • 1
    See this [answer](https://stackoverflow.com/questions/14304480/batch-resize-images-and-output-images-to-new-folder-with-imagemagick#answer-18018161) which suggests the `-path` argument should work. I think the pertinent part to your issue is that the output directories you point to must exist (as per this [comment](https://stackoverflow.com/questions/14304480/batch-resize-images-and-output-images-to-new-folder-with-imagemagick#comment-57755244)). – RobC Jan 23 '18 at 14:00
  • @RobC thx for the hint! My mistake was in `ImageMagick` with setting the `-path` at the end ... It threw a `unrecognized method` error. You have to declare the path before setting the image(s) source(s). – webprogrammer Jan 23 '18 at 15:57

1 Answers1

1

For Windows it's a bit more tricky then on Unix-systems. But here's the solution with ImageMagick:

FOR %a in (src/IMG/*.png) DO mogrify -strip -path dist/IMG/ -format jpg -quality 85 src/IMG/%a

We do have to care about the syntax as -path at the end throws an error!

webprogrammer
  • 792
  • 15
  • 26