diff --git a/CHANGELOG.md b/CHANGELOG.md index 04b8bf0..bba4757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ 7. Added `coalesce` option to all commands 8. Added orientation to `info()` 9. Changed `resize()` to not auto-set height from width +10. Added `getImageMagickVersion()` +11. Rewrote tests to be more clear + 2.2.0 - 10-01-2018 ------------------ diff --git a/README.md b/README.md index 95af25b..ed22c45 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,10 @@ any of the parameters defined on `IBaseOptions`. For example, to prevent EasyIma command. Every command must have a `src` parameter. If you do not specify a `dst`, then a random file will be created. Be sure to clean up randomly created files by -either moving them to permanent storage, or deleting them. Some command have other required options. +either moving them to permanent storage, or deleting them. Some commands have other required options. -The examples below only specify the required arguments. See the [Docs](https://mrkmg.github.io/node-easyimage/index.html) for all available options for each -command. +The examples below only specify some of the available arguments. See the [Docs](https://mrkmg.github.io/node-easyimage/index.html) for all available options for +each command. ### Convert @@ -179,7 +179,7 @@ ImageMagick. ``` import {getImageMagickVersion} from "easyimage"; -const version = getImageMagickVersion(); +const version = await getImageMagickVersion(); ``` ## Error Handling diff --git a/docs/classes/baddestinationerror.html b/docs/classes/baddestinationerror.html index 08795ef..a3ea99b 100644 --- a/docs/classes/baddestinationerror.html +++ b/docs/classes/baddestinationerror.html @@ -1047,7 +1047,7 @@

constructor

  • Returns BadDestinationError

    diff --git a/docs/classes/imagemagickmissingerror.html b/docs/classes/imagemagickmissingerror.html index 52a6621..c5230fa 100644 --- a/docs/classes/imagemagickmissingerror.html +++ b/docs/classes/imagemagickmissingerror.html @@ -1047,7 +1047,7 @@

    constructor

  • Returns ImageMagickMissingError

    diff --git a/docs/classes/missingextensionerror.html b/docs/classes/missingextensionerror.html index c8ef300..63c7e09 100644 --- a/docs/classes/missingextensionerror.html +++ b/docs/classes/missingextensionerror.html @@ -1047,7 +1047,7 @@

    constructor

  • Parameters

    diff --git a/docs/classes/missingoptionserror.html b/docs/classes/missingoptionserror.html index 983977a..0add8ec 100644 --- a/docs/classes/missingoptionserror.html +++ b/docs/classes/missingoptionserror.html @@ -1047,7 +1047,7 @@

    constructor

  • Parameters

    diff --git a/docs/classes/unsupportederror.html b/docs/classes/unsupportederror.html index 37f59d1..962f1c0 100644 --- a/docs/classes/unsupportederror.html +++ b/docs/classes/unsupportederror.html @@ -1047,7 +1047,7 @@

    constructor

  • Parameters

    diff --git a/docs/globals.html b/docs/globals.html index 19517f9..50ad2d6 100644 --- a/docs/globals.html +++ b/docs/globals.html @@ -1005,9 +1005,9 @@

    Installation

    any of the parameters defined on IBaseOptions. For example, to prevent EasyImage from auto-orientating your image, you can pass autoOrient: false on any command.

    Every command must have a src parameter. If you do not specify a dst, then a random file will be created. Be sure to clean up randomly created files by - either moving them to permanent storage, or deleting them. Some command have other required options.

    -

    The examples below only specify the required arguments. See the Docs for all available options for each - command.

    + either moving them to permanent storage, or deleting them. Some commands have other required options.

    +

    The examples below only specify some of the available arguments. See the Docs for all available options for + each command.

    Convert

    The convert() command can convert an image file from one type to another.

    import {convert} from "easyimage";
    @@ -1092,7 +1092,7 @@ 

    Info

    ImageMagick.

    import {getImageMagickVersion} from "easyimage";
     
    -const version = getImageMagickVersion();
    +const version = await getImageMagickVersion();
     

    Error Handling

    There are 5 different types of errors that can be thrown.

      @@ -1191,7 +1191,7 @@

      convert

    • @@ -1219,7 +1219,7 @@

      crop

    • @@ -1247,7 +1247,7 @@

      execute

    • @@ -1281,7 +1281,7 @@

      getImageMagickVersion

    • @@ -1312,7 +1312,7 @@

      info

    • @@ -1343,7 +1343,7 @@

      rescrop

    • @@ -1371,7 +1371,7 @@

      resize

    • @@ -1399,7 +1399,7 @@

      rotate

    • @@ -1427,7 +1427,7 @@

      thumbnail

    • diff --git a/docs/index.html b/docs/index.html index c92d6c9..2d8ab51 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1005,9 +1005,9 @@

      Installation

      any of the parameters defined on IBaseOptions. For example, to prevent EasyImage from auto-orientating your image, you can pass autoOrient: false on any command.

      Every command must have a src parameter. If you do not specify a dst, then a random file will be created. Be sure to clean up randomly created files by - either moving them to permanent storage, or deleting them. Some command have other required options.

      -

      The examples below only specify the required arguments. See the Docs for all available options for each - command.

      + either moving them to permanent storage, or deleting them. Some commands have other required options.

      +

      The examples below only specify some of the available arguments. See the Docs for all available options for + each command.

      Convert

      The convert() command can convert an image file from one type to another.

      import {convert} from "easyimage";
      @@ -1092,7 +1092,7 @@ 

      Info

      ImageMagick.

      import {getImageMagickVersion} from "easyimage";
       
      -const version = getImageMagickVersion();
      +const version = await getImageMagickVersion();
       

      Error Handling

      There are 5 different types of errors that can be thrown.

        @@ -1192,7 +1192,7 @@

        convert

      • @@ -1220,7 +1220,7 @@

        crop

      • @@ -1248,7 +1248,7 @@

        execute

      • @@ -1282,7 +1282,7 @@

        getImageMagickVersion

      • @@ -1313,7 +1313,7 @@

        info

      • @@ -1344,7 +1344,7 @@

        rescrop

      • @@ -1372,7 +1372,7 @@

        resize

      • @@ -1400,7 +1400,7 @@

        rotate

      • @@ -1428,7 +1428,7 @@

        thumbnail

      • diff --git a/docs/interfaces/ibaseoptions.html b/docs/interfaces/ibaseoptions.html index b383983..dcd7379 100644 --- a/docs/interfaces/ibaseoptions.html +++ b/docs/interfaces/ibaseoptions.html @@ -1058,7 +1058,7 @@

        Optional autoOrient

        autoOrient: boolean
        @@ -1078,7 +1078,7 @@

        Optional background

        background: string
        @@ -1093,7 +1093,7 @@

        Optional coalesce

        coalesce: boolean
        @@ -1116,7 +1116,7 @@

        Optional dst

        dst: string
        @@ -1136,7 +1136,7 @@

        Optional flatten

        flatten: boolean
        @@ -1156,7 +1156,7 @@

        Optional quality

        quality: number
        @@ -1176,7 +1176,7 @@

        src

        src: string
        diff --git a/docs/interfaces/iconvertoptions.html b/docs/interfaces/iconvertoptions.html index 32946c3..dc4649e 100644 --- a/docs/interfaces/iconvertoptions.html +++ b/docs/interfaces/iconvertoptions.html @@ -1047,7 +1047,7 @@

        Optional autoOrient

        @@ -1068,7 +1068,7 @@

        Optional background

        @@ -1084,7 +1084,7 @@

        Optional coalesce

        @@ -1108,7 +1108,7 @@

        Optional dst

        @@ -1129,7 +1129,7 @@

        Optional flatten

        @@ -1150,7 +1150,7 @@

        Optional quality

        @@ -1171,7 +1171,7 @@

        src

        diff --git a/docs/interfaces/icropoptions.html b/docs/interfaces/icropoptions.html index 8f99ace..3989c17 100644 --- a/docs/interfaces/icropoptions.html +++ b/docs/interfaces/icropoptions.html @@ -1080,7 +1080,7 @@

        Optional autoOrient

        @@ -1101,7 +1101,7 @@

        Optional background

        @@ -1117,7 +1117,7 @@

        Optional coalesce

        @@ -1140,7 +1140,7 @@

        Optional cropHeight

        cropHeight: number
        @@ -1160,7 +1160,7 @@

        cropWidth

        cropWidth: number
        @@ -1175,7 +1175,7 @@

        Optional cropheight

        cropheight: number
        @@ -1194,7 +1194,7 @@

        Optional cropwidth

        cropwidth: number
        @@ -1214,7 +1214,7 @@

        Optional dst

        @@ -1235,7 +1235,7 @@

        Optional flatten

        @@ -1255,7 +1255,7 @@

        Optional gravity

        gravity: string
        @@ -1276,7 +1276,7 @@

        Optional quality

        @@ -1297,7 +1297,7 @@

        src

        @@ -1312,7 +1312,7 @@

        Optional x

        x: number
        @@ -1332,7 +1332,7 @@

        Optional y

        y: number
        diff --git a/docs/interfaces/idensity.html b/docs/interfaces/idensity.html index 80c49d6..42fced6 100644 --- a/docs/interfaces/idensity.html +++ b/docs/interfaces/idensity.html @@ -1021,7 +1021,7 @@

        x

        x: number
        @@ -1031,7 +1031,7 @@

        y

        y: number
        diff --git a/docs/interfaces/iimagemagickcommandresult.html b/docs/interfaces/iimagemagickcommandresult.html index e9e1b5b..bae5510 100644 --- a/docs/interfaces/iimagemagickcommandresult.html +++ b/docs/interfaces/iimagemagickcommandresult.html @@ -1021,7 +1021,7 @@

        stderr

        stderr: string
        @@ -1031,7 +1031,7 @@

        stdout

        stdout: string
        diff --git a/docs/interfaces/iinforesult.html b/docs/interfaces/iinforesult.html index a25df29..9286a37 100644 --- a/docs/interfaces/iinforesult.html +++ b/docs/interfaces/iinforesult.html @@ -1053,7 +1053,7 @@

        density

        density: IDensity
        @@ -1068,7 +1068,7 @@

        depth

        depth: number
        @@ -1083,7 +1083,7 @@

        height

        height: number
        @@ -1098,7 +1098,7 @@

        name

        name: string
        @@ -1113,7 +1113,7 @@

        orientation

        orientation: string
        @@ -1128,7 +1128,7 @@

        path

        path: string
        @@ -1143,7 +1143,7 @@

        size

        size: number
        @@ -1158,7 +1158,7 @@

        type

        type: string
        @@ -1173,7 +1173,7 @@

        Optional warnings

        warnings: string
        @@ -1188,7 +1188,7 @@

        width

        width: number
        diff --git a/docs/interfaces/irescropoptions.html b/docs/interfaces/irescropoptions.html index c1746d0..b27ead1 100644 --- a/docs/interfaces/irescropoptions.html +++ b/docs/interfaces/irescropoptions.html @@ -1095,7 +1095,7 @@

        Optional autoOrient

        Inherited from IBaseOptions.autoOrient

        Overrides IBaseOptions.autoOrient

        @@ -1117,7 +1117,7 @@

        Optional background

        Inherited from IBaseOptions.background

        Overrides IBaseOptions.background

        @@ -1134,7 +1134,7 @@

        Optional coalesce

        Inherited from IBaseOptions.coalesce

        Overrides IBaseOptions.coalesce

        @@ -1158,7 +1158,7 @@

        Optional cropHeight

        @@ -1179,7 +1179,7 @@

        cropWidth

        @@ -1195,7 +1195,7 @@

        Optional cropheight

        @@ -1215,7 +1215,7 @@

        Optional cropwidth

        @@ -1236,7 +1236,7 @@

        Optional dst

        Inherited from IBaseOptions.dst

        Overrides IBaseOptions.dst

        @@ -1258,7 +1258,7 @@

        Optional flatten

        Inherited from IBaseOptions.flatten

        Overrides IBaseOptions.flatten

        @@ -1279,7 +1279,7 @@

        Optional gravity

        @@ -1300,7 +1300,7 @@

        Optional height

        @@ -1321,7 +1321,7 @@

        Optional ignoreAspect

        Inherited from IResizeOptions.ignoreAspectRatio

        @@ -1342,7 +1342,7 @@

        Optional onlyDownscale

        Inherited from IResizeOptions.onlyDownscale

        @@ -1364,7 +1364,7 @@

        Optional quality

        Inherited from IBaseOptions.quality

        Overrides IBaseOptions.quality

        @@ -1386,7 +1386,7 @@

        src

        Inherited from IBaseOptions.src

        Overrides IBaseOptions.src

        @@ -1402,7 +1402,7 @@

        width

        @@ -1418,7 +1418,7 @@

        Optional x

        @@ -1439,7 +1439,7 @@

        Optional y

        diff --git a/docs/interfaces/iresizeoptions.html b/docs/interfaces/iresizeoptions.html index d835f7f..f972610 100644 --- a/docs/interfaces/iresizeoptions.html +++ b/docs/interfaces/iresizeoptions.html @@ -1068,7 +1068,7 @@

        Optional autoOrient

        @@ -1089,7 +1089,7 @@

        Optional background

        @@ -1105,7 +1105,7 @@

        Optional coalesce

        @@ -1129,7 +1129,7 @@

        Optional dst

        @@ -1150,7 +1150,7 @@

        Optional flatten

        @@ -1170,7 +1170,7 @@

        Optional height

        height: number
        @@ -1190,7 +1190,7 @@

        Optional ignoreAspectignoreAspectRatio: boolean

        @@ -1210,7 +1210,7 @@

        Optional onlyDownscaleonlyDownscale: boolean

        @@ -1231,7 +1231,7 @@

        Optional quality

        @@ -1252,7 +1252,7 @@

        src

        @@ -1267,7 +1267,7 @@

        width

        width: number
        diff --git a/docs/interfaces/irotateoptions.html b/docs/interfaces/irotateoptions.html index d6cf739..5f4a049 100644 --- a/docs/interfaces/irotateoptions.html +++ b/docs/interfaces/irotateoptions.html @@ -1051,7 +1051,7 @@

        Optional autoOrient

        @@ -1072,7 +1072,7 @@

        Optional background

        @@ -1088,7 +1088,7 @@

        Optional coalesce

        @@ -1111,7 +1111,7 @@

        degree

        degree: number
        @@ -1127,7 +1127,7 @@

        Optional dst

        @@ -1148,7 +1148,7 @@

        Optional flatten

        @@ -1169,7 +1169,7 @@

        Optional quality

        @@ -1190,7 +1190,7 @@

        src

        diff --git a/docs/interfaces/ithumbnailoptions.html b/docs/interfaces/ithumbnailoptions.html index 1c26a4f..27073b6 100644 --- a/docs/interfaces/ithumbnailoptions.html +++ b/docs/interfaces/ithumbnailoptions.html @@ -1071,7 +1071,7 @@

        Optional autoOrient

        @@ -1092,7 +1092,7 @@

        Optional background

        @@ -1108,7 +1108,7 @@

        Optional coalesce

        @@ -1132,7 +1132,7 @@

        Optional dst

        @@ -1153,7 +1153,7 @@

        Optional flatten

        @@ -1173,7 +1173,7 @@

        Optional gravity

        gravity: string
        @@ -1193,7 +1193,7 @@

        height

        height: number
        @@ -1208,7 +1208,7 @@

        Optional interpolate

        interpolate: string
        @@ -1224,7 +1224,7 @@

        Optional quality

        @@ -1245,7 +1245,7 @@

        src

        @@ -1260,7 +1260,7 @@

        width

        width: number
        @@ -1275,7 +1275,7 @@

        Optional x

        x: number
        @@ -1290,7 +1290,7 @@

        Optional y

        y: number
        diff --git a/lib/EasyImage.js b/lib/EasyImage.js deleted file mode 100644 index d309528..0000000 --- a/lib/EasyImage.js +++ /dev/null @@ -1,28 +0,0 @@ -"use strict"; -/* - EasyImage - - EasyImage is a promise-based image processing module - for Node.js, it is built on top of ImageMagick, so - make sure ImageMagick is installed on your system. - - Copyright (c) 2015 Hage Yaapa - Maintained by Kevin Gravier - - MIT License - */ -exports.__esModule = true; -var tslib_1 = require("tslib"); -tslib_1.__exportStar(require("./ImageMagick"), exports); -tslib_1.__exportStar(require("./Commands/info"), exports); -tslib_1.__exportStar(require("./Commands/crop"), exports); -tslib_1.__exportStar(require("./Commands/convert"), exports); -tslib_1.__exportStar(require("./Commands/resize"), exports); -tslib_1.__exportStar(require("./Commands/rotate"), exports); -tslib_1.__exportStar(require("./Commands/rescrop"), exports); -tslib_1.__exportStar(require("./Commands/thumbnail"), exports); -tslib_1.__exportStar(require("./Errors/BadDestinationError"), exports); -tslib_1.__exportStar(require("./Errors/ImageMagickMissingError"), exports); -tslib_1.__exportStar(require("./Errors/MissingExtensionError"), exports); -tslib_1.__exportStar(require("./Errors/MissingOptionsError"), exports); -tslib_1.__exportStar(require("./Errors/UnsupportedError"), exports); diff --git a/lib/Commands/convert.js b/lib/commands/convert.js similarity index 73% rename from lib/Commands/convert.js rename to lib/commands/convert.js index 5145da3..585370c 100644 --- a/lib/Commands/convert.js +++ b/lib/commands/convert.js @@ -14,8 +14,8 @@ var tslib_1 = require("tslib"); MIT License */ var Bluebird = require("bluebird"); -var Utilities_1 = require("../Utilities"); -var ImageMagick_1 = require("../ImageMagick"); +var utilities_1 = require("../utilities"); +var execute_1 = require("../execute"); var info_1 = require("./info"); Promise = Promise || Bluebird; /** @@ -30,15 +30,15 @@ function convert(options) { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: - Utilities_1.applyDefaultsToBaseOptions(options); - Utilities_1.checkForMissingOptions(options, ["src"]); - return [4 /*yield*/, Utilities_1.ensureDestinationDirectoryExists(options)]; + utilities_1.applyDefaultsToBaseOptions(options); + utilities_1.checkForMissingOptions(options, ["src"]); + return [4 /*yield*/, utilities_1.ensureDestinationDirectoryExists(options)]; case 1: _a.sent(); args = [options.src]; - Utilities_1.applyBaseOptionsToArgs(options, args); + utilities_1.applyBaseOptionsToArgs(options, args); args.push(options.dst); - return [4 /*yield*/, ImageMagick_1.execute("convert", args)]; + return [4 /*yield*/, execute_1.execute("convert", args)]; case 2: _a.sent(); return [2 /*return*/, info_1.info(options.dst)]; diff --git a/lib/Commands/crop.js b/lib/commands/crop.js similarity index 74% rename from lib/Commands/crop.js rename to lib/commands/crop.js index 5cc13f7..1047a1d 100644 --- a/lib/Commands/crop.js +++ b/lib/commands/crop.js @@ -14,8 +14,8 @@ exports.__esModule = true; var tslib_1 = require("tslib"); var Bluebird = require("bluebird"); -var Utilities_1 = require("../Utilities"); -var ImageMagick_1 = require("../ImageMagick"); +var utilities_1 = require("../utilities"); +var execute_1 = require("../execute"); var info_1 = require("./info"); Promise = Promise || Bluebird; /** @@ -30,21 +30,25 @@ function crop(options) { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: - Utilities_1.applyDefaultsToBaseOptions(options); + utilities_1.applyDefaultsToBaseOptions(options); upgradeCropOptions(options); applyDefaultsToCropOptions(options); - return [4 /*yield*/, Utilities_1.ensureDestinationDirectoryExists(options)]; + return [4 /*yield*/, utilities_1.ensureDestinationDirectoryExists(options)]; case 1: _a.sent(); - Utilities_1.checkForMissingOptions(options, ["src", "cropWidth"]); + utilities_1.checkForMissingOptions(options, ["src", "cropWidth"]); args = [options.src]; - Utilities_1.applyBaseOptionsToArgs(options, args); - cropDefinition = options.cropWidth + "x" + options.cropHeight + "+" + options.x + "+" + options.y; + utilities_1.applyBaseOptionsToArgs(options, args); + cropDefinition = "" + options.cropWidth; + if (options.cropHeight) { + cropDefinition += "x" + options.cropHeight; + } + cropDefinition += "+" + options.x + "+" + options.y; if (options.gravity) { args.push("-gravity", options.gravity); } args.push("-crop", cropDefinition, options.dst); - return [4 /*yield*/, ImageMagick_1.execute("convert", args)]; + return [4 /*yield*/, execute_1.execute("convert", args)]; case 2: _a.sent(); return [2 /*return*/, info_1.info(options.dst)]; diff --git a/lib/Commands/info.js b/lib/commands/info.js similarity index 93% rename from lib/Commands/info.js rename to lib/commands/info.js index 0a738fd..b8105d0 100644 --- a/lib/Commands/info.js +++ b/lib/commands/info.js @@ -14,8 +14,8 @@ exports.__esModule = true; var tslib_1 = require("tslib"); var Bluebird = require("bluebird"); -var ImageMagick_1 = require("../ImageMagick"); -var UnsupportedError_1 = require("../Errors/UnsupportedError"); +var execute_1 = require("../execute"); +var UnsupportedError_1 = require("../errors/UnsupportedError"); Promise = Promise || Bluebird; /** * Returns information about an image. @@ -30,7 +30,7 @@ function info(filePath) { switch (_b.label) { case 0: args = ["-format", "%m %z %w %h %b %x %y %[orientation] %f", filePath]; - return [4 /*yield*/, ImageMagick_1.execute("identify", args)]; + return [4 /*yield*/, execute_1.execute("identify", args)]; case 1: _a = _b.sent(), stdout = _a.stdout, stderr = _a.stderr; if (stdout === "") { diff --git a/lib/Commands/rescrop.js b/lib/commands/rescrop.js similarity index 80% rename from lib/Commands/rescrop.js rename to lib/commands/rescrop.js index b10501b..c27480d 100644 --- a/lib/Commands/rescrop.js +++ b/lib/commands/rescrop.js @@ -14,8 +14,8 @@ exports.__esModule = true; var tslib_1 = require("tslib"); var Bluebird = require("bluebird"); -var Utilities_1 = require("../Utilities"); -var ImageMagick_1 = require("../ImageMagick"); +var utilities_1 = require("../utilities"); +var execute_1 = require("../execute"); var info_1 = require("./info"); Promise = Promise || Bluebird; /** @@ -30,14 +30,14 @@ function rescrop(options) { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: - Utilities_1.applyDefaultsToBaseOptions(options); + utilities_1.applyDefaultsToBaseOptions(options); upgradeCropOptions(options); applyDefaultsToRescropOptions(options); - return [4 /*yield*/, Utilities_1.ensureDestinationDirectoryExists(options)]; + return [4 /*yield*/, utilities_1.ensureDestinationDirectoryExists(options)]; case 1: _a.sent(); args = [options.src]; - Utilities_1.applyBaseOptionsToArgs(options, args); + utilities_1.applyBaseOptionsToArgs(options, args); resizeDefinition = "" + options.width; if (options.height) { resizeDefinition += "x" + options.height; @@ -52,12 +52,16 @@ function rescrop(options) { resizeDefinition += ">"; } } - cropDefinition = options.cropWidth + "x" + options.cropHeight + "+" + options.x + "+" + options.y; + cropDefinition = "" + options.cropWidth; + if (options.cropHeight) { + cropDefinition += "x" + options.cropHeight; + } + cropDefinition += "+" + options.x + "+" + options.y; if (options.gravity) { args.push("-gravity", options.gravity); } args.push("-resize", resizeDefinition, "-crop", cropDefinition, options.dst); - return [4 /*yield*/, ImageMagick_1.execute("convert", args)]; + return [4 /*yield*/, execute_1.execute("convert", args)]; case 2: _a.sent(); return [2 /*return*/, info_1.info(options.dst)]; diff --git a/lib/Commands/resize.js b/lib/commands/resize.js similarity index 83% rename from lib/Commands/resize.js rename to lib/commands/resize.js index c865e01..d764504 100644 --- a/lib/Commands/resize.js +++ b/lib/commands/resize.js @@ -14,8 +14,8 @@ exports.__esModule = true; var tslib_1 = require("tslib"); var Bluebird = require("bluebird"); -var Utilities_1 = require("../Utilities"); -var ImageMagick_1 = require("../ImageMagick"); +var utilities_1 = require("../utilities"); +var execute_1 = require("../execute"); var info_1 = require("./info"); Promise = Promise || Bluebird; /** @@ -30,14 +30,14 @@ function resize(options) { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: - Utilities_1.checkForMissingOptions(options, ["src", "width"]); - Utilities_1.applyDefaultsToBaseOptions(options); + utilities_1.checkForMissingOptions(options, ["src", "width"]); + utilities_1.applyDefaultsToBaseOptions(options); applyDefaultsToResizeOptions(options); - return [4 /*yield*/, Utilities_1.ensureDestinationDirectoryExists(options)]; + return [4 /*yield*/, utilities_1.ensureDestinationDirectoryExists(options)]; case 1: _a.sent(); args = [options.src]; - Utilities_1.applyBaseOptionsToArgs(options, args); + utilities_1.applyBaseOptionsToArgs(options, args); resizeDefinition = "" + options.width; if (options.height) { resizeDefinition += "x" + options.height; @@ -53,7 +53,7 @@ function resize(options) { } } args.push("-resize", resizeDefinition, options.dst); - return [4 /*yield*/, ImageMagick_1.execute("convert", args)]; + return [4 /*yield*/, execute_1.execute("convert", args)]; case 2: _a.sent(); return [2 /*return*/, info_1.info(options.dst)]; diff --git a/lib/Commands/rotate.js b/lib/commands/rotate.js similarity index 74% rename from lib/Commands/rotate.js rename to lib/commands/rotate.js index f10337c..909bda2 100644 --- a/lib/Commands/rotate.js +++ b/lib/commands/rotate.js @@ -14,8 +14,8 @@ exports.__esModule = true; var tslib_1 = require("tslib"); var Bluebird = require("bluebird"); -var Utilities_1 = require("../Utilities"); -var ImageMagick_1 = require("../ImageMagick"); +var utilities_1 = require("../utilities"); +var execute_1 = require("../execute"); var info_1 = require("./info"); Promise = Promise || Bluebird; /** @@ -30,15 +30,15 @@ function rotate(options) { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: - Utilities_1.checkForMissingOptions(options, ["src", "degree"]); - Utilities_1.applyDefaultsToBaseOptions(options); - return [4 /*yield*/, Utilities_1.ensureDestinationDirectoryExists(options)]; + utilities_1.checkForMissingOptions(options, ["src", "degree"]); + utilities_1.applyDefaultsToBaseOptions(options); + return [4 /*yield*/, utilities_1.ensureDestinationDirectoryExists(options)]; case 1: _a.sent(); args = [options.src]; - Utilities_1.applyBaseOptionsToArgs(options, args); + utilities_1.applyBaseOptionsToArgs(options, args); args.push("-rotate", options.degree.toString(), options.dst); - return [4 /*yield*/, ImageMagick_1.execute("convert", args)]; + return [4 /*yield*/, execute_1.execute("convert", args)]; case 2: _a.sent(); return [2 /*return*/, info_1.info(options.dst)]; diff --git a/lib/Commands/thumbnail.js b/lib/commands/thumbnail.js similarity index 86% rename from lib/Commands/thumbnail.js rename to lib/commands/thumbnail.js index 3dfadcb..3144e3a 100644 --- a/lib/Commands/thumbnail.js +++ b/lib/commands/thumbnail.js @@ -14,8 +14,8 @@ exports.__esModule = true; var tslib_1 = require("tslib"); var Bluebird = require("bluebird"); -var Utilities_1 = require("../Utilities"); -var ImageMagick_1 = require("../ImageMagick"); +var utilities_1 = require("../utilities"); +var execute_1 = require("../execute"); var info_1 = require("./info"); Promise = Promise || Bluebird; /** @@ -30,19 +30,19 @@ function thumbnail(options) { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: - Utilities_1.applyDefaultsToBaseOptions(options); + utilities_1.applyDefaultsToBaseOptions(options); return [4 /*yield*/, applyDefaultsToThumbnailOptions(options)]; case 1: _a.sent(); - Utilities_1.checkForMissingOptions(options, ["src", "width", "height"]); - return [4 /*yield*/, Utilities_1.ensureDestinationDirectoryExists(options)]; + utilities_1.checkForMissingOptions(options, ["src", "width", "height"]); + return [4 /*yield*/, utilities_1.ensureDestinationDirectoryExists(options)]; case 2: _a.sent(); return [4 /*yield*/, info_1.info(options.src)]; case 3: infoData = _a.sent(); args = [options.src]; - Utilities_1.applyBaseOptionsToArgs(options, args); + utilities_1.applyBaseOptionsToArgs(options, args); if (options.gravity) { args.push("-gravity", options.gravity); } @@ -56,7 +56,7 @@ function thumbnail(options) { } args.push("-crop", options.width + "x" + options.height + "+" + options.x + "+" + options.y); args.push(options.dst); - return [4 /*yield*/, ImageMagick_1.execute("convert", args)]; + return [4 /*yield*/, execute_1.execute("convert", args)]; case 4: _a.sent(); return [2 /*return*/, info_1.info(options.dst)]; @@ -78,7 +78,7 @@ function applyDefaultsToThumbnailOptions(options) { options.y = 0; } if (!!options.interpolate) return [3 /*break*/, 2]; - return [4 /*yield*/, ImageMagick_1.getImageMagickVersion()]; + return [4 /*yield*/, execute_1.getImageMagickVersion()]; case 1: availableVersion = _a.sent(); switch (availableVersion) { diff --git a/lib/easyimage.js b/lib/easyimage.js new file mode 100644 index 0000000..a045c16 --- /dev/null +++ b/lib/easyimage.js @@ -0,0 +1,28 @@ +"use strict"; +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ +exports.__esModule = true; +var tslib_1 = require("tslib"); +tslib_1.__exportStar(require("./execute"), exports); +tslib_1.__exportStar(require("./commands/info"), exports); +tslib_1.__exportStar(require("./commands/crop"), exports); +tslib_1.__exportStar(require("./commands/convert"), exports); +tslib_1.__exportStar(require("./commands/resize"), exports); +tslib_1.__exportStar(require("./commands/rotate"), exports); +tslib_1.__exportStar(require("./commands/rescrop"), exports); +tslib_1.__exportStar(require("./commands/thumbnail"), exports); +tslib_1.__exportStar(require("./errors/BadDestinationError"), exports); +tslib_1.__exportStar(require("./errors/ImageMagickMissingError"), exports); +tslib_1.__exportStar(require("./errors/MissingExtensionError"), exports); +tslib_1.__exportStar(require("./errors/MissingOptionsError"), exports); +tslib_1.__exportStar(require("./errors/UnsupportedError"), exports); diff --git a/lib/Errors/BadDestinationError.js b/lib/errors/BadDestinationError.js similarity index 100% rename from lib/Errors/BadDestinationError.js rename to lib/errors/BadDestinationError.js diff --git a/lib/Errors/ImageMagickMissingError.js b/lib/errors/ImageMagickMissingError.js similarity index 100% rename from lib/Errors/ImageMagickMissingError.js rename to lib/errors/ImageMagickMissingError.js diff --git a/lib/Errors/MissingExtensionError.js b/lib/errors/MissingExtensionError.js similarity index 100% rename from lib/Errors/MissingExtensionError.js rename to lib/errors/MissingExtensionError.js diff --git a/lib/Errors/MissingOptionsError.js b/lib/errors/MissingOptionsError.js similarity index 100% rename from lib/Errors/MissingOptionsError.js rename to lib/errors/MissingOptionsError.js diff --git a/lib/Errors/UnsupportedError.js b/lib/errors/UnsupportedError.js similarity index 100% rename from lib/Errors/UnsupportedError.js rename to lib/errors/UnsupportedError.js diff --git a/lib/ImageMagick.js b/lib/execute.js similarity index 97% rename from lib/ImageMagick.js rename to lib/execute.js index e669c87..2f0b2bb 100644 --- a/lib/ImageMagick.js +++ b/lib/execute.js @@ -15,8 +15,8 @@ exports.__esModule = true; var tslib_1 = require("tslib"); var Bluebird = require("bluebird"); var child_process_1 = require("child_process"); -var ImageMagickMissingError_1 = require("./Errors/ImageMagickMissingError"); -var UnsupportedError_1 = require("./Errors/UnsupportedError"); +var ImageMagickMissingError_1 = require("./errors/ImageMagickMissingError"); +var UnsupportedError_1 = require("./errors/UnsupportedError"); Promise = Promise || Bluebird; var availableImageMagickVersion = null; /** diff --git a/lib/Options.js b/lib/options.js similarity index 100% rename from lib/Options.js rename to lib/options.js diff --git a/lib/Utilities.js b/lib/utilities.js similarity index 94% rename from lib/Utilities.js rename to lib/utilities.js index 409198b..02180eb 100644 --- a/lib/Utilities.js +++ b/lib/utilities.js @@ -18,9 +18,9 @@ var mkdirp = require("mkdirp"); var os_1 = require("os"); var path_1 = require("path"); var shortid_1 = require("shortid"); -var BadDestinationError_1 = require("./Errors/BadDestinationError"); -var MissingOptionsError_1 = require("./Errors/MissingOptionsError"); -var MissingExtensionError_1 = require("./Errors/MissingExtensionError"); +var BadDestinationError_1 = require("./errors/BadDestinationError"); +var MissingOptionsError_1 = require("./errors/MissingOptionsError"); +var MissingExtensionError_1 = require("./errors/MissingExtensionError"); Promise = Promise || Bluebird; function ensureDestinationDirectoryExists(options) { if (!options.dst) { diff --git a/package-lock.json b/package-lock.json index 4e6ae97..416cd97 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,27 @@ "integrity": "sha512-2nHw8pBp6J0N4mHPEO5GJptmd0KKjLFz/wpBiLMOT8UVnGqAP2e7P44wKVj+ujPvsFuIGyB2waDA3dpYX3c6Aw==", "dev": true }, + "@types/chai": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.0.tgz", + "integrity": "sha512-OuYBlXWHYthxIudMXMeQr92f6D97YoT9CUYCRb0BEP4OavC95jNcczjjr4Ob3H5E1IqlWqwj+leUZPSeth27Qw==", + "dev": true + }, + "@types/chai-as-promised": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.0.tgz", + "integrity": "sha512-MFiW54UOSt+f2bRw8J7LgQeIvE/9b4oGvwU7XW30S9QGAiHGnU/fmiOprsyMkdmH2rl8xSPc0/yrQw8juXU6bQ==", + "dev": true, + "requires": { + "@types/chai": "4.1.0" + } + }, + "@types/events": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@types/events/-/events-1.1.0.tgz", + "integrity": "sha512-y3bR98mzYOo0pAZuiLari+cQyiKk3UXRuT45h1RjhfeCzqkjaVsfZJNaxdgtk7/3tzOm1ozLTqEqMP3VbI48jw==", + "dev": true + }, "@types/fs-extra": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-4.0.0.tgz", @@ -19,6 +40,17 @@ "@types/node": "4.2.23" } }, + "@types/glob": { + "version": "5.0.34", + "resolved": "https://registry.npmjs.org/@types/glob/-/glob-5.0.34.tgz", + "integrity": "sha512-sUvpieq+HsWTLdkeOI8Mi8u22Ag3AoGuM3sv+XMP1bKtbaIAHpEA2f52K2mz6vK5PVhTa3bFyRZLZMqTxOo2Cw==", + "dev": true, + "requires": { + "@types/events": "1.1.0", + "@types/minimatch": "2.0.29", + "@types/node": "4.2.23" + } + }, "@types/handlebars": { "version": "4.0.31", "resolved": "https://registry.npmjs.org/@types/handlebars/-/handlebars-4.0.31.tgz", @@ -58,12 +90,28 @@ "@types/node": "4.2.23" } }, + "@types/mocha": { + "version": "2.2.46", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-2.2.46.tgz", + "integrity": "sha512-fwTTP5QLf4xHMkv7ovcKvmlLWX3GrxCa5DRQDOilVyYGCp+arZTAQJCy7/4GKezzYJjfWMpB/Cy4e8nrc9XioA==", + "dev": true + }, "@types/node": { "version": "4.2.23", "resolved": "https://registry.npmjs.org/@types/node/-/node-4.2.23.tgz", "integrity": "sha512-U6IchCNLRyswc9p6G6lxWlbE+KwAhZp6mGo6MD2yWpmFomhYmetK+c98OpKyvphNn04CU3aXeJrXdOqbXVTS/w==", "dev": true }, + "@types/rimraf": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@types/rimraf/-/rimraf-2.0.2.tgz", + "integrity": "sha512-Hm/bnWq0TCy7jmjeN5bKYij9vw5GrDFWME4IuxV08278NtU/VdGbzsBohcCUJ7+QMqmUq5hpRKB39HeQWJjztQ==", + "dev": true, + "requires": { + "@types/glob": "5.0.34", + "@types/node": "4.2.23" + } + }, "@types/shelljs": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/@types/shelljs/-/shelljs-0.7.0.tgz", @@ -79,6 +127,34 @@ "integrity": "sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=", "dev": true }, + "@types/sinon": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-4.1.3.tgz", + "integrity": "sha512-Xxn32Q3mAJHOMU20bxcT6HiPksUJEkZA+nyZS4NhLo8kKb8hLhkBgp5OeW/BI3+9QmdrvDRk3caYNqtYb+TEbA==", + "dev": true + }, + "@types/sinon-chai": { + "version": "2.7.29", + "resolved": "https://registry.npmjs.org/@types/sinon-chai/-/sinon-chai-2.7.29.tgz", + "integrity": "sha512-EkI/ZvJT4hglWo7Ipf9SX+J+R9htNOMjW8xiOhce7+0csqvgoF5IXqY5Ae1GqRgNtWCuaywR5HjVa1snkTqpOw==", + "dev": true, + "requires": { + "@types/chai": "4.1.0", + "@types/sinon": "4.1.3" + } + }, + "@types/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@types/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-FKjsOVbC6B7bdSB5CuzyHCkK69I=", + "dev": true + }, + "@types/strip-json-comments": { + "version": "0.0.30", + "resolved": "https://registry.npmjs.org/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz", + "integrity": "sha512-7NQmHra/JILCd1QqpSzl8+mJRc8ZHz3uDm8YV1Ks9IhK0epEiTw8aIErbvH9PI+6XbqhyIQy3462nEsn7UVzjQ==", + "dev": true + }, "align-text": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/align-text/-/align-text-0.1.4.tgz", @@ -96,6 +172,21 @@ "integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=", "dev": true }, + "ansi-styles": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.0.tgz", + "integrity": "sha512-NnSOmMEYtVR2JVMIGTzynRkkaxtiq1xnFBcdQD/DnNCYPoEPsVJhM98BDyaoNOQIi7p4okdi3E27eN7GQbsUug==", + "dev": true, + "requires": { + "color-convert": "1.9.1" + } + }, + "arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "dev": true + }, "assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", @@ -176,6 +267,17 @@ "check-error": "1.0.2" } }, + "chalk": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.3.0.tgz", + "integrity": "sha512-Az5zJR2CBujap2rqXGaJKaPHyJ0IrUimvYNX+ncCy8PJP4ltOGTrHUIo097ZaL2zMeKYpiCdqDvS6zdrTFok3Q==", + "dev": true, + "requires": { + "ansi-styles": "3.2.0", + "escape-string-regexp": "1.0.5", + "supports-color": "4.4.0" + } + }, "check-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", @@ -203,6 +305,21 @@ } } }, + "color-convert": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.1.tgz", + "integrity": "sha512-mjGanIiwQJskCC18rPR6OmrZ6fm2Lc7PeGFYwCmy5J34wC6F1PzdGL6xeMfmgicfYcNLGuVFA3WzXtIDCQSZxQ==", + "dev": true, + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", + "dev": true + }, "commander": { "version": "2.11.0", "resolved": "https://registry.npmjs.org/commander/-/commander-2.11.0.tgz", @@ -252,6 +369,15 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "formatio": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/formatio/-/formatio-1.2.0.tgz", + "integrity": "sha1-87IWfZBoxGmKjVH092CjmlTYGOs=", + "dev": true, + "requires": { + "samsam": "1.3.0" + } + }, "fs-extra": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz", @@ -331,6 +457,15 @@ "integrity": "sha1-5tnb5Xy+/mB1HwKvM2GVhwyQwB4=", "dev": true }, + "homedir-polyfill": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/homedir-polyfill/-/homedir-polyfill-1.0.1.tgz", + "integrity": "sha1-TCu8inWJmP7r9e1oWA921GdotLw=", + "dev": true, + "requires": { + "parse-passwd": "1.0.0" + } + }, "inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -359,6 +494,12 @@ "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", "dev": true }, + "isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", + "dev": true + }, "jsonfile": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", @@ -368,6 +509,12 @@ "graceful-fs": "4.1.11" } }, + "just-extend": { + "version": "1.1.27", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-1.1.27.tgz", + "integrity": "sha512-mJVp13Ix6gFo3SBAy9U/kL+oeZqzlYYYLQBwXVBlVzIsZwBqGREnOro24oC/8s8aox+rJhtZ2DiQof++IrkA+g==", + "dev": true + }, "kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", @@ -390,12 +537,30 @@ "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=", "dev": true }, + "lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk=", + "dev": true + }, + "lolex": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/lolex/-/lolex-2.3.1.tgz", + "integrity": "sha512-mQuW55GhduF3ppo+ZRUTz1PRjEh1hS5BbqU7d8D0ez2OKxHDod7StPPeAVKisZR5aLkHZjdGWSL42LSONUJsZw==", + "dev": true + }, "longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", "integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc=", "dev": true }, + "make-error": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.2.tgz", + "integrity": "sha512-l9ra35l5VWLF24y75Tg8XgfGLX0ueRhph118WKM6H5denx4bB5QF59+4UAm9oJ2qsPQZas/CQUDdtDdfvYHBdQ==", + "dev": true + }, "marked": { "version": "0.3.12", "resolved": "https://registry.npmjs.org/marked/-/marked-0.3.12.tgz", @@ -448,6 +613,27 @@ "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", "dev": true }, + "nise": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/nise/-/nise-1.2.0.tgz", + "integrity": "sha512-q9jXh3UNsMV28KeqI43ILz5+c3l+RiNW8mhurEwCKckuHQbL+hTJIKKTiUlCPKlgQ/OukFvSnKB/Jk3+sFbkGA==", + "dev": true, + "requires": { + "formatio": "1.2.0", + "just-extend": "1.1.27", + "lolex": "1.6.0", + "path-to-regexp": "1.7.0", + "text-encoding": "0.6.4" + }, + "dependencies": { + "lolex": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/lolex/-/lolex-1.6.0.tgz", + "integrity": "sha1-OpoCg0UqR9dDnnJzG54H1zhuSfY=", + "dev": true + } + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -467,6 +653,12 @@ "wordwrap": "0.0.3" } }, + "parse-passwd": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/parse-passwd/-/parse-passwd-1.0.0.tgz", + "integrity": "sha1-bVuTSkVpk7I9N/QKOC1vFmao5cY=", + "dev": true + }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -479,6 +671,15 @@ "integrity": "sha1-PBrfhx6pzWyUMbbqK9dKD/BVxME=", "dev": true }, + "path-to-regexp": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.7.0.tgz", + "integrity": "sha1-Wf3g9DW62suhA6hOnTvGTpa5k30=", + "dev": true, + "requires": { + "isarray": "0.0.1" + } + }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", @@ -534,6 +735,12 @@ "glob": "7.1.2" } }, + "samsam": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/samsam/-/samsam-1.3.0.tgz", + "integrity": "sha512-1HwIYD/8UlOtFS3QO3w7ey+SdSDFE4HRNLZoZRYVQefrOY3l17epswImeB1ijgJFQJodIaHcwkp3r/myBjFVbg==", + "dev": true + }, "shelljs": { "version": "0.7.8", "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.7.8.tgz", @@ -550,6 +757,38 @@ "resolved": "https://registry.npmjs.org/shortid/-/shortid-2.2.8.tgz", "integrity": "sha1-AzsRfWoul1gE9vCWnb59PQs1UTE=" }, + "sinon": { + "version": "4.1.6", + "resolved": "https://registry.npmjs.org/sinon/-/sinon-4.1.6.tgz", + "integrity": "sha1-nLNGvdsYDWioBEKf/hSXjX+v1ik=", + "dev": true, + "requires": { + "diff": "3.3.1", + "formatio": "1.2.0", + "lodash.get": "4.4.2", + "lolex": "2.3.1", + "nise": "1.2.0", + "supports-color": "5.1.0", + "type-detect": "4.0.6" + }, + "dependencies": { + "supports-color": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.1.0.tgz", + "integrity": "sha512-Ry0AwkoKjDpVKK4sV4h6o3UJmNRbjYm2uXhwfj3J56lMVdvnUNqzQVRztOOMGQ++w1K/TjNDFvpJk0F/LoeBCQ==", + "dev": true, + "requires": { + "has-flag": "2.0.0" + } + } + } + }, + "sinon-chai": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/sinon-chai/-/sinon-chai-2.14.0.tgz", + "integrity": "sha512-9stIF1utB0ywNHNT7RgiXbdmen8QDCRsrTjw+G9TgKt1Yexjiv8TOWZ6WHsTPz57Yky3DIswZvEqX8fpuHNDtQ==", + "dev": true + }, "source-map": { "version": "0.4.4", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.4.4.tgz", @@ -559,6 +798,35 @@ "amdefine": "1.0.1" } }, + "source-map-support": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.1.tgz", + "integrity": "sha512-EZNecLNrsdRk9fcdOcjjy+Z/id7cr68sdmsYtR1gA45oQ81Ccea0UvM7DdSRblO0Ie5zWX31bvJTC7Y3QZVujg==", + "dev": true, + "requires": { + "source-map": "0.6.1" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "dev": true + }, + "strip-json-comments": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", + "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "dev": true + }, "supports-color": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-4.4.0.tgz", @@ -568,6 +836,50 @@ "has-flag": "2.0.0" } }, + "text-encoding": { + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.6.4.tgz", + "integrity": "sha1-45mpgiV6J22uQou5KEXLcb3CbRk=", + "dev": true + }, + "ts-node": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-4.1.0.tgz", + "integrity": "sha512-xcZH12oVg9PShKhy3UHyDmuDLV3y7iKwX25aMVPt1SIXSuAfWkFiGPEkg+th8R4YKW/QCxDoW7lJdb15lx6QWg==", + "dev": true, + "requires": { + "arrify": "1.0.1", + "chalk": "2.3.0", + "diff": "3.3.1", + "make-error": "1.3.2", + "minimist": "1.2.0", + "mkdirp": "0.5.1", + "source-map-support": "0.5.1", + "tsconfig": "7.0.0", + "v8flags": "3.0.1", + "yn": "2.0.0" + }, + "dependencies": { + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "dev": true + } + } + }, + "tsconfig": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/tsconfig/-/tsconfig-7.0.0.tgz", + "integrity": "sha512-vZXmzPrL+EmC4T/4rVlT2jNVMWCi/O4DIiSj3UHg1OE5kCKbk4mfrXc6dZksLgRM/TZlKnousKH9bbTazUWRRw==", + "dev": true, + "requires": { + "@types/strip-bom": "3.0.0", + "@types/strip-json-comments": "0.0.30", + "strip-bom": "3.0.0", + "strip-json-comments": "2.0.1" + } + }, "tslib": { "version": "1.8.1", "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.8.1.tgz", @@ -657,6 +969,15 @@ "integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc=", "dev": true }, + "v8flags": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/v8flags/-/v8flags-3.0.1.tgz", + "integrity": "sha1-3Oj8N5wX2fLJ6e142JzgAFKxt2s=", + "dev": true, + "requires": { + "homedir-polyfill": "1.0.1" + } + }, "window-size": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/window-size/-/window-size-0.1.0.tgz", @@ -688,6 +1009,12 @@ "decamelize": "1.2.0", "window-size": "0.1.0" } + }, + "yn": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", + "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=", + "dev": true } } } diff --git a/package.json b/package.json index dc0d093..a29182e 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,12 @@ "version": "3.0.0", "description": "A promise-based, user-friendly module for processing images in Node.js", "license": "MIT", - "main": "lib/EasyImage.js", - "types": "types/EasyImage.d.ts", + "main": "lib/easyimage.js", + "types": "types/easyimage.d.ts", "scripts": { - "test": "cd test && mocha", + "test": "mocha -r ts-node/register --timeout 5000 test/specs/*spec.ts", "build": "npm run src && npm run doc", - "doc": "typedoc src/ImageMagick.ts src/Options.ts src/Commands/* src/Errors/*", + "doc": "typedoc src/execute.ts src/options.ts src/commands/* src/errors/*", "src": "tsc" }, "author": { @@ -46,13 +46,22 @@ }, "devDependencies": { "@types/bluebird": "^3.5.19", + "@types/chai": "^4.1.0", + "@types/chai-as-promised": "^7.1.0", "@types/mkdirp": "^0.5.2", + "@types/mocha": "^2.2.46", "@types/node": "=4", + "@types/rimraf": "^2.0.2", "@types/shortid": "0.0.29", + "@types/sinon": "^4.1.3", + "@types/sinon-chai": "^2.7.29", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", "mocha": "^4.1.0", - "rimraf": "^2.2.8", + "rimraf": "^2.6.2", + "sinon": "^4.1.6", + "sinon-chai": "^2.14.0", + "ts-node": "^4.1.0", "typedoc": "^0.9.0" } } diff --git a/src/EasyImage.ts b/src/EasyImage.ts deleted file mode 100644 index 3d349f3..0000000 --- a/src/EasyImage.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - EasyImage - - EasyImage is a promise-based image processing module - for Node.js, it is built on top of ImageMagick, so - make sure ImageMagick is installed on your system. - - Copyright (c) 2015 Hage Yaapa - Maintained by Kevin Gravier - - MIT License - */ - -export * from "./ImageMagick"; -export * from "./Commands/info"; -export * from "./Commands/crop"; -export * from "./Commands/convert"; -export * from "./Commands/resize"; -export * from "./Commands/rotate"; -export * from "./Commands/rescrop"; -export * from "./Commands/thumbnail"; - -export * from "./Errors/BadDestinationError"; -export * from "./Errors/ImageMagickMissingError"; -export * from "./Errors/MissingExtensionError"; -export * from "./Errors/MissingOptionsError"; -export * from "./Errors/UnsupportedError"; diff --git a/src/Commands/convert.ts b/src/commands/convert.ts similarity index 88% rename from src/Commands/convert.ts rename to src/commands/convert.ts index b76e6e6..3cec23c 100644 --- a/src/Commands/convert.ts +++ b/src/commands/convert.ts @@ -11,9 +11,9 @@ MIT License */ import * as Bluebird from "bluebird"; -import {IBaseOptions} from "../Options"; -import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../Utilities"; -import {execute} from "../ImageMagick"; +import {IBaseOptions} from "../options"; +import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../utilities"; +import {execute} from "../execute"; import {info, IInfoResult} from "./info"; Promise = Promise || Bluebird as any; diff --git a/src/Commands/crop.ts b/src/commands/crop.ts similarity index 88% rename from src/Commands/crop.ts rename to src/commands/crop.ts index 7166102..81f579a 100644 --- a/src/Commands/crop.ts +++ b/src/commands/crop.ts @@ -12,9 +12,9 @@ */ import * as Bluebird from "bluebird"; -import {IBaseOptions} from "../Options"; -import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../Utilities"; -import {execute} from "../ImageMagick"; +import {IBaseOptions} from "../options"; +import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../utilities"; +import {execute} from "../execute"; import {info, IInfoResult} from "./info"; Promise = Promise || Bluebird as any; @@ -38,7 +38,11 @@ export async function crop(options: ICropOptions): Promise { applyBaseOptionsToArgs(options, args); - const cropDefinition = options.cropWidth + "x" + options.cropHeight + "+" + options.x + "+" + options.y; + let cropDefinition = `${options.cropWidth}`; + if (options.cropHeight) { + cropDefinition += `x${options.cropHeight}`; + } + cropDefinition += `+${options.x}+${options.y}`; if (options.gravity) { args.push("-gravity", options.gravity); diff --git a/src/Commands/info.ts b/src/commands/info.ts similarity index 96% rename from src/Commands/info.ts rename to src/commands/info.ts index 63373ec..761192c 100644 --- a/src/Commands/info.ts +++ b/src/commands/info.ts @@ -12,8 +12,8 @@ */ import * as Bluebird from "bluebird"; -import {execute} from "../ImageMagick"; -import {UnsupportedError} from "../Errors/UnsupportedError"; +import {execute} from "../execute"; +import {UnsupportedError} from "../errors/UnsupportedError"; Promise = Promise || Bluebird as any; diff --git a/src/Commands/rescrop.ts b/src/commands/rescrop.ts similarity index 88% rename from src/Commands/rescrop.ts rename to src/commands/rescrop.ts index 1fe743e..30af872 100644 --- a/src/Commands/rescrop.ts +++ b/src/commands/rescrop.ts @@ -12,8 +12,8 @@ */ import * as Bluebird from "bluebird"; -import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs} from "../Utilities"; -import {execute} from "../ImageMagick"; +import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs} from "../utilities"; +import {execute} from "../execute"; import {info, IInfoResult} from "./info"; import {ICropOptions} from "./crop"; import {IResizeOptions} from "./resize"; @@ -51,7 +51,12 @@ export async function rescrop(options: IResCropOptions): Promise { } } - const cropDefinition = options.cropWidth + "x" + options.cropHeight + "+" + options.x + "+" + options.y; + let cropDefinition = `${options.cropWidth}`; + if (options.cropHeight) { + cropDefinition += `x${options.cropHeight}`; + } + cropDefinition += `+${options.x}+${options.y}`; + if (options.gravity) { args.push("-gravity", options.gravity); diff --git a/src/Commands/resize.ts b/src/commands/resize.ts similarity index 93% rename from src/Commands/resize.ts rename to src/commands/resize.ts index dbc833b..78f1c4a 100644 --- a/src/Commands/resize.ts +++ b/src/commands/resize.ts @@ -12,9 +12,9 @@ */ import * as Bluebird from "bluebird"; -import {IBaseOptions} from "../Options"; -import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../Utilities"; -import {execute} from "../ImageMagick"; +import {IBaseOptions} from "../options"; +import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../utilities"; +import {execute} from "../execute"; import {info, IInfoResult} from "./info"; Promise = Promise || Bluebird as any; diff --git a/src/Commands/rotate.ts b/src/commands/rotate.ts similarity index 89% rename from src/Commands/rotate.ts rename to src/commands/rotate.ts index fec41f2..f5c1529 100644 --- a/src/Commands/rotate.ts +++ b/src/commands/rotate.ts @@ -12,9 +12,9 @@ */ import * as Bluebird from "bluebird"; -import {IBaseOptions} from "../Options"; -import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../Utilities"; -import {execute} from "../ImageMagick"; +import {IBaseOptions} from "../options"; +import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../utilities"; +import {execute} from "../execute"; import {info, IInfoResult} from "./info"; Promise = Promise || Bluebird as any; diff --git a/src/Commands/thumbnail.ts b/src/commands/thumbnail.ts similarity index 93% rename from src/Commands/thumbnail.ts rename to src/commands/thumbnail.ts index 457a90e..fb67563 100644 --- a/src/Commands/thumbnail.ts +++ b/src/commands/thumbnail.ts @@ -12,9 +12,9 @@ */ import * as Bluebird from "bluebird"; -import {IBaseOptions} from "../Options"; -import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../Utilities"; -import {execute, getImageMagickVersion} from "../ImageMagick"; +import {IBaseOptions} from "../options"; +import {ensureDestinationDirectoryExists, applyDefaultsToBaseOptions, applyBaseOptionsToArgs, checkForMissingOptions} from "../utilities"; +import {execute, getImageMagickVersion} from "../execute"; import {info, IInfoResult} from "./info"; Promise = Promise || Bluebird as any; diff --git a/src/easyimage.ts b/src/easyimage.ts new file mode 100644 index 0000000..553e3a6 --- /dev/null +++ b/src/easyimage.ts @@ -0,0 +1,27 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +export * from "./execute"; +export * from "./commands/info"; +export * from "./commands/crop"; +export * from "./commands/convert"; +export * from "./commands/resize"; +export * from "./commands/rotate"; +export * from "./commands/rescrop"; +export * from "./commands/thumbnail"; + +export * from "./errors/BadDestinationError"; +export * from "./errors/ImageMagickMissingError"; +export * from "./errors/MissingExtensionError"; +export * from "./errors/MissingOptionsError"; +export * from "./errors/UnsupportedError"; diff --git a/src/Errors/BadDestinationError.ts b/src/errors/BadDestinationError.ts similarity index 100% rename from src/Errors/BadDestinationError.ts rename to src/errors/BadDestinationError.ts diff --git a/src/Errors/ImageMagickMissingError.ts b/src/errors/ImageMagickMissingError.ts similarity index 100% rename from src/Errors/ImageMagickMissingError.ts rename to src/errors/ImageMagickMissingError.ts diff --git a/src/Errors/MissingExtensionError.ts b/src/errors/MissingExtensionError.ts similarity index 100% rename from src/Errors/MissingExtensionError.ts rename to src/errors/MissingExtensionError.ts diff --git a/src/Errors/MissingOptionsError.ts b/src/errors/MissingOptionsError.ts similarity index 100% rename from src/Errors/MissingOptionsError.ts rename to src/errors/MissingOptionsError.ts diff --git a/src/Errors/UnsupportedError.ts b/src/errors/UnsupportedError.ts similarity index 100% rename from src/Errors/UnsupportedError.ts rename to src/errors/UnsupportedError.ts diff --git a/src/ImageMagick.ts b/src/execute.ts similarity index 95% rename from src/ImageMagick.ts rename to src/execute.ts index 9a82ee7..f58dbbf 100644 --- a/src/ImageMagick.ts +++ b/src/execute.ts @@ -13,8 +13,8 @@ import * as Bluebird from "bluebird"; import { execFile } from "child_process"; -import {ImageMagickMissingError} from "./Errors/ImageMagickMissingError"; -import {UnsupportedError} from "./Errors/UnsupportedError"; +import {ImageMagickMissingError} from "./errors/ImageMagickMissingError"; +import {UnsupportedError} from "./errors/UnsupportedError"; Promise = Promise || Bluebird as any; diff --git a/src/Options.ts b/src/options.ts similarity index 100% rename from src/Options.ts rename to src/options.ts diff --git a/src/Utilities.ts b/src/utilities.ts similarity index 92% rename from src/Utilities.ts rename to src/utilities.ts index a0f5138..73b6758 100644 --- a/src/Utilities.ts +++ b/src/utilities.ts @@ -17,10 +17,10 @@ import * as mkdirp from "mkdirp"; import {tmpdir} from "os"; import {dirname, extname} from "path"; import {generate} from "shortid"; -import {BadDestinationError} from "./Errors/BadDestinationError"; -import {IBaseOptions} from "./Options"; -import {MissingOptionsError} from "./Errors/MissingOptionsError"; -import {MissingExtensionError} from "./Errors/MissingExtensionError"; +import {BadDestinationError} from "./errors/BadDestinationError"; +import {IBaseOptions} from "./options"; +import {MissingOptionsError} from "./errors/MissingOptionsError"; +import {MissingExtensionError} from "./errors/MissingExtensionError"; Promise = Promise || Bluebird as any; diff --git a/test/files/tall.png b/test/files/tall.png new file mode 100644 index 0000000..949171a Binary files /dev/null and b/test/files/tall.png differ diff --git a/test/test.pdf b/test/files/test.pdf similarity index 100% rename from test/test.pdf rename to test/files/test.pdf diff --git a/test/files/wide.jpg b/test/files/wide.jpg new file mode 100644 index 0000000..3ed360e Binary files /dev/null and b/test/files/wide.jpg differ diff --git a/test/files/wide.png b/test/files/wide.png new file mode 100644 index 0000000..057e67f Binary files /dev/null and b/test/files/wide.png differ diff --git a/test/specs/convert.spec.ts b/test/specs/convert.spec.ts new file mode 100644 index 0000000..e1673d9 --- /dev/null +++ b/test/specs/convert.spec.ts @@ -0,0 +1,125 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +import "mocha"; +import * as chai from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import * as rimraf from "rimraf"; +import {mkdir, unlink} from "fs"; + +import {convert} from "../../src/commands/convert"; + +chai.use(chaiAsPromised); +chai.should(); + +const files = `${__dirname}/../files`; +const output = `${__dirname}/../output`; + +describe("convert command", () => { + beforeEach((done: () => void) => { + try { + mkdir(output, done); + } catch (e) { + done(); + } + }); + + afterEach((done: () => void) => { + rimraf(output, done); + }); + + describe("with image source", () => { + it("should convert to image", async () => { + const info = await convert({ + src: `${files}/wide.jpg`, + dst: `${output}/test.png`, + }); + + info.should.be.an("object"); + info.should.have.property("type"); + info.should.have.property("name"); + info.type.should.be.equal("png"); + info.name.should.be.equal("test.png"); + }); + + it("should convert to pdf", async () => { + const info = await convert({ + src: `${files}/wide.jpg`, + dst: `${output}/test.pdf`, + }); + + info.should.be.an("object"); + info.should.have.property("type"); + info.should.have.property("name"); + info.type.should.be.equal("pdf"); + info.name.should.be.equal("test.pdf"); + }); + }); + + describe("with pdf source", () => { + it("should convert one page to image", async () => { + const info = await convert({ + src: `${files}/test.pdf[1]`, + dst: `${output}/test.png`, + }); + + info.should.be.an("object"); + info.should.have.property("type"); + info.should.have.property("name"); + info.should.have.property("height"); + info.type.should.be.equal("png"); + info.name.should.be.equal("test.png"); + info.height.should.be.equal(792); + + }); + + it("should convert all pages to image", async () => { + const info = await convert({ + src: `${files}/test.pdf`, + dst: `${output}/test.png`, + }); + + info.should.be.an("object"); + info.should.have.property("type"); + info.should.have.property("name"); + info.should.have.property("height"); + info.type.should.be.equal("png"); + info.name.should.be.equal("test.png"); + info.height.should.be.equal(1584); + }); + }); + + describe("to temporary file", () => { + let fullPath: string = null; + afterEach((done: () => void) => { + if (fullPath) { + unlink(fullPath, done); + fullPath = null; + } + }); + + it("should create temporary dst file", async () => { + const info = await convert({ + src: `${files}/wide.jpg`, + }); + + fullPath = info.path; + + info.should.be.an("object"); + info.should.have.property("type"); + info.should.have.property("name"); + info.type.should.be.equal("jpeg"); + /EasyImage-.+\.jpg/.test(info.name).should.be.true; + }); + }); +}); diff --git a/test/specs/crop.spec.ts b/test/specs/crop.spec.ts new file mode 100644 index 0000000..81304da --- /dev/null +++ b/test/specs/crop.spec.ts @@ -0,0 +1,78 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +import "mocha"; +import * as chai from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import * as rimraf from "rimraf"; +import {mkdir} from "fs"; + +import {crop} from "../../src/commands/crop"; + +chai.use(chaiAsPromised); +chai.should(); + +const files = `${__dirname}/../files`; +const output = `${__dirname}/../output`; + +describe("crop command", () => { + beforeEach((done: () => void) => { + try { + mkdir(output, done); + } catch (e) { + done(); + } + }); + + afterEach((done: () => void) => { + rimraf(output, done); + }); + + describe("to square (only cropWidth)", () => { + it("should crop an image to smaller size", async () => { + const info = await crop({ + src: `${files}/wide.png`, + dst: `${output}/test.png`, + cropWidth: 50, + }); + + info.width.should.be.equal(50); + info.height.should.be.equal(50); + }); + + it("shouldn't crop to larger", async () => { + const info = await crop({ + src: `${files}/wide.png`, + dst: `${output}/test.png`, + cropWidth: 500, + }); + + info.width.should.be.equal(400); + info.height.should.be.equal(200); + }); + }); + + describe("to rectangle (both cropWidth and cropHeight)", () => { + it("should crop an image to smaller size", async () => { + const info = await crop({ + src: `${files}/wide.png`, + dst: `${output}/test.png`, + cropWidth: 50, + cropHeight: 75, + }); + + info.width.should.be.equal(50); + info.height.should.be.equal(75); + }); + }); +}); diff --git a/test/specs/easyimage.spec.ts b/test/specs/easyimage.spec.ts new file mode 100644 index 0000000..4ea002c --- /dev/null +++ b/test/specs/easyimage.spec.ts @@ -0,0 +1,65 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +import "mocha"; +import * as chai from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import * as EasyImage from "../../src/easyimage"; + +chai.use(chaiAsPromised); +chai.should(); + +describe("EasyImage Global", () => { + it("should be an object", () => { + EasyImage.should.be.an("object"); + }); + + it("should export helper functions", () => { + EasyImage.should.have.property("execute"); + EasyImage.should.have.property("getImageMagickVersion"); + + EasyImage.execute.should.be.a("function"); + EasyImage.getImageMagickVersion.should.be.a("function"); + }); + + it("should export commands", () => { + EasyImage.should.have.property("convert"); + EasyImage.should.have.property("crop"); + EasyImage.should.have.property("info"); + EasyImage.should.have.property("rescrop"); + EasyImage.should.have.property("resize"); + EasyImage.should.have.property("rotate"); + + EasyImage.convert.should.be.a("function"); + EasyImage.crop.should.be.a("function"); + EasyImage.info.should.be.a("function"); + EasyImage.rescrop.should.be.a("function"); + EasyImage.resize.should.be.a("function"); + EasyImage.rotate.should.be.a("function"); + + }); + + it("should export error constructors", () => { + EasyImage.should.have.property("BadDestinationError"); + EasyImage.should.have.property("ImageMagickMissingError"); + EasyImage.should.have.property("MissingExtensionError"); + EasyImage.should.have.property("MissingOptionsError"); + EasyImage.should.have.property("UnsupportedError"); + + EasyImage.BadDestinationError.should.be.a("function"); + EasyImage.ImageMagickMissingError.should.be.a("function"); + EasyImage.MissingExtensionError.should.be.a("function"); + EasyImage.MissingOptionsError.should.be.a("function"); + EasyImage.UnsupportedError.should.be.a("function"); + }); +}); diff --git a/test/specs/info.spec.ts b/test/specs/info.spec.ts new file mode 100644 index 0000000..e5d0510 --- /dev/null +++ b/test/specs/info.spec.ts @@ -0,0 +1,54 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +import "mocha"; +import * as chai from "chai"; +import * as chaiAsPromised from "chai-as-promised"; + +import {info} from "../../src/commands/info"; + +chai.use(chaiAsPromised); +chai.should(); + +const files = `${__dirname}/../files`; + +describe("info command", () => { + + it("should return all fields", async () => { + const fileInfo = await info(`${files}/wide.png`); + + fileInfo.should.be.an("object"); + fileInfo.should.have.property("type"); + fileInfo.should.have.property("depth"); + fileInfo.should.have.property("width"); + fileInfo.should.have.property("height"); + fileInfo.should.have.property("size"); + fileInfo.should.have.property("density"); + fileInfo.should.have.property("orientation"); + fileInfo.should.have.property("name"); + fileInfo.should.have.property("path"); + fileInfo.density.should.have.property("x"); + fileInfo.density.should.have.property("y"); + + fileInfo.type.should.equal("png"); + fileInfo.depth.should.equal(8); + fileInfo.width.should.equal(400); + fileInfo.height.should.equal(200); + fileInfo.size.should.closeTo(3565, 10); + fileInfo.density.x.should.equal(28.35); + fileInfo.density.y.should.equal(28.35); + fileInfo.orientation.should.equal("Undefined"); + fileInfo.name.should.equal("wide.png"); + fileInfo.path.should.equal(`${files}/wide.png`); + }); +}); diff --git a/test/specs/rescrop.spec.ts b/test/specs/rescrop.spec.ts new file mode 100644 index 0000000..5dffe48 --- /dev/null +++ b/test/specs/rescrop.spec.ts @@ -0,0 +1,53 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +import "mocha"; +import * as chai from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import * as rimraf from "rimraf"; +import {mkdir} from "fs"; + +import {rescrop} from "../../src/commands/rescrop"; + +chai.use(chaiAsPromised); +chai.should(); + +const files = `${__dirname}/../files`; +const output = `${__dirname}/../output`; + +describe("rescrop command", () => { + beforeEach((done: () => void) => { + try { + mkdir(output, done); + } catch (e) { + done(); + } + }); + + afterEach((done: () => void) => { + rimraf(output, done); + }); + + it("should resize and crop an image", async () => { + const info = await rescrop({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 100, + height: 100, + cropWidth: 50, + }); + + info.width.should.equal(50); + info.height.should.equal(50); + }); +}); diff --git a/test/specs/resize.spec.ts b/test/specs/resize.spec.ts new file mode 100644 index 0000000..20b1435 --- /dev/null +++ b/test/specs/resize.spec.ts @@ -0,0 +1,224 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +import "mocha"; +import * as chai from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import * as rimraf from "rimraf"; +import {mkdir} from "fs"; + +import {resize} from "../../src/commands/resize"; + +chai.use(chaiAsPromised); +chai.should(); + +const files = `${__dirname}/../files`; +const output = `${__dirname}/../output`; + +describe("resize command", () => { + beforeEach((done: () => void) => { + try { + mkdir(output, done); + } catch (e) { + done(); + } + }); + + afterEach((done: () => void) => { + rimraf(output, done); + }); + + describe("with keeping aspect ratio", async () => { + describe("with only width", () => { + it("should make smaller image", async () => { + const wideInfo = await resize({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 50, + }); + const tallInfo = await resize({ + src: `${files}/tall.png`, + dst: `${output}/tall.png`, + width: 50, + }); + + wideInfo.width.should.equal(50); + wideInfo.height.should.equal(25); + + tallInfo.width.should.equal(50); + tallInfo.height.should.equal(100); + }); + + it("should make larger image", async () => { + const wideInfo = await resize({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 500, + }); + const tallInfo = await resize({ + src: `${files}/tall.png`, + dst: `${output}/tall.png`, + width: 500, + }); + + wideInfo.width.should.equal(500); + wideInfo.height.should.equal(250); + + tallInfo.width.should.equal(500); + tallInfo.height.should.equal(1000); + }); + }); + + describe("with width and height", () => { + it("should make smaller image", async () => { + const wideInfo = await resize({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 100, + height: 100, + }); + const tallInfo = await resize({ + src: `${files}/tall.png`, + dst: `${output}/tall.png`, + width: 100, + height: 100, + }); + + wideInfo.width.should.equal(100); + wideInfo.height.should.equal(50); + + tallInfo.width.should.equal(50); + tallInfo.height.should.equal(100); + }); + + it("should make larger image", async () => { + const wideInfo = await resize({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 500, + height: 500, + }); + const tallInfo = await resize({ + src: `${files}/tall.png`, + dst: `${output}/tall.png`, + width: 500, + height: 500, + }); + + wideInfo.width.should.equal(500); + wideInfo.height.should.equal(250); + + tallInfo.width.should.equal(250); + tallInfo.height.should.equal(500); + }); + }); + }); + + describe("without keeping aspect ratio", async () => { + describe("with width and height", () => { + it("should make smaller image", async () => { + const wideInfo = await resize({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 100, + height: 100, + ignoreAspectRatio: true, + }); + const tallInfo = await resize({ + src: `${files}/tall.png`, + dst: `${output}/tall.png`, + width: 100, + height: 100, + ignoreAspectRatio: true, + }); + + wideInfo.width.should.equal(100); + wideInfo.height.should.equal(100); + + tallInfo.width.should.equal(100); + tallInfo.height.should.equal(100); + }); + + it("should make larger image", async () => { + const wideInfo = await resize({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 500, + height: 500, + ignoreAspectRatio: true, + }); + const tallInfo = await resize({ + src: `${files}/tall.png`, + dst: `${output}/tall.png`, + width: 500, + height: 500, + ignoreAspectRatio: true, + }); + + wideInfo.width.should.equal(500); + wideInfo.height.should.equal(500); + + tallInfo.width.should.equal(500); + tallInfo.height.should.equal(500); + }); + }); + }); + + describe("with only downscaling", () => { + it("should make a smaller image", async () => { + const wideInfo = await resize({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 50, + height: 50, + onlyDownscale: true, + }); + const tallInfo = await resize({ + src: `${files}/tall.png`, + dst: `${output}/tall.png`, + width: 50, + height: 50, + onlyDownscale: true, + }); + + wideInfo.width.should.equal(50); + wideInfo.height.should.equal(25); + + tallInfo.width.should.equal(25); + tallInfo.height.should.equal(50); + }); + + it("shouldn't make larger image", async () => { + const wideInfo = await resize({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 500, + height: 500, + onlyDownscale: true, + }); + const tallInfo = await resize({ + src: `${files}/tall.png`, + dst: `${output}/tall.png`, + width: 500, + height: 500, + onlyDownscale: true, + }); + + wideInfo.width.should.equal(400); + wideInfo.height.should.equal(200); + + tallInfo.width.should.equal(200); + tallInfo.height.should.equal(400); + }); + }); +}); diff --git a/test/specs/rotate.spec.ts b/test/specs/rotate.spec.ts new file mode 100644 index 0000000..18a5c41 --- /dev/null +++ b/test/specs/rotate.spec.ts @@ -0,0 +1,51 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +import "mocha"; +import * as chai from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import * as rimraf from "rimraf"; +import {mkdir} from "fs"; + +import {rotate} from "../../src/commands/rotate"; + +chai.use(chaiAsPromised); +chai.should(); + +const files = `${__dirname}/../files`; +const output = `${__dirname}/../output`; + +describe("rotate command", () => { + beforeEach((done: () => void) => { + try { + mkdir(output, done); + } catch (e) { + done(); + } + }); + + afterEach((done: () => void) => { + rimraf(output, done); + }); + + it("should rotate an image", async () => { + const info = await rotate({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + degree: 90, + }); + + info.width.should.equal(200); + info.height.should.equal(400); + }); +}); diff --git a/test/specs/thumbail.spec.ts b/test/specs/thumbail.spec.ts new file mode 100644 index 0000000..3dd754e --- /dev/null +++ b/test/specs/thumbail.spec.ts @@ -0,0 +1,52 @@ +/* + EasyImage + + EasyImage is a promise-based image processing module + for Node.js, it is built on top of ImageMagick, so + make sure ImageMagick is installed on your system. + + Copyright (c) 2015 Hage Yaapa + Maintained by Kevin Gravier + + MIT License + */ + +import "mocha"; +import * as chai from "chai"; +import * as chaiAsPromised from "chai-as-promised"; +import * as rimraf from "rimraf"; +import {mkdir} from "fs"; + +import {thumbnail} from "../../src/commands/thumbnail"; + +chai.use(chaiAsPromised); +chai.should(); + +const files = `${__dirname}/../files`; +const output = `${__dirname}/../output`; + +describe("thumbnail command", () => { + beforeEach((done: () => void) => { + try { + mkdir(output, done); + } catch (e) { + done(); + } + }); + + afterEach((done: () => void) => { + rimraf(output, done); + }); + + it("should create a thumbnail", async () => { + const info = await thumbnail({ + src: `${files}/wide.png`, + dst: `${output}/wide.png`, + width: 100, + height: 100, + }); + + info.width.should.equal(100); + info.height.should.equal(100); + }); +}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index 73b889b..0000000 --- a/test/test.js +++ /dev/null @@ -1,330 +0,0 @@ -var chai = require('chai'); -var chaiAsPromised = require('chai-as-promised'); -chai.use(chaiAsPromised); -chai.should(); -var assert = chai.assert; -var fs = require('fs'); -var rimraf = require('rimraf'); - -var outputDir = './output'; -if (!fs.existsSync(outputDir)) { - fs.mkdirSync(outputDir); -} - -var easyimg = require('../lib/EasyImage.js'); -var srcimg = 'kitten.jpg'; - -describe('.info - ', function () { - describe('valid file type', function () { - it('should show file info', function () { - return easyimg.info(srcimg).then(function (file) { - //console.log(file); - file.should.be.an('object'); - file.should.have.property('name'); - file.name.should.be.a('string'); - file.should.have.property('path'); - file.path.should.be.a('string'); - file.should.have.property('type'); - file.type.should.be.a('string'); - file.should.have.property('width'); - file.width.should.be.a('number'); - file.should.have.property('height'); - file.height.should.be.a('number'); - file.should.have.property('depth'); - file.depth.should.be.a('number'); - file.should.have.property('size'); - file.size.should.be.a('number'); - file.should.have.property('density'); - file.density.should.be.an('object'); - file.density.should.have.property('x'); - file.density.x.should.be.a('number'); - file.density.should.have.property('y'); - file.density.y.should.be.a('number'); - }) - }); - }); - - describe('invalid file type', function () { - it('should not be supported', function () { - return assert.isRejected(easyimg.info('./test.js'), "The issued command is unsupported"); - }); - }); - -}); - -describe('.convert -', function () { - - afterEach(function (done) { - fs.unlink(__dirname + '/output/convert.png', function () { - /* ignore any error unlinking */ - done(); - }); - }); - - it('should convert an image format to another', function () { - - return easyimg.convert({ - src: srcimg, - dst: __dirname + '/output/convert.png', - quality: 10 - }).then(function (file) { - file.should.be.a('object'); - file.should.have.property('type'); - file.type.should.be.equal('png'); - file.name.should.be.equal('convert.png'); - }); - }); - - it("should convert a multi-page pdf to a single image", function () { - return easyimg.convert({ - src: "test.pdf", - dst: __dirname + "/output/convert.png" - }).then(function (file) { - file.should.be.a('object'); - file.should.have.property('type'); - file.type.should.be.equal('png'); - file.name.should.be.equal('convert.png'); - file.height.should.be.equal(1584); - }); - }); - -}); - -describe('.rotate -', function () { - - afterEach(function (done) { - fs.unlink(__dirname + '/output/rotated.jpg', function () { - /* ignore any error unlinking */ - done(); - }); - }); - - it('should rotate the image by 90 degree', function () { - return easyimg.info(srcimg).then(function (info) { - info.should.have.property('width'); - info.should.have.property('height'); - - // Mainly check only if width and height are swapped - return easyimg.rotate({ - src: srcimg, - dst: __dirname + '/output/rotated.jpg', - degree: 90 - }).then(function (file) { - file.should.be.a('object'); - file.name.should.be.equal('rotated.jpg'); - file.should.have.property('width'); - file.width.should.be.equal(info.height); - file.height.should.be.equal(info.width); - }); - }) - }); - -}); - -describe('.resize -', function () { - - afterEach(function (done) { - fs.unlink(__dirname + '/output/resize.jpg', function () { - /* ignore any error unlinking */ - done(); - }); - }); - - it('should resize an image with preserved aspect ratio', function () { - return easyimg.resize({ - src: srcimg, - dst: __dirname + '/output/resize.jpg', - width: 640, - height: 400 - }).then(function (file) { - file.should.be.a('object'); - file.should.have.property('width'); - /* - * The original aspect ratio is equal ~1.333. - * Imagemagick calculates it with the lowest common - * denominator in our case the height, thats why it is - * preserved and width will be adjusted as follow - * 400 * 1.33 = ~533 - */ - file.width.should.be.equal(533); - file.height.should.be.equal(400); - file.name.should.be.equal('resize.jpg'); - }); - - }); - - it("should resize an image with ignored aspect ratio", function () { - return easyimg.resize({ - src: srcimg, - dst: __dirname + '/output/resize.jpg', - width: 640, - height: 400, - ignoreAspectRatio: true - }).then(function (file) { - file.should.be.a('object'); - file.should.have.property('width'); - file.width.should.be.equal(640); - file.height.should.be.equal(400); - file.name.should.be.equal('resize.jpg'); - }); - }); - - it("should resize a tall image to a specified width while maintaining aspect ratio", function () { - return easyimg.resize({ - src: "./yolo-tall.png", - dst: __dirname + '/output/resize.jpg', - width: 10 - }).then(function (file) { - file.should.be.a('object'); - file.should.have.property('width'); - file.width.should.be.equal(10); - file.height.should.be.equal(25); - file.name.should.be.equal('resize.jpg'); - }); - }); - - it("should not upscale an image if downscaleOnly is true", function () { - return easyimg.resize({ - src: srcimg, - dst: __dirname + '/output/resize.jpg', - width: 1000, - onlyDownscale: true - }).then(function (file) { - file.should.be.a('object'); - file.should.have.property('width'); - file.width.should.be.equal(800); - file.name.should.be.equal('resize.jpg'); - }); - }); -}); - -describe('.crop -', function () { - - afterEach(function (done) { - fs.unlink(__dirname + '/output/crop.jpg', function () { - /* ignore any error unlinking */ - done(); - }); - }); - - it('should crop an image', function () { - return easyimg.crop({ - src: srcimg, - dst: __dirname + '/output/crop.jpg', - cropwidth: 128, - cropheight: 128, - gravity: 'North', - x: 0, - y: 0 - }).then(function (file) { - file.should.be.a('object'); - file.should.have.property('width'); - file.width.should.be.equal(128); - file.name.should.be.equal('crop.jpg'); - }); - - }); - -}); - -describe('.rescrop -', function () { - - afterEach(function (done) { - fs.unlink(__dirname + '/output/rescrop.jpg', function () { - /* ignore any error unlinking */ - done(); - }); - }); - - it('should resize and crop', function () { - return easyimg.rescrop({ - src: srcimg, - dst: __dirname + '/output/rescrop.jpg', - width: 400, - height: 5400, - cropwidth: 100, - cropheight: 100, - x: 0, - y: 0 - }).then(function (file) { - file.should.be.a('object'); - file.should.have.property('width'); - file.width.should.be.equal(100); - file.name.should.be.equal('rescrop.jpg'); - }); - - }); - -}); - -describe('.thumbnail -', function () { - - afterEach(function (done) { - fs.unlink(__dirname + '/output/thumb nail.jpg', function () { - /* ignore any error unlinking */ - done(); - }); - }); - - //this.timeout(5000); - it('should generate a thumbnail', function () { - return easyimg.thumbnail({ - src: srcimg, - dst: __dirname + '/output/thumb nail.jpg', - width: 128, - height: 128, - x: 0, - y: 0 - }).then(function (file) { - file.should.be.a("object"); - file.should.have.property('width'); - file.width.should.be.equal(128); - file.name.should.be.equal('thumb nail.jpg'); - }); - - }); - -}); - -describe('.execute -', function () { - - afterEach(function (done) { - fs.unlink(__dirname + '/output/hello kitty.gif', function () { - /* ignore any error unlinking */ - done(); - }); - }); - - it('should invoke `convert` command', function () { - return easyimg.execute('convert', [srcimg, './output/hello\\ kitty.gif']); - - }); - -}); - -describe('additionals', function () { - - afterEach(function (done) { - rimraf(__dirname + '/output/foo/', function () { - done(); - }); - }); - - //this.timeout(5000); - it('should create directories if they do not exist', function () { - - return easyimg.thumbnail({ - src: srcimg, - dst: __dirname + '/output/foo/bar/hey.jpg', - width: 128, - height: 128, - x: 0, - y: 0 - }).then(function (file) { - file.should.be.a('object'); - file.name.should.be.equal('hey.jpg'); - }); - - }); - -}); diff --git a/test/yolo-tall.png b/test/yolo-tall.png deleted file mode 100644 index 81270a4..0000000 Binary files a/test/yolo-tall.png and /dev/null differ diff --git a/test/yolo.png b/test/yolo.png deleted file mode 100644 index 4fd82d1..0000000 Binary files a/test/yolo.png and /dev/null differ diff --git a/tsconfig.json b/tsconfig.json index ec4be99..ed11670 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,7 @@ "outDir": "./lib", "skipLibCheck": true, "importHelpers": true, - "lib": ["es2015"] + "lib": ["ES2015"] }, "include": ["./src/**/*"], "exclude": ["node_modules"] diff --git a/types/EasyImage.d.ts b/types/EasyImage.d.ts deleted file mode 100644 index f9bd396..0000000 --- a/types/EasyImage.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -export * from "./ImageMagick"; -export * from "./Commands/info"; -export * from "./Commands/crop"; -export * from "./Commands/convert"; -export * from "./Commands/resize"; -export * from "./Commands/rotate"; -export * from "./Commands/rescrop"; -export * from "./Commands/thumbnail"; -export * from "./Errors/BadDestinationError"; -export * from "./Errors/ImageMagickMissingError"; -export * from "./Errors/MissingExtensionError"; -export * from "./Errors/MissingOptionsError"; -export * from "./Errors/UnsupportedError"; diff --git a/types/Commands/convert.d.ts b/types/commands/convert.d.ts similarity index 87% rename from types/Commands/convert.d.ts rename to types/commands/convert.d.ts index 40824e4..6a77103 100644 --- a/types/Commands/convert.d.ts +++ b/types/commands/convert.d.ts @@ -1,4 +1,4 @@ -import { IBaseOptions } from "../Options"; +import { IBaseOptions } from "../options"; import { IInfoResult } from "./info"; /** * Converts an image from one format to another. diff --git a/types/Commands/crop.d.ts b/types/commands/crop.d.ts similarity index 95% rename from types/Commands/crop.d.ts rename to types/commands/crop.d.ts index c240470..9147e1b 100644 --- a/types/Commands/crop.d.ts +++ b/types/commands/crop.d.ts @@ -1,4 +1,4 @@ -import { IBaseOptions } from "../Options"; +import { IBaseOptions } from "../options"; import { IInfoResult } from "./info"; /** * Crops an image. diff --git a/types/Commands/info.d.ts b/types/commands/info.d.ts similarity index 100% rename from types/Commands/info.d.ts rename to types/commands/info.d.ts diff --git a/types/Commands/rescrop.d.ts b/types/commands/rescrop.d.ts similarity index 100% rename from types/Commands/rescrop.d.ts rename to types/commands/rescrop.d.ts diff --git a/types/Commands/resize.d.ts b/types/commands/resize.d.ts similarity index 94% rename from types/Commands/resize.d.ts rename to types/commands/resize.d.ts index 8ce4013..ddf0f00 100644 --- a/types/Commands/resize.d.ts +++ b/types/commands/resize.d.ts @@ -1,4 +1,4 @@ -import { IBaseOptions } from "../Options"; +import { IBaseOptions } from "../options"; import { IInfoResult } from "./info"; /** * Resizes an image. diff --git a/types/Commands/rotate.d.ts b/types/commands/rotate.d.ts similarity index 90% rename from types/Commands/rotate.d.ts rename to types/commands/rotate.d.ts index 5c5a96f..3f648a2 100644 --- a/types/Commands/rotate.d.ts +++ b/types/commands/rotate.d.ts @@ -1,4 +1,4 @@ -import { IBaseOptions } from "../Options"; +import { IBaseOptions } from "../options"; import { IInfoResult } from "./info"; /** * Rotates an image by a specified number of degrees. diff --git a/types/Commands/thumbnail.d.ts b/types/commands/thumbnail.d.ts similarity index 94% rename from types/Commands/thumbnail.d.ts rename to types/commands/thumbnail.d.ts index 27139d0..b075947 100644 --- a/types/Commands/thumbnail.d.ts +++ b/types/commands/thumbnail.d.ts @@ -1,4 +1,4 @@ -import { IBaseOptions } from "../Options"; +import { IBaseOptions } from "../options"; import { IInfoResult } from "./info"; /** * Creates a thumbnail of an image. diff --git a/types/easyimage.d.ts b/types/easyimage.d.ts new file mode 100644 index 0000000..a474cbe --- /dev/null +++ b/types/easyimage.d.ts @@ -0,0 +1,13 @@ +export * from "./execute"; +export * from "./commands/info"; +export * from "./commands/crop"; +export * from "./commands/convert"; +export * from "./commands/resize"; +export * from "./commands/rotate"; +export * from "./commands/rescrop"; +export * from "./commands/thumbnail"; +export * from "./errors/BadDestinationError"; +export * from "./errors/ImageMagickMissingError"; +export * from "./errors/MissingExtensionError"; +export * from "./errors/MissingOptionsError"; +export * from "./errors/UnsupportedError"; diff --git a/types/Errors/BadDestinationError.d.ts b/types/errors/BadDestinationError.d.ts similarity index 100% rename from types/Errors/BadDestinationError.d.ts rename to types/errors/BadDestinationError.d.ts diff --git a/types/Errors/ImageMagickMissingError.d.ts b/types/errors/ImageMagickMissingError.d.ts similarity index 100% rename from types/Errors/ImageMagickMissingError.d.ts rename to types/errors/ImageMagickMissingError.d.ts diff --git a/types/Errors/MissingExtensionError.d.ts b/types/errors/MissingExtensionError.d.ts similarity index 100% rename from types/Errors/MissingExtensionError.d.ts rename to types/errors/MissingExtensionError.d.ts diff --git a/types/Errors/MissingOptionsError.d.ts b/types/errors/MissingOptionsError.d.ts similarity index 100% rename from types/Errors/MissingOptionsError.d.ts rename to types/errors/MissingOptionsError.d.ts diff --git a/types/Errors/UnsupportedError.d.ts b/types/errors/UnsupportedError.d.ts similarity index 100% rename from types/Errors/UnsupportedError.d.ts rename to types/errors/UnsupportedError.d.ts diff --git a/types/ImageMagick.d.ts b/types/execute.d.ts similarity index 100% rename from types/ImageMagick.d.ts rename to types/execute.d.ts diff --git a/types/Options.d.ts b/types/options.d.ts similarity index 100% rename from types/Options.d.ts rename to types/options.d.ts diff --git a/types/Utilities.d.ts b/types/utilities.d.ts similarity index 90% rename from types/Utilities.d.ts rename to types/utilities.d.ts index 77e5f12..29204fe 100644 --- a/types/Utilities.d.ts +++ b/types/utilities.d.ts @@ -1,4 +1,4 @@ -import { IBaseOptions } from "./Options"; +import { IBaseOptions } from "./options"; export declare function ensureDestinationDirectoryExists(options: IBaseOptions): Promise<{}>; export declare function applyDefaultsToBaseOptions(options: IBaseOptions): void; export declare function applyBaseOptionsToArgs(options: IBaseOptions, args: string[]): void;