From f9ca656ccad8c1e0cc9a75d7bd7f725ca8514f56 Mon Sep 17 00:00:00 2001 From: sandstrom Date: Sun, 18 Feb 2024 16:24:46 +0100 Subject: [PATCH] Add libvips example to readme --- README.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d45ac0f..d207f2c 100644 --- a/README.md +++ b/README.md @@ -22,15 +22,25 @@ Or install it yourself as: ## Usage -To generate the blurhash string from an image file, you need to read in the image pixel data yourself, for example with RMagick: +To generate the blurhash string from an image file, you need to read in the image pixel data yourself, for example with RMagick or libvips: ```ruby +# example with rmagick require 'blurhash' require 'rmagick' image = Magick::ImageList.new('foo.png') puts Blurhash.encode(image.columns, image.rows, image.export_pixels) + + +# example with libvips +require 'blurhash' +require 'ruby-vips' + +image = Vips::Image.new_from_file('foo.png', access: :sequential) + +puts Blurhash.encode(image.width, image.height, image.to_a.flatten) ``` To display the visual component once you have the blurhash string, you need another library in JavaScript, Swift, Kotlin and so on. Fore more information, see [the original blurhash repository](https://github.com/woltapp/blurhash).