Skip to content

Commit

Permalink
Replace Phashion with dhash-vips
Browse files Browse the repository at this point in the history
Phashion currently doesn't install on Apple Silicon, and it doesn't seem
it's going to get fixed.

An upside is that this will now work on JRuby as well, since dhash-vips
doesn't use C extensions.
  • Loading branch information
janko committed Sep 26, 2021
1 parent b2b91df commit f0c152e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion image_processing.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest", "~> 5.8"
spec.add_development_dependency "minitest-hooks", ">= 1.4.2"
spec.add_development_dependency "minispec-metadata"
spec.add_development_dependency "phashion" unless RUBY_ENGINE == "jruby"
spec.add_development_dependency "dhash-vips"
end
16 changes: 6 additions & 10 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

ENV["VIPS_WARNING"] = "0" # disable libvips warnings

require "phashion" unless RUBY_ENGINE == "jruby"
require "dhash-vips"
require "vips"
require "mini_magick"

Expand All @@ -27,15 +27,11 @@ def copy_to_tempfile(io, extension = nil)
end

def assert_similar(image1, image2)
return if RUBY_ENGINE == "jruby" # Phashion has C extensions

assert_operator distance(image1, image2), :<=, 4
assert_operator distance(image1, image2), :<=, 3
end

def refute_similar(image1, image2)
return if RUBY_ENGINE == "jruby" # Phashion has C extensions

assert_operator distance(image1, image2), :>, 4
assert_operator distance(image1, image2), :>, 3
end

def assert_dimensions(dimensions, file)
Expand All @@ -49,10 +45,10 @@ def assert_type(type, file)
private

def distance(image1, image2)
a = Phashion::Image.new(image1.path)
b = Phashion::Image.new(image2.path)
hash1 = DHashVips::IDHash.fingerprint(image1.path)
hash2 = DHashVips::IDHash.fingerprint(image2.path)

a.distance_from(b).abs
DHashVips::IDHash.distance hash1, hash2
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/vips_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@
it "produces correct image when enlarging" do
@pipeline = ImageProcessing::Vips.source(@landscape)
expected = fixture_image("pad-large.jpg")
assert_similar expected, @pipeline.resize_and_pad!(1000, 1000, background: [0, 255, 0])
assert_similar expected, @pipeline.resize_and_pad!(1000, 1000, background: [55, 126, 34])
end

it "accepts gravity" do
Expand Down

0 comments on commit f0c152e

Please sign in to comment.