GMImage.Hash
------------

Calculates a hash of the image.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [GraphicsMagick](component_GraphicsMagick.md) | [9.4](newinversion94.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "GMImage.Hash"; ImageRef { ; Size } ) 

**MBS**( **"GMImage.Hash";** /\* Calculates a hash of the image. \*/  
**$ImageRef**; /\* The image reference number.e.g. 1 \*/   
**$Size**) /\* Optional; The size of the bitmap.  
Value from 8 to 1024.  
Default is 8. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| ImageRef | The image reference number. | 1 |  |
| Size | The size of the bitmap.   Value from 8 to 1024.   Default is 8. |  | Optional      Added in version **12.4**. |

### Result

Returns text or error.

### Description

Calculates a hash of the image.  
Hash is returned as 64 characters being 1 or 0.  
We convert image to 8x8, turn grayscale and check if pixels are above or below mean value.  
This hash is quite immune against resizing, compression artifacts and hue changes.  
You can use [Text.LevenshteinDistance](TextLevenshteinDistance.md) or [Text.JaroWinklerDistance](TextJaroWinklerDistance.md) to compare two hashes.  
  
While GMImage.Hash does make a finger print, you can use [Hash.Digest](HashDigest.md) to get a hash of the image bytes.  
### Examples

Play with hash function:

 Set Variable \[ $ImageRef ; Value: MBS ("[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; Test::BigImage ) \]   
Set Variable \[ $Hash1 ; Value: MBS ("GMImage.Hash"; $ImageRef ) \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.Flip](GMImageFlip.md)"; $ImageRef ) \]   
Set Variable \[ $Hash2 ; Value: MBS ("GMImage.Hash"; $ImageRef ) \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.Flop](GMImageFlop.md)"; $ImageRef ) \]   
Set Variable \[ $Hash3 ; Value: MBS ("GMImage.Hash"; $ImageRef ) \]   
Set Variable \[ $Error ; Value: MBS ("[GMImage.Release](GMImageRelease.md)"; $ImageRef ) \]   
Show Custom Dialog \[ "Hash original: " &amp; $hash1 &amp; ¶ &amp; "Hash after 1x mirror: " &amp; $hash2 &amp; ¶ &amp; "Hash after 2x mirror: " &amp;… \]  
### See also

- [GMImage.Erase](GMImageErase.md)
- [GMImage.Flop](GMImageFlop.md)
- [GMImage.Map](GMImageMap.md)
- [GMImage.NewFromContainer](GMImageNewFromContainer.md)
- [GMImage.Raise](GMImageRaise.md)
- [GMImage.Release](GMImageRelease.md)
- [GMImage.Wave](GMImageWave.md)
- [Hash.Digest](HashDigest.md)
- [Text.JaroWinklerDistance](TextJaroWinklerDistance.md)
- [Text.LevenshteinDistance](TextLevenshteinDistance.md)

### Release notes

- **Version 12.4**
    - Added size parameter for [GMImage.Hash](https://www.mbsplugins.eu/GMImageHash.shtml) function.
- **Version 9.4**
    - Added [GMImage.Hash](http://www.mbsplugins.eu/GMImageHash.shtml) function.

### Blog Entries

- [Neues MBS Plugin 12.4 für Claris FileMaker](https://www.mbsplugins.de/archive/2022-09-06/Neues_MBS_Plugin_124_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 12.4 for Claris FileMaker](https://www.mbsplugins.de/archive/2022-09-06/MBS_Plugin_124_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 12.4pr1](https://www.mbsplugins.de/archive/2022-08-01/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)
- [Neue Funktionen des MBS FileMaker Plugin 9.4](https://www.mbsplugins.de/archive/2019-10-05/Neue_Funktionen_des_MBS_FileMa/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin 9.4 - More than 5900 Functions In One Plugin](https://www.mbsplugins.de/archive/2019-09-17/MBS_FileMaker_Plugin_94_-_More/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 9.4pr7](https://www.mbsplugins.de/archive/2019-09-12/MBS_FileMaker_Plugin_version_9/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 10th September 2019 , last changed 28th July 2022

  
[GMImage.GetZPL](GMImageGetZPL.md) - [GMImage.ImageCount](GMImageImageCount.md)

[HTML Version](GMImageHash.shtml)