{"id":18365384,"url":"https://github.com/le0pard/webp-ffi","last_synced_at":"2025-05-15T22:08:37.262Z","repository":{"id":7298402,"uuid":"8614749","full_name":"le0pard/webp-ffi","owner":"le0pard","description":"Ruby wrapper for libwebp","archived":false,"fork":false,"pushed_at":"2025-03-19T21:09:20.000Z","size":4233,"stargazers_count":114,"open_issues_count":1,"forks_count":14,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-01T07:51:17.081Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://leopard.in.ua/webp-ffi/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/le0pard.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2013-03-06T22:25:44.000Z","updated_at":"2025-03-19T21:09:23.000Z","dependencies_parsed_at":"2025-01-19T06:03:09.496Z","dependency_job_id":"be674cb7-5f3a-43d8-a1a7-a2defc2b11fa","html_url":"https://github.com/le0pard/webp-ffi","commit_stats":{"total_commits":216,"total_committers":6,"mean_commits":36.0,"dds":0.03240740740740744,"last_synced_commit":"11542b3d9b24f6c54b0bf0cebd4a7492e0f8150d"},"previous_names":[],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fwebp-ffi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fwebp-ffi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fwebp-ffi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/le0pard%2Fwebp-ffi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/le0pard","download_url":"https://codeload.github.com/le0pard/webp-ffi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809962,"owners_count":20999816,"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":[],"created_at":"2024-11-05T23:13:19.041Z","updated_at":"2025-04-08T09:07:32.874Z","avatar_url":"https://github.com/le0pard.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Webp-ffi\n\n[![Build](https://github.com/le0pard/webp-ffi/actions/workflows/build.yml/badge.svg)](https://github.com/le0pard/webp-ffi/actions/workflows/build.yml)\n\nRuby wrapper for libwebp. What is WebP?\n\nWebP is a new image format that provides lossless and lossy compression for images on the web. WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller in size compared to JPEG images at equivalent SSIM index. WebP supports lossless transparency (also known as alpha channel) with just 22% additional bytes. Transparency is also supported with lossy compression and typically provides 3x smaller file sizes compared to PNG when lossy compression is acceptable for the red/green/blue color channels.\n\n## [WebP Gallery](https://developers.google.com/speed/webp/gallery)\n\n## Installation\n\n### Requirements\n\nFirst of all you should have install libraries: libpng, libjpeg and libtiff.\n\nFor Ubuntu, Debian:\n\n    sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libwebp-dev\n\nFor Fedora, CentOS:\n\n    sudo dnf install libjpeg-devel libpng-devel libtiff-devel libwebp-devel\n\nFor Mac OS:\n\n    brew install libjpg libpng libtiff webp\n\nor (for MacPorts):\n\n    sudo port install jpeg libpng tiff\n\nNext, you should [install libwebp](https://developers.google.com/speed/webp/docs/compiling) (if you didn't install it by `brew` in Mac OS or by `apt-get` in Ubuntu or Debian). Webp library version should be \u003e= 0.3.0. This gem is not support Windows systems.\n\n### Final part\n\nAdd this line to your application's Gemfile:\n\n    gem 'webp-ffi'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install webp-ffi\n\n## Usage\n\n### Encoder end Decoder versions\n\nBasic info about libwebp (encoder and decoder versions):\n\n    $ irb\n    2.0.0p0 :001 \u003e require 'webp_ffi'\n     =\u003e true\n    2.0.0p0 :002 \u003e WebP.decoder_version\n     =\u003e \"0.3.1\"\n    2.0.0p0 :003 \u003e WebP.encoder_version\n     =\u003e \"0.3.1\"\n\n\n### WebP size (width and height)\n\nGet size (width and height) from webp image:\n\n    filename = File.expand_path(File.join(File.dirname(__FILE__), \"spec/factories/4.webp\"))\n    WebP.webp_size(File.open(filename, \"rb\").read)\n     =\u003e [2000, 2353]\n\n\n### Encode WebP image\n\nEncode png, jpg or tiff image to webp:\n\n    filename = File.expand_path(File.join(File.dirname(__FILE__), \"spec/factories/4.png\"))\n    out_filename = File.expand_path(File.join(File.dirname(__FILE__), \"tmp/4.webp\"))\n    WebP.encode(filename, out_filename)\n\n\nEncode png, jpg or tiff image to webp with options:\n\n    WebP.encode(filename, out_filename, quality: 50, resize_w: 100, resize_h: 200)\n    WebP.encode(filename, out_filename, quality: 75, crop_x: 0, cropt_y: 0, crop_w: 100, crop_h: 100)\n\n\nPossible encode options:\n\n * **lossless** (int) - Lossless encoding (0=lossy(default), 1=lossless)\n * **near_lossless** (int) - Use near-lossless image preprocessing (0=maximum preprocessing, 100=no preprocessing(default))\n * **quality** (float) - between 0 (smallest file) and 100 (biggest)\n * **method** (int) - quality/speed trade-off (0=fast, 6=slower-better)\n * **target\\_size** (int) - if non-zero, set the desired target size in bytes. Takes precedence over the 'compression' parameter\n * **target\\_PSNR** (float) - if non-zero, specifies the minimal distortion to try to achieve. Takes precedence over target\\_size\n * **segments** (int) - maximum number of segments to use, in [1..4]\n * **sns_strength** (int) - Spatial Noise Shaping. 0=off, 100=maximum\n * **filter\\_strength** (int) - range: [0 = off .. 100 = strongest]\n * **filter\\_sharpness** (int) - range: [0 = off .. 7 = least sharp]\n * **filter\\_type** (int) - filtering type: 0 = simple, 1 = strong (only used if filter\\_strength \u003e 0 or autofilter \u003e 0)\n * **autofilter** (int) - Auto adjust filter's strength [0 = off, 1 = on]\n * **alpha\\_compression** (int) - Algorithm for encoding the alpha plane (0 = none, 1 = compressed with WebP lossless). Default is 1\n * **alpha\\_filtering** (int) - Predictive filtering method for alpha plane. 0: none, 1: fast, 2: best. Default if 1\n * **alpha\\_quality** (int) - Between 0 (smallest size) and 100 (lossless). Default is 100\n * **pass** (int) - number of entropy-analysis passes (in [1..10])\n * **show\\_compressed** (int) - if true, export the compressed picture back. In-loop filtering is not applied\n * **preprocessing** (int) - preprocessing filter (0=none, 1=segment-smooth)\n * **partitions** (int) - log2(number of token partitions) in [0..3]. Default is set to 0 for easier progressive decoding\n * **partition\\_limit** (int) - quality degradation allowed to fit the 512k limit on prediction modes coding (0: no degradation, 100: maximum possible degradation)\n * **width** (int), **height** (int) - Input size (width x height) for YUV\n * **crop\\_x** (int), **crop\\_y** (int), **crop\\_w** (int), **crop\\_h** (int) - crop picture with the given rectangle\n * **resize\\_w** (int), **resize\\_h** (int) - resize picture (after any cropping)\n\n### Decode WebP image\n\nDecode webp image (default format is png):\n\n    filename = File.expand_path(File.join(File.dirname(__FILE__), \"spec/factories/4.webp\"))\n    out_filename = File.expand_path(File.join(File.dirname(__FILE__), \"tmp/4.png\"))\n    WebP.decode(filename, out_filename)\n\n\nDecode webp image to pam, ppm, pgm, bmp, tiff or yuv format of image:\n\n    filename = File.expand_path(File.join(File.dirname(__FILE__), \"spec/factories/4.webp\"))\n    out_filename = File.expand_path(File.join(File.dirname(__FILE__), \"tmp/4.png\"))\n    WebP.decode(filename, out_filename, output_format: :pam)\n    WebP.decode(filename, out_filename, output_format: :ppm)\n    WebP.decode(filename, out_filename, output_format: :pgm)\n    WebP.decode(filename, out_filename, output_format: :bmp)\n    WebP.decode(filename, out_filename, output_format: :tiff)\n    WebP.decode(filename, out_filename, output_format: :yuv)\n\n\nDecode webp image with options:\n\n    WebP.encode(filename, out_filename, resize_w: 100, resize_h: 200)\n    WebP.encode(filename, out_filename, crop_x: 0, cropt_y: 0, crop_w: 100, crop_h: 100)\n\n\nPossible decode options:\n\n * **bypass\\_filtering** (bool) - disable in-loop filtering\n * **no\\_fancy\\_upsampling** (bool) - don't use the fancy YUV420 upscaler\n * **use\\_threads** (bool) - use multi-threading\n * **crop\\_x** (int), **crop\\_y** (int), **crop\\_w** (int), **crop\\_h** (int) - crop picture with the given rectangle\n * **resize\\_w** (int), **resize\\_h** (int) - resize picture (after any cropping)\n\n## Rails assets pipeline integration\n\nFor integration with Rails 3+ you can use very simple rake task:\n\n```ruby\n# Place this code in lib/tasks/assets.rake\nrequire 'webp-ffi'\n\nnamespace :assets do\n  desc \"Create .webp versions of assets\"\n  task :webp =\u003e :environment do\n    image_types = /\\.(?:png|jpe?g)$/\n\n    public_assets = File.join(\n      Rails.root,\n      \"public\",\n      Rails.application.config.assets.prefix)\n\n    Dir[\"#{public_assets}/**/*\"].each do |filename|\n      next unless filename =~ image_types\n\n      mtime = File.mtime(filename)\n      webp_file = \"#{filename}.webp\"\n      next if File.exist?(webp_file) \u0026\u0026 File.mtime(webp_file) \u003e= mtime\n      begin\n        WebP.encode(filename, webp_file)\n        File.utime(mtime, mtime, webp_file)\n        puts \"Webp converted image #{webp_file}\"\n      rescue =\u003e e\n        puts \"Webp convertion error of image #{webp_file}. Error info: #{e.message}\"\n      end\n    end\n  end\n\n  # Hook into existing assets:precompile task\n  Rake::Task[\"assets:precompile\"].enhance do\n    Rake::Task[\"assets:webp\"].invoke\n  end\nend\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fle0pard%2Fwebp-ffi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fle0pard%2Fwebp-ffi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fle0pard%2Fwebp-ffi/lists"}