{"id":15066775,"url":"https://github.com/cristianofmc/image_compare","last_synced_at":"2026-01-28T05:59:07.951Z","repository":{"id":257508728,"uuid":"858485844","full_name":"cristianofmc/image_compare","owner":"cristianofmc","description":"Compare PNG images in pure Ruby (uses ChunkyPNG) using different algorithms. This is a utility library for image regression testing.","archived":false,"fork":false,"pushed_at":"2024-09-17T03:15:02.000Z","size":22,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-31T19:22:20.643Z","etag":null,"topics":["chunky-png","gem","image","ruby","selection","test"],"latest_commit_sha":null,"homepage":"https://github.com/instantink/image_compare","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cristianofmc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-17T01:27:28.000Z","updated_at":"2024-09-17T03:17:22.000Z","dependencies_parsed_at":"2024-09-17T05:26:37.214Z","dependency_job_id":"62e07743-51f6-48f0-840d-4310b34ffd00","html_url":"https://github.com/cristianofmc/image_compare","commit_stats":null,"previous_names":["cristianofmc/image_compare"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/cristianofmc/image_compare","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianofmc%2Fimage_compare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianofmc%2Fimage_compare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianofmc%2Fimage_compare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianofmc%2Fimage_compare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cristianofmc","download_url":"https://codeload.github.com/cristianofmc/image_compare/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cristianofmc%2Fimage_compare/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28840275,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T05:50:12.573Z","status":"ssl_error","status_checked_at":"2026-01-28T05:49:54.528Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chunky-png","gem","image","ruby","selection","test"],"created_at":"2024-09-25T01:12:02.208Z","updated_at":"2026-01-28T05:59:07.939Z","avatar_url":"https://github.com/cristianofmc.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Original repository on : https://github.com/instantink/image_compare/tree/main\n# ImageCompare\n[\u003cimg src=\"https://shields.io/github/license/instantink/image_compare?color=%2345a34c\" /\u003e](LICENSE.txt)\n[\u003cimg src=\"https://shields.io/gem/v/image_compare\" /\u003e](https://rubygems.org/gems/image_compare)\n\u003cimg alt=\"Gem total downloads\" src=\"https://shields.io/gem/dt/image_compare\" /\u003e\n\nCompare PNG images in pure Ruby (uses [ChunkyPNG](https://github.com/wvanbergen/chunky_png)) using different algorithms.\nThis is a utility library for image regression testing.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"image_compare\"\n```\n\nOr adding to your project:\n\n```ruby\n# my-cool-gem.gemspec\nGem::Specification.new do |spec|\n  # ...\n  spec.add_dependency \"image_compare\"\n  # ...\nend\n```\n\nAdditionally, you may want to install [oily_png](https://github.com/wvanbergen/oily_png) to improve performance when using MRI. Just install it globally or add to your Gemfile.\n\n## Modes\n\nImageCompare supports different ways (_modes_) of comparing images.\n\nSource images used in examples:\n\na.png\n\n\u003cimg alt=\"a.png\" src=\"https://raw.githubusercontent.com/instantink/image_compare/main/spec/fixtures/a.png\" /\u003e\n\nb.png\n\n\u003cimg alt=\"b.png\" src=\"https://raw.githubusercontent.com/instantink/image_compare/main/spec/fixtures/b.png\" /\u003e\n\na1.png\n\n\u003cimg alt=\"a1.png\" src=\"https://raw.githubusercontent.com/instantink/image_compare/main/spec/fixtures/a1.png\" /\u003e\n\n### Base (Color) mode (a.png X a1.png)\n\nCompare pixels, resulting score is a ratio of unequal pixels (with respect to provided tolerance).\n\nResulting diff contains version of the first image with different pixels highlighted in red and red bounding box.\n\n\u003cimg alt=\"color_diff\" src=\"https://raw.githubusercontent.com/instantink/image_compare/main/spec/fixtures/color_diff.png\" /\u003e\n\n## Usage\n\n```ruby\n# Create new matcher with default threshold equals to 0\n# and base (Color) mode\ncmp = ImageCompare::Matcher.new\ncmp.mode #=\u003e ImageCompare::Modes::Color\n\n# Create new matcher with default threshold equals to 0\n# and base (RGB) mode\ncmp = ImageCompare::Matcher.new mode: :rgb\ncmp.mode #=\u003e ImageCompare::Modes::RGB\n\n# Create matcher with specific threshold\ncmp = ImageCompare::Matcher.new threshold: 0.05\ncmp.threshold #=\u003e 0.05\n\n# or with a lower threshold (in case you want to test that there is some difference)\ncmp = ImageCompare::Matcher.new lower_threshold: 0.01\ncmp.lower_threshold #=\u003e 0.01\n\n# Create zero-tolerance grayscale matcher\ncmp = ImageCompare::Matcher.new mode: :grayscale, tolerance: 0\ncmp.mode #=\u003e ImageCompare::Modes::Grayscale\n\nres = cmp.compare(\"path/image1.png\", \"path/image2.png\")\nres #=\u003e ImageCompare::Result\nres.match? #=\u003e true\nres.score #=\u003e 0.0\n\n# Return diff image object\nres.difference_image #=\u003e ImageCompare::Image\nres.difference_image.save(result)\n\n# without explicit matcher\nres = ImageCompare.compare(\"path/image1.png\", \"path/image2.png\", options)\nres.match? #=\u003e true\nres.score #=\u003e 0.0\n\n# equals to\nres = ImageCompare::Matcher.new(options).compare(\"my_images_path/image1.png\", \"my_images_path/image2.png\")\nres.match? #=\u003e true\nres.score #=\u003e 0.0\n```\n\n## Excluding rectangle (a.png X a1.png)\n\n\u003cimg alt=\"a1.png\" src=\"https://raw.githubusercontent.com/instantink/image_compare/main/spec/fixtures/multiple_exclude_rects.png\" /\u003e\n\nYou can exclude rectangle from comparing by passing `:exclude_rects` to `compare`.\nE.g., if `path_1` and `path_2` contain images above\n```ruby\nImageCompare.compare(\"path/image1.png\", \"path/image2.png\", mode: :rgb, exclude_rects: [[170, 221, 188, 246], [289, 221, 307, 246]]).match? # =\u003e true\n\n# or\n\ncmp = ImageCompare::Matcher.new mode: :rgb, exclude_rect: [[170, 221, 188, 246], [289, 221, 307, 246]]\nres = cmp.compare(\"path/image1.png\", \"path/image2.png\")\nres #=\u003e ImageCompare::Result\nres.match? #=\u003e true\nres.score #=\u003e 0.0\n\n# Return diff image object\nres.difference_image #=\u003e ImageCompare::Image\nres.difference_image.save(\"path/diff.png\")\n```\n`[[170, 221, 188, 246],[289, 221, 307, 246]]` is a set of multiple areas, containing area not to be considered in comparison, each area is an array of two vertices of rectangle -- (170, 121) is left-top vertex and (288, 246) is right-bottom.\n\n\n\n### Cucumber + Capybara example\n`support/env.rb`:\n```ruby\nrequire \"image_compare\"\n```\n\n`support/capybara_extensions.rb`:\n```ruby\n# frozen_string_literal: true\n\nCapybara::Node::Element.class_eval do\n  def rect_area\n    rect_area = self.evaluate_script(\"this.getBoundingClientRect()\") # rubocop:disable Style/RedundantSelf\n\n    [\n      rect_area[\"left\"].to_f.round,\n      rect_area[\"top\"].to_f.round,\n      rect_area[\"right\"].to_f.round,\n      rect_area[\"bottom\"].to_f.round\n    ]\n  rescue StandardError =\u003e e # rubocop:disable Style/RescueStandardError\n    raise \"Error getting element rect area: #{e.inspect}!\"\n  end\nend\n```\n\n`steps/my_step.rb`:\n```ruby\nmy_element = page.find(\"#my_element\").rect_area\n\ncmp = ImageCompare::Matcher.new exclude_rect: my_element.rect_area\nres = cmp.compare(\"path/image1.png\", \"path/image2.png\")\nres.difference_image.save(\"path/diff.png\")\n\nexpect(res.match?).to eq(true)\n```\n\n## Including rectangle\n\nYou can set bounds of comparing by passing `:include_rect` to `compare` with array similar to previous example\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/instantink/image_compare.\n\n### Running tests and code inspections\n\n- `rake rubocop`\n- `rake rubocop:md`\n- `rake spec`\n- `ruby examples/performance.rb` Create the \"gemfile.local\" file with the content below to run the performance tests:\n```ruby\n# frozen_string_literal: true\n\nsource \"https://rubygems.org\"\ngem \"benchmark-ips\", \"~\u003e 2.7\", \"\u003e= 2.7.2\"\n```\n\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcristianofmc%2Fimage_compare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcristianofmc%2Fimage_compare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcristianofmc%2Fimage_compare/lists"}