public static function Instance()
 {
     if (is_null(self::$Instance)) {
         self::$Instance = new self();
     }
     return self::$Instance;
 }
 function imageHashing()
 {
     require_once 'classes/phasher.class.php';
     $I = PHasher::Instance();
     $hash = $I->FastHashImage(Search::uploadImage());
     $hex = $I->HashAsString($hash);
     $query = "SELECT `fid`,`hash` FROM `images` WHERE `hash` LIKE '%" . $hex . "%'";
     return $query;
 }
Esempio n. 3
0
 /**
  * @dataProvider providerImageGenerator
  */
 function testGenerateImage($preset, $generated)
 {
     $manager = $this->getManager();
     $original_file = vfsStream::url('root/images') . '/' . $this->getDummyImageName();
     $final_file = vfsStream::url('root/images') . '/' . $generated;
     $final_file_compared = __DIR__ . '/Fixtures/result/' . $generated;
     $image = new Image($original_file, $this->getMockedToolkit());
     //uncomment and the images will be created on disk
     //$this->assertTrue($this->setAccessible('buildImage')->invoke($manager, $preset, $image, $final_file_compared));
     $this->assertTrue($this->setAccessible('buildImage')->invoke($manager, $preset, $image, $final_file));
     //generated images must be at least 95% identical
     $this->assertGreaterThan(95, PHasher::compare($final_file, $final_file_compared));
 }
Esempio n. 4
0
 public function calcHash()
 {
     $phasher = \PHasher::Instance();
     $url = $this->image != null ? $this->image : ($this->video == null ? null : $this->video->image);
     if ($url == null) {
         return;
     }
     $resource = imagecreatefromstring(file_get_contents($url));
     try {
         $hash = $phasher->FastHashImage($resource);
         $this->hash = $phasher->HashAsString($hash);
     } catch (\Exception $e) {
         $this->hash = null;
     }
 }
Esempio n. 5
0
    function __construct()
    {
        require_once '../phasher.class.php';
        $this->I = PHasher::Instance();
        // this is inverted. WHY DID I DO THIS?
        $this->tests = array("original image, with hash", "duplicate reduced 50%", "compared with itself", "duplicate reduced 50% and rotated 90 degrees. The hash also rotated -- it isn't perfect but its close.", "Comparing the original image with the reduced size one. ", "Now comparing the hashes of the original image, and one reduced and rotated 90 degrees.", "Comparing an image with a desaturated version.");
        if (isset($_GET['test'])) {
            switch (intval($_GET['test'])) {
                //case 7:  $this->Test($this->tests[7], 'IsNegative', array('monalisa2.jpg','monalisa5.jpg')); break;
                case 6:
                    $this->Compare($this->tests[6], 'monalisa2.jpg', 'monalisa4.jpg');
                    break;
                case 5:
                    $this->Compare($this->tests[5], 'monalisa.jpg', 'monalisa3.jpg');
                    break;
                case 4:
                    $this->Compare($this->tests[4], 'monalisa.jpg', 'monalisa2.jpg');
                    break;
                case 3:
                    $this->Show($this->tests[3], "monalisa3.jpg");
                    break;
                case 2:
                    $this->Compare($this->tests[2], 'monalisa2.jpg', 'monalisa2.jpg');
                    break;
                case 1:
                    $this->Show($this->tests[1], "monalisa2.jpg");
                    break;
                default:
                    $this->Show($this->tests[0], "monalisa.jpg");
                    break;
            }
        } else {
            echo <<<EOD
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>

<div class="demo-return">
<UL>
EOD;
            foreach ($this->tests as $key => $val) {
                echo "<LI class='test-link'><a href='#' data-test={$key}>{$val}</a></LI>";
            }
            echo <<<EOD
</UL>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="js/vendor/jquery-1.8.3.min.js"><\\/script>')</script>
<script type="text/javascript">
\$(window).on('load', function(){
\t\$("#demo-menu").load("index.php", function(){
\t\t\$("li.test-link").each(function(i,val){
\t\t\t\$(this).find('a').on('click', function(e){
\t\t\t\tvar datatest = \$(this).data('test');
\t\t\t\te.preventDefault();
\t\t\t\tvar rundemo =  \$.ajax({
\t\t\t\t\t"url": "index.php",
\t\t\t\t\t"type": "GET",
\t\t\t\t\t"data": {
\t\t\t\t\t\t"test": datatest
\t\t\t\t\t}
\t\t\t\t});
\t\t\t\trundemo.success(function(obj){
\t\t\t\t\t
\t\t\t\t\t//console.log(data);
\t\t\t\t\t
\t\t\t\t\t//var obj = \$.parseJSON(data);
\t\t\t\t\t
\t\t\t\t\t//console.log(obj);
\t\t\t\t\t
\t\t\t\t\tvar content = \$("<div></div>");
\t\t\t\t\tcontent.append(obj.text);
\t\t\t\t\tcontent.append('<hr>');
\t\t\t\t\tfor(t=0; t<=obj.images.length-1; t++){
\t\t\t\t\t\tcontent.append("<img src=\\""+obj.images[t]+"\\">");
\t\t\t\t\t}
\t\t\t\t\tfor(t=0; t<=obj.results.length-1; t++){
\t\t\t\t\t\tcontent.append("<div>"+obj.results[t]+"</div>");
\t\t\t\t\t}
\t\t\t\t\t\$('#phash').html(content);
\t\t\t\t});
\t\t\t})
\t\t});
\t});
});
</script>

<div id="demo-menu"></div>
<div id="phash"></div>
</body>
</html>
EOD;
        }
    }
Esempio n. 6
0
<UL><?php 
// testing the CompareStrings method
require_once '../src/PHasher.php';
$I = PHasher::Instance();
// get a hash string for each image
?>
 <LI> monalisa.jpg <?php 
$str1 = $I->HashAsString($I->HashImage('monalisa.jpg'));
echo print_r($str1, true);
?>
</LI><LI> monalisa2.jpg <?php 
$str2 = $I->HashAsString($I->HashImage('monalisa2.jpg'));
echo print_r($str2, true);
// compare them..
?>
</LI><LI> comparison: <?php 
$comp = $I->CompareStrings($str1, $str2);
echo print_r($comp, true);
?>
</LI></UL>


Esempio n. 7
0
<?php

/* command-line utility for generating hashes for our site */
if (PHP_SAPI != 'cli') {
    exit;
}
include 'credentials.inc.php';
/* http://www.sitepoint.com/interactive-cli-password-prompt-in-php/ */
function prompt_silent($prompt = " Enter password: "******"/usr/bin/env bash -c 'echo OK'";
    if (rtrim(shell_exec($command)) !== 'OK') {
        trigger_error("Can't invoke bash");
        return;
    }
    $command = "/usr/bin/env bash -c 'read -s -p \"" . addslashes($prompt) . "\" mypassword && echo \$mypassword'";
    $password = rtrim(shell_exec($command));
    echo "\n";
    return $password;
}
echo "Password hashing tool, requires Linux.\n---\n";
$p = prompt_silent();
$p2 = prompt_silent('Retype Password: '******'t match.\n";
} else {
    $hasher = new PHasher();
    echo $hasher->create_hash($p);
}