Module: NSWTopo::Dither

Included in:
Map
Defined in:
lib/nswtopo/dither.rb

Instance Method Summary collapse

Instance Method Details

#dither(*png_paths) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/nswtopo/dither.rb', line 3

def dither(*png_paths)
  Enumerator.new do |yielder|
    yielder << -> { OS.pngquant "--quiet", "--force", "--ext", ".png", "--speed", 1, "--nofs", *png_paths }
    gimp_script = "      (map\n        (lambda (path)\n          (let*\n            (\n              (image (car (gimp-file-load RUN-NONINTERACTIVE path path)))\n              (drawable (car (gimp-image-get-active-layer image)))\n            )\n            (gimp-image-convert-indexed image FSLOWBLEED-DITHER MAKE-PALETTE 256 FALSE FALSE \"\")\n            (gimp-file-save RUN-NONINTERACTIVE image drawable path path)\n          )\n        )\n        (list \"\#{png_paths.join ?\\s}\")\n      )\n    EOF\n    yielder << -> { OS.gimp \"-c\", \"-d\", \"-f\", \"-i\", \"-b\", gimp_script, \"-b\", \"(gimp-quit TRUE)\" }\n    yielder << -> { OS.mogrify \"-type\", \"PaletteBilevelAlpha\", \"-dither\", \"Riemersma\", *png_paths }\n    raise \"pngquant, GIMP or ImageMagick required for dithering\"\n  end.each do |dither|\n    dither.call\n    break\n  rescue OS::Missing\n  end\nend\n"