phashion 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,6 +1,12 @@
1
1
  History
2
2
  =========
3
3
 
4
+ 1.0.2
5
+ -------
6
+
7
+ * Make installation much easier by distributing and building locally all the native dependencies.
8
+ This includes pHash 0.9.0 and CImg 1.3.4.
9
+
4
10
  1.0.1
5
11
  -------
6
12
 
data/README.md CHANGED
@@ -4,37 +4,21 @@ Phashion
4
4
  Phashion is a Ruby wrapper around the pHash library, "perceptual hash", which detects duplicate
5
5
  and near duplicate multimedia files (images, audio, video). The wrapper currently only supports images.
6
6
 
7
+ [See an overview of Phashion on my blog](http://www.mikeperham.com/2010/05/21/detecting-duplicate-images-with-phashion/).
8
+
7
9
  Installation
8
10
  -------------
9
11
 
10
- First you need to install pHash. pHash requires three libraries: CImg, ffmpeg and libjpeg. My system already came with libjpeg on it so I didn't have to do anything for it. YMMV.
11
-
12
- Install CImg.h by downloading the latest version from http://cimg.sf.net and placing the CImg.h header file in /usr/local/include.
13
-
14
- If you are working with audio or video, you will need to install ffmpeg:
15
-
16
- port install ffmpeg (OR)
17
- brew install ffmpeg
18
-
19
- Alternatively you can configure pHash to not support audio/video:
12
+ You install it just like any other Ruby gem:
20
13
 
21
- ./configure --disable-audio-hash --disable-video-hash
14
+ gem install phashion
22
15
 
23
- Download and install the latest pHash tarball from http://phash.org/download/. With 0.9.0, there are several issues with OSX: I had to disable audio and video support to avoid compilation issues and modify `ph_num_threads` in pHash.cpp to avoid Linux-specific code:
16
+ Phashion is somewhat involved to install as it has a few dependencies. I've wrapped up those
17
+ dependencies into a custom tarball that is built locally just for this gem so you don't have to
18
+ do anything special. See the code in `ext/phashion_ext` for more details.
24
19
 
25
- ./configure --disable-audio-hash --disable-video-hash
26
-
27
- int ph_num_threads()
28
- {
29
- int numCPU = 2;
30
- return numCPU;
31
- }
32
-
33
- Finally, run `make && make install` to install the pHash binaries.
34
-
35
- Now you can install this gem:
36
-
37
- gem install phashion
20
+ Because of this complexity, it is possible the gem install will fail on your platform. I've tested
21
+ it on Mac OSX 10.6 and Ubuntu 8.04 but please contact me if you have installation problems.
38
22
 
39
23
  Usage
40
24
  ---------
@@ -45,14 +29,6 @@ Usage
45
29
  img1.duplicate?(img2)
46
30
  --> true
47
31
 
48
- Left to the reader: add equality semantics so that duplicate images placed in a Ruby set are automatically removed:
49
-
50
- set = Set.new
51
- set << img1
52
- set << img2
53
- set.size
54
- --> 1
55
-
56
32
  Author
57
33
  ==========
58
34
 
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/mperham/phashion"
12
12
  gem.authors = ["Mike Perham"]
13
13
  gem.add_development_dependency 'rake-compiler', '>= 0.7.0'
14
- gem.version = '1.0.1'
14
+ gem.version = '1.0.2'
15
15
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
16
  end
17
17
  Jeweler::GemcutterTasks.new
@@ -1,13 +1,45 @@
1
1
  require 'mkmf'
2
2
 
3
- $CFLAGS << " -x c++ #{ENV["CFLAGS"]}"
4
- $LIBS << " -lpHash #{ENV["LIBS"]}"
3
+ HERE = File.expand_path(File.dirname(__FILE__))
4
+ BUNDLE = Dir.glob("#{HERE}/pHash-*.tar.gz").first
5
+ BUNDLE_PATH = BUNDLE.gsub(".tar.gz", "")
6
+ $CFLAGS = " -x c++ #{ENV["CFLAGS"]}"
7
+ $includes = " -I#{HERE}/include"
8
+ $libraries = " -L#{HERE}/lib"
9
+ $LIBPATH = ["#{HERE}/lib"]
10
+ $CFLAGS = "#{$includes} #{$libraries} #{$CFLAGS}"
11
+ $LDFLAGS = "#{$libraries} #{$LDFLAGS}"
5
12
 
6
- # TODO: need to figure this stuff out
7
- # dir_config 'pHash'
8
- # if !have_library('pHash', 'ph_dct_imagehash')
9
- # puts "Unable to find pHash library, please use 'gem install phashion -- --with-pHash-dir=/phash/install/root'"
10
- # exit 1
11
- # end
13
+ Dir.chdir(HERE) do
14
+ if File.exist?("lib")
15
+ puts "pHash already built; run 'rake clean' first if you need to rebuild."
16
+ else
12
17
 
13
- create_makefile('phashion_ext')
18
+ puts(cmd = "tar xzf #{BUNDLE} 2>&1")
19
+ raise "'#{cmd}' failed" unless system(cmd)
20
+
21
+ Dir.chdir(BUNDLE_PATH) do
22
+ puts(cmd = "env CFLAGS='#{$CFLAGS}' LDFLAGS='#{$LDFLAGS}' ./configure --prefix=#{HERE} --disable-audio-hash --disable-video-hash --disable-shared --with-pic 2>&1")
23
+ raise "'#{cmd}' failed" unless system(cmd)
24
+
25
+ puts(cmd = "make || true 2>&1")
26
+ raise "'#{cmd}' failed" unless system(cmd)
27
+
28
+ puts(cmd = "make install || true 2>&1")
29
+ raise "'#{cmd}' failed" unless system(cmd)
30
+
31
+ puts(cmd = "mv CImg.h ../include 2>&1")
32
+ raise "'#{cmd}' failed" unless system(cmd)
33
+ end
34
+
35
+ system("rm -rf #{BUNDLE_PATH}") unless ENV['DEBUG'] or ENV['DEV']
36
+ end
37
+
38
+ Dir.chdir("#{HERE}/lib") do
39
+ system("cp -f libpHash.a libpHash_gem.a")
40
+ system("cp -f libpHash.la libpHash_gem.la")
41
+ end
42
+ $LIBS = " -lpHash_gem"
43
+ end
44
+
45
+ create_makefile 'phashion_ext'
Binary file
data/lib/phashion.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'rubygems'
2
-
3
1
  ##
4
2
  # Provides a clean and simple API to detect duplicate image files using
5
3
  # the pHash library under the covers.
@@ -9,7 +7,7 @@ require 'rubygems'
9
7
  # int ph_hamming_distance(ulong64 hasha, ulong64 hashb);
10
8
 
11
9
  module Phashion
12
- VERSION = '1.0.1'
10
+ VERSION = '1.0.2'
13
11
 
14
12
  class Image
15
13
  SETTINGS = {
data/phashion.gemspec ADDED
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{phashion}
8
+ s.version = "1.0.2"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Mike Perham"]
12
+ s.date = %q{2010-06-04}
13
+ s.description = %q{Simple wrapper around the pHash library}
14
+ s.email = %q{mperham@gmail.com}
15
+ s.extensions = ["ext/phashion_ext/extconf.rb"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "CHANGES.md",
24
+ "LICENSE",
25
+ "README.md",
26
+ "Rakefile",
27
+ "TODO.md",
28
+ "ext/phashion_ext/extconf.rb",
29
+ "ext/phashion_ext/pHash-0.9.0.tar.gz",
30
+ "ext/phashion_ext/phashion_ext.c",
31
+ "lib/phashion.rb",
32
+ "phashion.gemspec",
33
+ "test/86x86-0a1e.jpeg",
34
+ "test/86x86-83d6.jpeg",
35
+ "test/86x86-a855.jpeg",
36
+ "test/avatar.jpg",
37
+ "test/b32aade8c590e2d776c24f35868f0c7a588f51e1.jpeg",
38
+ "test/df9cc82f5b32d7463f36620c61854fde9d939f7f.jpeg",
39
+ "test/e7397898a7e395c2524978a5e64de0efabf08290.jpeg",
40
+ "test/helper.rb",
41
+ "test/test_phashion.rb"
42
+ ]
43
+ s.homepage = %q{http://github.com/mperham/phashion}
44
+ s.rdoc_options = ["--charset=UTF-8"]
45
+ s.require_paths = ["lib"]
46
+ s.rubygems_version = %q{1.3.6}
47
+ s.summary = %q{Simple wrapper around the pHash library}
48
+ s.test_files = [
49
+ "test/helper.rb",
50
+ "test/test_phashion.rb"
51
+ ]
52
+
53
+ if s.respond_to? :specification_version then
54
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
55
+ s.specification_version = 3
56
+
57
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
58
+ s.add_development_dependency(%q<rake-compiler>, [">= 0.7.0"])
59
+ else
60
+ s.add_dependency(%q<rake-compiler>, [">= 0.7.0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<rake-compiler>, [">= 0.7.0"])
64
+ end
65
+ end
66
+
@@ -10,6 +10,14 @@ class TestPhashion < Test::Unit::TestCase
10
10
  assert_duplicate images[0], images[2]
11
11
  end
12
12
 
13
+ def test_duplicate_detection_2
14
+ files = %w(b32aade8c590e2d776c24f35868f0c7a588f51e1.jpeg df9cc82f5b32d7463f36620c61854fde9d939f7f.jpeg e7397898a7e395c2524978a5e64de0efabf08290.jpeg)
15
+ images = files.map {|f| Phashion::Image.new("#{File.dirname(__FILE__) + '/../test/'}#{f}")}
16
+ assert_duplicate images[0], images[1]
17
+ assert_duplicate images[1], images[2]
18
+ assert_duplicate images[0], images[2]
19
+ end
20
+
13
21
  def test_not_duplicate
14
22
  files = %w(86x86-0a1e.jpeg 86x86-83d6.jpeg 86x86-a855.jpeg avatar.jpg)
15
23
  images = files.map {|f| Phashion::Image.new("#{File.dirname(__FILE__) + '/../test/'}#{f}")}
@@ -21,10 +29,10 @@ class TestPhashion < Test::Unit::TestCase
21
29
  private
22
30
 
23
31
  def assert_duplicate(a, b)
24
- raise ArgumentError, "#{a.filename} not dupe of #{b.filename}" unless a.duplicate?(b)
32
+ assert a.duplicate?(b), "#{a.filename} not dupe of #{b.filename}"
25
33
  end
26
34
 
27
35
  def assert_not_duplicate(a, b)
28
- raise ArgumentError, "#{a.filename} dupe of #{b.filename}" if a.duplicate?(b)
36
+ assert !a.duplicate?(b), "#{a.filename} dupe of #{b.filename}"
29
37
  end
30
38
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 1
9
- version: 1.0.1
8
+ - 2
9
+ version: 1.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mike Perham
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-05-20 00:00:00 -05:00
17
+ date: 2010-06-04 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -49,12 +49,17 @@ files:
49
49
  - Rakefile
50
50
  - TODO.md
51
51
  - ext/phashion_ext/extconf.rb
52
+ - ext/phashion_ext/pHash-0.9.0.tar.gz
52
53
  - ext/phashion_ext/phashion_ext.c
53
54
  - lib/phashion.rb
55
+ - phashion.gemspec
54
56
  - test/86x86-0a1e.jpeg
55
57
  - test/86x86-83d6.jpeg
56
58
  - test/86x86-a855.jpeg
57
59
  - test/avatar.jpg
60
+ - test/b32aade8c590e2d776c24f35868f0c7a588f51e1.jpeg
61
+ - test/df9cc82f5b32d7463f36620c61854fde9d939f7f.jpeg
62
+ - test/e7397898a7e395c2524978a5e64de0efabf08290.jpeg
58
63
  - test/helper.rb
59
64
  - test/test_phashion.rb
60
65
  has_rdoc: true