{"id":17200521,"url":"https://github.com/toy/image_size","last_synced_at":"2025-05-15T16:03:55.598Z","repository":{"id":1156115,"uuid":"1042843","full_name":"toy/image_size","owner":"toy","description":"measure image size using pure Ruby (by Keisuke Minami)","archived":false,"fork":false,"pushed_at":"2025-04-24T11:37:49.000Z","size":353,"stargazers_count":90,"open_issues_count":1,"forks_count":12,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-24T12:44:13.997Z","etag":null,"topics":["image-dimensions","image-format","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/toy.png","metadata":{"files":{"readme":"README.markdown","changelog":"CHANGELOG.markdown","contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2010-11-01T20:13:10.000Z","updated_at":"2025-04-24T11:37:53.000Z","dependencies_parsed_at":"2023-01-13T10:58:49.144Z","dependency_job_id":"fce2583e-e1c4-47fe-86b3-1cf8f28e2aee","html_url":"https://github.com/toy/image_size","commit_stats":{"total_commits":243,"total_committers":7,"mean_commits":"34.714285714285715","dds":"0.024691358024691357","last_synced_commit":"1b2aa7a8ad92da87b5f8777fb73a915802d8ba54"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toy%2Fimage_size","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toy%2Fimage_size/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toy%2Fimage_size/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toy%2Fimage_size/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toy","download_url":"https://codeload.github.com/toy/image_size/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254374403,"owners_count":22060609,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["image-dimensions","image-format","ruby"],"created_at":"2024-10-15T02:08:56.047Z","updated_at":"2025-05-15T16:03:55.525Z","avatar_url":"https://github.com/toy.png","language":"Ruby","readme":"[![Gem Version](https://img.shields.io/gem/v/image_size?logo=rubygems)](https://rubygems.org/gems/image_size)\n[![Check](https://img.shields.io/github/actions/workflow/status/toy/image_size/check.yml?label=check\u0026logo=github)](https://github.com/toy/image_size/actions/workflows/check.yml)\n[![Rubocop](https://img.shields.io/github/actions/workflow/status/toy/image_size/rubocop.yml?label=rubocop\u0026logo=rubocop)](https://github.com/toy/image_size/actions/workflows/rubocop.yml)\n\n# image_size\n\nMeasure image size/dimensions using pure Ruby.\nFormats: `apng`, `avif`, `bmp`, `cur`, `emf`, `gif`, `heic`, `heif`, `ico`, `j2c`, `jp2`, `jpeg`, `jpx`, `mng`, `pam`, `pbm`, `pcx`, `pgm`, `png`, `ppm`, `psd`, `svg`, `swf`, `tiff`, `webp`, `xbm`, `xpm`.\n\n## Installation\n\n```sh\ngem install image_size\n```\n\n### Bundler\n\nAdd to your `Gemfile`:\n\n```ruby\ngem 'image_size', '~\u003e 3.0'\n```\n\n## Usage\n\n```ruby\nimage_size = ImageSize.path('spec/images/jpeg/436x429.jpeg')\n\nimage_size.format       #=\u003e :jpeg\nimage_size.width        #=\u003e 436\nimage_size.height       #=\u003e 429\nimage_size.w            #=\u003e 436\nimage_size.h            #=\u003e 429\nimage_size.size         #=\u003e [436, 429]\nimage_size.size.to_s    #=\u003e \"436x429\"\n\"#{image_size.size}\"    #=\u003e \"436x429\"\nimage_size.size.width   #=\u003e 436\nimage_size.size.height  #=\u003e 429\nimage_size.size.w       #=\u003e 436\nimage_size.size.h       #=\u003e 429\nimage_size.media_type   #=\u003e \"image/jpeg\"\nimage_size.media_types  #=\u003e [\"image/jpeg\"]\n```\n\nOr using `IO` object:\n\n```ruby\nimage_size = File.open('spec/images/jpeg/436x429.jpeg', 'rb'){ |fh| ImageSize.new(fh) }\n```\n\nAny object responding to `read` and `eof?`:\n\n```ruby\nrequire 'image_size'\n\nimage_size = ImageSize.new(ARGF)\n```\n\nWorks with `open-uri`, see [experimental HTTP server interface below](#experimental-fetch-image-meta-from-http-server):\n\n```ruby\nrequire 'image_size'\nrequire 'open-uri'\n\nimage_size = URI.parse('http://www.rubycgi.org/image/ruby_gtk_book_title.jpg').open('rb') do |fh|\n  ImageSize.new(fh)\nend\n\nimage_size = open('http://www.rubycgi.org/image/ruby_gtk_book_title.jpg', 'rb') do |fh|\n  ImageSize.new(fh)\nend\n```\n\nNote that starting with version `2.0.0` the object given to `ImageSize` will not be rewound before or after use.\nSo rewind if needed before passing to `ImageSize` and/or rewind after passing to `ImageSize` before reading data.\n\n```ruby\nrequire 'image_size'\n\nFile.open('spec/images/jpeg/436x429.jpeg', 'rb') do |fh|\n  image_size = ImageSize.new(fh)\n\n  fh.rewind\n  data = fh.read\nend\n\nFile.open('spec/images/jpeg/436x429.jpeg', 'rb') do |fh|\n  data = fh.read\n  fh.rewind\n\n  image_size = ImageSize.new(fh)\nend\n```\n\n### Experimental: fetch image meta from HTTP server\n\nIf server recognises Range header, only needed chunks will be fetched even for TIFF images, otherwise required amount\nof data will be fetched, in most cases first few kilobytes (TIFF images is an exception).\n\n```ruby\nrequire 'image_size/uri'\n\nurl = 'http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg'\np ImageSize.url(url).size\n```\n\nThis interface is as fast as dedicated gem fastimage for images with meta information in the header:\n\n```ruby\nurl = 'http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg'\nputs Benchmark.measure{ p FastImage.size(url) }\n```\n```\n[9545, 6623]\n  0.004176   0.001974   0.006150 (  0.282889)\n```\n```ruby\nputs Benchmark.measure{ p ImageSize.url(url).size }\n```\n```\n[9545, 6623]\n  0.005604   0.001406   0.007010 (  0.238629)\n```\n\nAnd considerably faster for images with meta information at the end of file:\n\n```ruby\nurl = \"https://upload.wikimedia.org/wikipedia/commons/c/c7/Curiosity%27s_Vehicle_System_Test_Bed_%28VSTB%29_Rover_%28PIA15876%29.tif\"\nputs Benchmark.measure{ p FastImage.size(url) }\n```\n```\n[7360, 4912]\n  0.331284   0.247295   0.578579 (  6.027051)\n```\n```ruby\nputs Benchmark.measure{ p ImageSize.url(url).size }\n```\n```\n[7360, 4912]\n  0.006247   0.001045   0.007292 (  0.197631)\n```\n\n## Licence\n\nThis code is free to use under the terms of the [Ruby's licence](LICENSE.txt).\n\nOriginal author: Keisuke Minami \u003ckeisuke@rccn.com\u003e.\\\nFurther development 2010-2024 Ivan Kuchin https://github.com/toy/image_size\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoy%2Fimage_size","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoy%2Fimage_size","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoy%2Fimage_size/lists"}