commit 112e101643a5699dc6a2b8ec68e1ad529d32b125
parent 6624c940d99c3e05863680f4b9a3be526ac8129e
Author: David Eisinger <[email protected]>
Date: Fri, 2 Feb 2024 14:27:32 -0500
DITHER=0 to disable dithering
Diffstat:
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/bin/dither/dither.rb b/bin/dither/dither.rb
@@ -5,6 +5,13 @@ MiniMagick.logger.level = Logger::DEBUG
ROOT = ENV["ROOT"]
KEY = ENV["KEY"]
+DITHER = ENV["DITHER"] != "0"
+
+EXTENSION, CONTENT_TYPE = if DITHER
+ [".png", "image/png"]
+else
+ [".webp", "image/webp"]
+end
FileUtils.mkdir_p "tmp"
@@ -13,7 +20,7 @@ get "/*" do |path|
geometry = params["geo"] unless params["geo"] == ""
@decrypted = Tempfile.new(filename, "tmp")
- @dithered = Tempfile.new([filename, ".png"], "tmp")
+ @dithered = Tempfile.new([filename, EXTENSION], "tmp")
%x(
openssl \
@@ -40,11 +47,14 @@ get "/*" do |path|
end
end
- convert.ordered_dither "o8x8"
- convert.monochrome
+ if DITHER
+ convert.ordered_dither "o8x8"
+ convert.monochrome
+ end
+
convert << @dithered.path
convert.call
- content_type "image/png"
+ content_type CONTENT_TYPE
File.open(@dithered.path)
end