Project

image_hash

0.0
No commit activity in last 3 years
No release in over 3 years
generate a perceptual hash of any image using ImageMagick and a very simple algorithm
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 10.0
~> 3.0

Runtime

 Project Readme

ImageHash

This is a very simple Ruby library for calculating a perceptual hash of any image using ImageMagick.

Installation

Add this line to your application's Gemfile:

gem 'image_hash'

And then execute:

$ bundle

Or install it yourself as:

$ gem install image_hash

Usage

Create a new ImageHash instance, passing in the path to your image. Use the #hash method to get a compact hexadecimal hash representing the image:

ImageHash.new('image1.jpg').hash        # => fce000101834b692
ImageHash.new('image2.jpg').hash        # => fce000101834b693

If you would rather, you can get the binary hash with #binary_hash:

ImageHash.new('image1.jpg').binary_hash # => 1111110011100000000000000001000000011000001101001011011010010010
ImageHash.new('image2.jpg').binary_hash # => 1111110011100000000000000001000000011000001101001011011010010011

Easily compare two hashes using the .distance method:

ImageHash.distance(
  ImageHash.new('image1.jpg').hash,
  ImageHash.new('image2.jpg').hash
) # => 1

License

The gem is available as open source under the terms of the MIT License.