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
30
31
|
# File 'lib/nswtopo/dither.rb', line 5
def dither(*png_paths)
Enumerator.new do |yielder|
yielder << -> { OS.pngquant *%w[--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.magick *%w[mogrify -type PaletteBilevelAlpha -dither Riemersma -colors 256], *png_paths }\n raise Missing, \"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"
|