Giter Club home page Giter Club logo

node-imagemagick-cli's Introduction

node-imagemagick-cli

npm version CircleCI Build status codecov dependencies Status devDependencies Status Greenkeeper badge GuardRails badge

Access the ImageMagick CLI tools from Node. Cross-platform, with support for ImageMagick 6 and 7. Uses Node LTS.

Introduction

This library is designed to provide a safe and platform independent way of calling the ImageMagick CLI tools.

It is safe because it correctly deals with the Windows convert issue. It is platform independent because you don't have to worry about how it deals with the issue.

Ensure you are using the correct version of Node (for example with Node Version Manager:

nvm install --lts
nvm use --lts

Install with npm:

npm install --save imagemagick-cli

To call an ImageMagick CLI tool, just run:

const imagemagickCli = require('imagemagick-cli');
imagemagickCli.exec('convert -version');

This command will work consistently on MacOSX, Windows and Linux. On Windows, it will not conflict with the system installed convert.exe tool.

Compatibility

This libary is tested with the following platforms and ImageMagick versions:

Platform ImageMagick Version
OSX 6 ✅
OSX 7 ✅
Ubuntu 6 ✅
Ubuntu 7 ✅
Windows 6 ✅
Windows 7 ✅

API

Execute a command:

imagemagickCli
    .exec('convert -version')
    .then(({ stdout, stderr }) => {
        console.log(`Output: ${stdout}`);
    });

Check the ImageMagick version:

imagemagickCli
    .getVersion()
    .then((version) => {
        console.log(`Version: ${version}`);
    });

If the version cannot be identified (most likely because ImageMagick is not installed) then the function resolves with null.

Debugging

This library uses the node-debug module. To see low-level debugging information when using this library, set imagemagick-cli as part of the DEBUG environment variable:

DEBUG=imagemagick-cli node ./my-script.js

With debugging enabled, the full command sent to the CLI, as well as all stderr and stdout output is shown in the log.

Prior Art / Design Goals

I made this library to deal with some issues relating to Windows in the app-icon project, which I didn't have to deal with again in other projects (like app-splash.

There are some great and sophisticated modules around for working with IM:

I decided to create my own library because I don't need apis for ImageMagick in my use cases, just a platform agnostic way to call the CLI tools. The design goals for this project are that it allows you to run IM CLI tools without having to worry about platform or version nuances, that's it.

If you need more functionality I recommend looking into the projects above.

Coding

Ensure you are using the correct version of Node (for example with Node Version Manager:

nvm install --lts
nvm use --lts

Useful commands for development are:

Command Usage
npm test Runs the unit tests.
npm run test:debug Runs the tests in a debugger. Combine with .only and debugger for ease of debugging.
npm run cov Runs the tests, writing coverage reports to ./artifacts/coverage.
npm run lint Lint the code, using airbnb.

Creating a Release

To create a release.

  • Merge your work to master.
  • Use npm run release to bump and update the changelog
  • Push and deploy git push --follow-tags && npm publish

License

MIT

node-imagemagick-cli's People

Contributors

colomboe avatar dwmkerr avatar greenkeeper[bot] avatar guardrails[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

raschidjfr dyon42

node-imagemagick-cli's Issues

convert issue doesn't seem to be solved on windows

This code

const imagemagickCli = require('imagemagick-cli')

//...
//...

imagemagickCli
  .exec(`convert ${filename} -strip ${filename + '.min'}`)
  .then(({ stdout, stderr }) => {
    if (stderr) {
      callback(Error('Error compressing ' + filename + '. ' + stderr))
    } else {
      // removes original and renames
      fs.unlinkSync(filename)
      fs.renameSync(filename + '.min', filename)
    }
  }).catch(err => {
    callback(Error('Error compressing ' + filename + '. ' + err))
  })

return this on windows

Error: Error compressing D:\a\autocosts\autocosts\bin\public\favicon.png. Error: Failed to call 'convert D:\a\autocosts\autocosts\bin\public\favicon.png -strip D:\a\autocosts\autocosts\bin\public\favicon.png.min', which was mapped to '"C:\Windows\System32\convert.exe" D:\a\autocosts\autocosts\bin\public\favicon.png -strip D:\a\autocosts\autocosts\bin\public\favicon.png.min'. Error is 'Command failed: "C:\Windows\System32\convert.exe" D:\a\autocosts\autocosts\bin\public\favicon.png -strip D:\a\autocosts\autocosts\bin\public\favicon.png.min
Invalid Parameter - -strip
'.
    at D:\a\autocosts\autocosts\build\compressImages.js:39:17
    at D:\a\autocosts\autocosts\node_modules\async\dist\async.js:2955:19
    at wrapper (D:\a\autocosts\autocosts\node_modules\async\dist\async.js:268:20)
    at iteratorCallback (D:\a\autocosts\autocosts\node_modules\async\dist\async.js:493:17)
    at D:\a\autocosts\autocosts\node_modules\async\dist\async.js:321:20
    at D:\a\autocosts\autocosts\node_modules\async\dist\async.js:2953:17
    at D:\a\autocosts\autocosts\build\compressImages.js:130:11
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
npm ERR! Test failed.  See above for more details.
Error: Process completed with exit code 1.

How to automate installation in Windows

Hi, thanks for the great package

Since this is supposed to work in Windows, do you know how to automate the installation of imagemagick in Windows with command line. I need it, right, before using your module?

I need it for a Continuous Integration action

Dockerise Ubuntu Tests

Ubuntu tests could be much faster if dockerised, avoiding the need for a time consuming imagemagick installation.

An in-range update of sinon is breaking the build 🚨

The devDependency sinon was updated from 7.4.2 to 7.5.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

sinon is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests passed on CircleCI! (Details).
  • continuous-integration/appveyor/branch: AppVeyor build failed (Details).

Commits

The new version differs by 9 commits.

  • 7835301 Update docs/changelog.md and set new release id in docs/_config.yml
  • 4978898 Add release documentation for v7.5.0
  • 5d0adf7 7.5.0
  • c0e68b6 Update CHANGELOG.md and AUTHORS for new release
  • bf26967 Merge pull request #2080 from dpmott/issue-2006-Sinon.assert.calledOnceWithExactly
  • c3e9512 Merge branch '2027-apply-feedback'
  • 9c4bbf1 refactor: extract and share common tests for spies/stubs
  • fed2129 Proposed resolution to issue 2006
  • 181dcdd 2026 - Updated to support spying all methods on an object to similar to stub capabilities

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of mocha is breaking the build 🚨

The devDependency mocha was updated from 6.0.2 to 6.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

mocha is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: Your tests failed on CircleCI (Details).
  • continuous-integration/appveyor/branch: AppVeyor build succeeded (Details).

Release Notes for v6.1.0

6.1.0 / 2019-04-07

🔒 Security Fixes

  • #3845: Update dependency "js-yaml" to v3.13.0 per npm security advisory (@plroebuck)

🎉 Enhancements

  • #3766: Make reporter constructor support optional options parameter (@plroebuck)
  • #3760: Add support for config files with .jsonc extension (@sstephant)

📠 Deprecations

These are soft-deprecated, and will emit a warning upon use. Support will be removed in (likely) the next major version of Mocha:

🐛 Fixes

  • #3829: Use cwd-relative pathname to load config file (@plroebuck)
  • #3745: Fix async calls of this.skip() in "before each" hooks (@juergba)
  • #3669: Enable --allow-uncaught for uncaught exceptions thrown inside hooks (@givanse)

and some regressions:

📖 Documentation

🔩 Other

  • #3830: Replace dependency "findup-sync" with "find-up" for faster startup (@cspotcode)
  • #3799: Update devDependencies to fix many npm vulnerabilities (@XhmikosR)
Commits

The new version differs by 28 commits.

  • f4fc95a Release v6.1.0
  • bd29dbd update CHANGELOG for v6.1.0 [ci skip]
  • aaf2b72 Use cwd-relative pathname to load config file (#3829)
  • b079d24 upgrade deps as per npm audit fix; closes #3854
  • e87c689 Deprecate this.skip() for "after all" hooks (#3719)
  • 81cfa90 Copy Suite property "root" when cloning; closes #3847 (#3848)
  • 8aa2fc4 Fix issue 3714, hide pound icon showing on hover header on docs page (#3850)
  • 586bf78 Update JS-YAML to address security issue (#3845)
  • d1024a3 Update doc examples "tests.html" (#3811)
  • 1d570e0 Delete "/docs/example/chai.js"
  • ade8b90 runner.js: "self.test" undefined in Browser (#3835)
  • 0098147 Replace findup-sync with find-up for faster startup (#3830)
  • d5ba121 Remove "package" flag from sample config file because it can only be passes as CLI arg (#3793)
  • a3089ad update package-lock
  • 75430ec Upgrade yargs-parser dependency to avoid loading 2 copies of yargs

There are 28 commits in total.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

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.