Skip to content

API Wiki

dogghi no edited this page May 4, 2023 · 1 revision

Welcome to the IMGDiff Wiki! 📖

In this wiki you will find some infos on how to communicate with imgdiff api

Response format and errors

The API always replies with this format: {ok: bool, error: string, response: data} "response" is different for every method and contains the actual API response, before trying to read the response ALWAYS check if ok == true, if not you should check out the "error" parameter which contains the error generated from golang. Pay also attention to the HTTP Status Code since it will tell you if the problem was caused by the server code or by the parameters you passed

Image IDs

The API works by uploading an image, that will give you an Image ID that will be necessary to interact with the API later

Distance

Distance is a float indicating how different an image is from another one, so: the lower the distance is, the more similar two images are

Endpoints

/ (GET)

The root endpoint shows by default some infos regarding the server, it returns a json like this {version:string, endpoints:[]string, hashtypes:[]string} where "version" is the IMGDiff version, "endpoints" is a list of supported endpoints and "hashtypes" is a list of valid hashes that can be used in the /similarities endpoint

/upload (POST)

The upload endpoint accepts a multipart form with a key named "image" and a file as a value, the file must be an image so that the server can store its hashes and return its image_id, the response will always follow the basic format but the "response" key will be structured like this:

{
        "average_hash": "AAA8eOz///8=",
        "difference_hash": "DA4HPnfy8rA=",
        "median_hash": "AAAcYODv//8=",
        "color_moment_hash": [
            0.0028560631496505414,
            6.471420303817127e-7,
            9.538806590873181e-10,
            7.246366686315828e-10,
            4.65528481492347e-19,
            -5.479740008410095e-13,
            3.824134604179522e-19,
            0.0011012032917703204,
            9.092108915247998e-11,
            1.1909307844691415e-13,
            5.580570596436144e-13,
            1.7157587085865873e-26,
            -5.308004890273424e-18,
            1.4284022287923028e-25,
            0.0011732847965691174,
            9.723386552565448e-8,
            2.7429934321988277e-10,
            3.295537437566094e-12,
            -6.242454636029294e-23,
            -2.542755143303511e-16,
            7.694631204394735e-23,
            0.0015686853126462932,
            1.272451742740731e-7,
            7.172280912539058e-10,
            9.460028580627943e-12,
            -3.656449495586842e-22,
            2.9103030942508663e-15,
            -6.881190220498429e-22,
            0.0011601932458903657,
            7.309245008932501e-11,
            8.671415555992079e-12,
            3.726311941347771e-12,
            2.011549938836631e-23,
            -2.3324109643710974e-17,
            -6.636060291134677e-24,
            0.001548104984991593,
            1.1638076835204108e-10,
            2.062688282885403e-11,
            5.32002684649775e-12,
            3.210717676888233e-23,
            -1.8656148410090536e-17,
            4.555151538164152e-23
        ],
        "marr_hildreth_hash": "4e4e0w202200g+aHc0220SW0km2bHJ0kkSYPk+0JK0B43PbZk8nmsmTe0hf4E83E1s8AP0HJ6nI20b8E2JMk2SGTI3Nu0JO0",
        "block_mean_hash": "AAAAAAAAwAHwB/AP4D/AH2D4f/x/9v////////////8=",
        "p_hash": "4bqexizpw/M=",
        "radial_variance_hash": "gt7/vgDp86Cgrsp5foCsbqR2hZuNfGabjoabjXBgdHhlXnJ9fGBxfg==",
        "inserted_at": "2023-05-04T15:47:07.7260991+02:00",
        "image_id": "MTY4MzIwODAyNzcyNjA5OTEwMA=="
    }

This was an example response from the upload endpoint, it basically returns all the image's hashes and its ID

/similarities (GET)

The similarities endpoint has a mandatory query parameter named "id" used to specify the image ID, it also has two optional parameters:

  • hash: this specifies which hash will be used to search similar images (default PHash since it looks like it's the best one)
  • max_distance: this specifies the maximum distance between to images to consider them "similar" (default 10)

The response is still wrapped in the basic response while the "response" key is structured like this {distance: []ImageData}, so if no similar image is found it will just be empty ({}), "distance" is a stringified float indicating the distance between your image and every image found in the value, the value is a list of images, an images is reppresented like in the /upload response.