Skip to content

Simple REST api to make diff from images using resemble.js

Notifications You must be signed in to change notification settings

BobCashStory/Resemble-api

Repository files navigation

Resemble.js

Build Status Code Health Coverage Build Status NPM Downloads

Analyse and compare images with Javascript and HTML5. Read the doc here. Compatible with Node.js >8.


Get it

Clone this repo or use our docker image : cashstory/resemble-api

Docker

Run the docker machine the service is serve on the port 3000 .

Local

do npm i and then npm start make it serve on port 3000 .

Test it

the API is pretty simple :

POST on /diff your two images named image_1 and image_2 in option in the body you can use all options of Rasemble.js

curl --location --request POST 'localhost:3000/diff' \
--form 'image_1=@/Users/martind/Downloads/accounting_101_Evolution_du_CA.png' \
--form 'image_2=@/Users/martind/Downloads/accounting_101_Evolution_du_CA_1.png'

or POST with specific options (optional):

curl --location --request POST 'localhost:3000/diff' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--form 'image_1=@/Users/martind/Downloads/accounting_101_Evolution_du_CA.png' \
--form 'image_2=@/Users/martind/Downloads/accounting_101_Evolution_du_CA_1.png' \
--form 'options={
      "output": {
          "errorColor": {
              "red": 255,
              "green": 0,
              "blue": 255
          },
          "errorType": "movement",
          "transparency": 0.3,
          "largeImageThreshold": 1200,
          "useCrossOrigin": false,
          "outputDiff": true
      },
      "scaleToSameSize": true,
      "ignore": "antialiasing"
  }'

the api will return you a JSON object.

like this

{
    "diffImage": "BASE64 STRING",
    "score": {
        "misMatchPercentage": "0.20",
        "isSameDimensions": true,
        "dimensionDifference": {
            "width": 0,
            "height": 0
        }
    }
}

Only option

Just ask for the diff score with only=score :

curl --location --request POST 'localhost:3000/diff' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--form 'image_1=@/Users/martind/Downloads/accounting_101_Evolution_du_CA.png' \
--form 'image_2=@/Users/martind/Downloads/accounting_101_Evolution_du_CA_1.png' \
--form 'only=score'

and you get :

{
    "misMatchPercentage": "0.14",
    "isSameDimensions": true,
    "dimensionDifference": {
        "width": 0,
        "height": 0
    }
}

Just ask for the diff image with only=image :

curl --location --request POST 'localhost:3000/diff' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--form 'image_1=@/Users/martind/Downloads/accounting_101_Evolution_du_CA.png' \
--form 'image_2=@/Users/martind/Downloads/accounting_101_Evolution_du_CA_1.png' \
--form 'only=image'

and you get :

Diff Image exemple

About

Simple REST api to make diff from images using resemble.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •