Coder Social home page Coder Social logo

Comments (4)

pachico avatar pachico commented on July 17, 2024

I can confirm the same behaviour, returning sometimes even less chars than that.

from imagehash.

st-bobb avatar st-bobb commented on July 17, 2024

Now I can consistently get 16 char hashes.
Modified the hash function in DifferenceHash.php

// DifferenceHash.php
$hash = '';// Create a string instead of a binary that could get interpreted as an integer

//......

// if ($left > $right) {
//     $hash |= $one;
// }

if ($left > $right) {
    $hash .= '1';
 }else{
    $hash .= '0';
 }

Modified this function that was receiving an integer which I suspect dropped leading zeros.

    //ImageHash.php
    protected function formatHash($hash)// Now coming in as a string
        {
            $hex = '';
            // To prevent php complaining about big integer numbers
            //  convert the 64 chars to 8 sets of 8 chars.
            $strings = str_split($hash,8);
            foreach($strings as $string)
            {
                $hex .= str_pad(base_convert($string,2, 16) , 2 , "0" , STR_PAD_LEFT);
            }
            return $hex; // Save this value in the db
            // return $this->mode === static::HEXADECIMAL ? dechex($hash) : $hash;
        }

from imagehash.

pachico avatar pachico commented on July 17, 2024

If this got to a PR it would be great!

from imagehash.

st-bobb avatar st-bobb commented on July 17, 2024

If you have gmp enabled you can increase the image size constant and then get more accuracy as now you have a larger hash. I am now using a 12 x 12 image which gives me a 36 char hash which means my hamming distance range is greater. No need to change more code. The difference method doesn't care about the length of your hash as long as you maintain it as a hex and have gmp enabled.

Running my db now to get the 40,000 larger hashes to see if the larger image size helps.

from imagehash.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.