travail/image-perceptualhash 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

travail/image-perceptualhash

最新稳定版本:v0.1.0

Composer 安装命令:

composer require travail/image-perceptualhash

包简介

travail/image-perceptualhash

README 文档

README

NAME

Image\PerceptualHash - Generate comparable hash from images

SYNOPSIS

<?php

use Image\PerceptualHash;
use Image\PerceptualHash\Algorithm\DifferenceHash;
use Image\PerceptualHash\Algorithm\PerceptionHash;

// Create an instance of Image\PerceptualHash, at the same time calculate hashes
// using hashing algorithm Image\PerceptualHash\Algorithm\AverageHash by default
$ph = new PerceptualHash('/path/to/foo.jpg');

// Get binary hash
$binary_hash = $ph->bin();

// Get hexadecimal hash
$hex_hash = $ph->hex();

// Compare with another image, return a Hamming distance
$distance = $ph->compare('/path/to/bar.jpg');

// Calculate a similarity
$similarity = $ph->similarity('/path/to/baz.jpg');

// Calculate by other hashing algorithms
$ph = new PerceptualHash('/path/to/foo.jpg', new DifferenceHash());
// or
$ph = new PerceptualHash('/path/to/foo.jpg', new PerceptionHash());

DESCRIPTION

Image\PerceptualHash generates distinct, but not unique fingerprint with three hashing algorithms. Unlike cryptographic hashing, these fingerprints from similar images will be also similar.

DEPENDENCIES

  • ext-gd

INSTALLATION

To install this package into your project via composer, add the following snippet to your composer.json. Then run composer install.

"require": {
  "travail/image-perceptualhash": "dev-master"
}

or

"repositories": {
  {
    "type": "vcs",
    "url": "git@github.com:travail/php-Image-PerceptualHash.git"
  }
}

TESTS

After cloning the project, run composer install and ./vendor/bin/phpunit.

$ git clone git@github.com:travail/php-Image-PerceptualHash.git
$ cd php-Image-PerceptualHash
$ composer install
$ ./vendor/bin/phpunit

METHODS

__construct

Image\PerceptualHash __construct($file, Algorithm $algorithm)

Creates a new instance of Image\PerceptualHash and calculates hashes.

$file

Path to a file or a resource of that.

Algorithm $algorithm

Hashing algorithm, currently the following algorithm are available:

  • AverageHash
  • DifferenceHash
  • PerceptionHash

bin

string bin()

Returns calculated binary hash.

hex

string hex()

Returns calculated hexadecimal hash.

compare

int compare(string|resource $file)

Compares with another image and returns the Hamming distance to that.

$file

Path to a file or a resource of that.

distance

int distance(string $hash1, string $hash2)

similarity

double similarity(string|resource $file)

Calculates the similarity to another image.

$file

Path to a file or a resource of that.

AUTHOR

travail

LICENSE

This library is free software. You can redistribute it and/or modify it under the same terms as PHP itself.

统计信息

  • 总下载量: 4.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 9
  • Watchers: 4
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: PHP-3.0
  • 更新时间: 2015-02-03