Module: Blurhash

Defined in:
lib/blurhash.rb,
lib/blurhash/version.rb,
ext/blurhash/encode.c

Defined Under Namespace

Modules: Base83

Constant Summary collapse

VERSION =
"0.1.8"

Class Method Summary collapse

Class Method Details

.components(str) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/blurhash.rb', line 14

def self.components(str)
  size_flag = Base83.decode83(str[0])
  y_comp    = (size_flag / 9) + 1
  x_comp    = (size_flag % 9) + 1

  return if str.size != 4 + 2 * x_comp * y_comp

  [x_comp, y_comp]
end

.encode(width, height, pixels, x_comp: 4, y_comp: 3) ⇒ Object



7
8
9
10
11
12
# File 'lib/blurhash.rb', line 7

def self.encode(width, height, pixels, x_comp: 4, y_comp: 3)
  raise 'Pixels array has wrong size' if pixels.size != width * height * 3

  p = pixels.pack("C#{pixels.size}")
  return Unstable.blurHashForPixels(x_comp, y_comp, width, height, p)
end