Add dither server
This commit is contained in:
7
bin/dither/Gemfile
Normal file
7
bin/dither/Gemfile
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
source "https://rubygems.org"
|
||||||
|
|
||||||
|
gem "sinatra"
|
||||||
|
gem "rackup"
|
||||||
|
gem "mini_magick"
|
||||||
36
bin/dither/Gemfile.lock
Normal file
36
bin/dither/Gemfile.lock
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
base64 (0.2.0)
|
||||||
|
mini_magick (4.12.0)
|
||||||
|
mustermann (3.0.0)
|
||||||
|
ruby2_keywords (~> 0.0.1)
|
||||||
|
rack (3.0.9)
|
||||||
|
rack-protection (4.0.0)
|
||||||
|
base64 (>= 0.1.0)
|
||||||
|
rack (>= 3.0.0, < 4)
|
||||||
|
rack-session (2.0.0)
|
||||||
|
rack (>= 3.0.0)
|
||||||
|
rackup (2.1.0)
|
||||||
|
rack (>= 3)
|
||||||
|
webrick (~> 1.8)
|
||||||
|
ruby2_keywords (0.0.5)
|
||||||
|
sinatra (4.0.0)
|
||||||
|
mustermann (~> 3.0)
|
||||||
|
rack (>= 3.0.0, < 4)
|
||||||
|
rack-protection (= 4.0.0)
|
||||||
|
rack-session (>= 2.0.0, < 3)
|
||||||
|
tilt (~> 2.0)
|
||||||
|
tilt (2.3.0)
|
||||||
|
webrick (1.8.1)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
arm64-darwin-22
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
mini_magick
|
||||||
|
rackup
|
||||||
|
sinatra
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.4.8
|
||||||
40
bin/dither/dither.rb
Normal file
40
bin/dither/dither.rb
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
require "sinatra"
|
||||||
|
require "mini_magick"
|
||||||
|
|
||||||
|
MiniMagick.logger.level = Logger::DEBUG
|
||||||
|
|
||||||
|
ROOT = ENV["ROOT"]
|
||||||
|
KEY = ENV["KEY"]
|
||||||
|
|
||||||
|
FileUtils.mkdir_p "tmp"
|
||||||
|
|
||||||
|
get "/*" do |path|
|
||||||
|
filename = File.basename(path)
|
||||||
|
geometry = params["geo"]
|
||||||
|
|
||||||
|
@decrypted = Tempfile.new(filename, "tmp")
|
||||||
|
@dithered = Tempfile.new([filename, ".png"], "tmp")
|
||||||
|
|
||||||
|
%x(
|
||||||
|
openssl \
|
||||||
|
aes-256-cbc \
|
||||||
|
-d \
|
||||||
|
-in #{ROOT}/#{path}.enc \
|
||||||
|
-out #{@decrypted.path} \
|
||||||
|
-pass file:#{KEY} \
|
||||||
|
-iter 1000000
|
||||||
|
)
|
||||||
|
|
||||||
|
MiniMagick::Tool::Magick.new do |magick|
|
||||||
|
magick << @decrypted.path
|
||||||
|
magick.resize "#{geometry}^"
|
||||||
|
magick.gravity "center"
|
||||||
|
magick.extent geometry
|
||||||
|
magick.ordered_dither "o8x8"
|
||||||
|
magick.monochrome
|
||||||
|
magick << @dithered.path
|
||||||
|
end
|
||||||
|
|
||||||
|
content_type "image/png"
|
||||||
|
File.open(@dithered.path)
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user