DITHER=0 to disable dithering

This commit is contained in:
David Eisinger
2024-02-02 14:27:32 -05:00
parent 6624c940d9
commit 112e101643

View File

@@ -5,6 +5,13 @@ MiniMagick.logger.level = Logger::DEBUG
ROOT = ENV["ROOT"] ROOT = ENV["ROOT"]
KEY = ENV["KEY"] KEY = ENV["KEY"]
DITHER = ENV["DITHER"] != "0"
EXTENSION, CONTENT_TYPE = if DITHER
[".png", "image/png"]
else
[".webp", "image/webp"]
end
FileUtils.mkdir_p "tmp" FileUtils.mkdir_p "tmp"
@@ -13,7 +20,7 @@ get "/*" do |path|
geometry = params["geo"] unless params["geo"] == "" geometry = params["geo"] unless params["geo"] == ""
@decrypted = Tempfile.new(filename, "tmp") @decrypted = Tempfile.new(filename, "tmp")
@dithered = Tempfile.new([filename, ".png"], "tmp") @dithered = Tempfile.new([filename, EXTENSION], "tmp")
%x( %x(
openssl \ openssl \
@@ -40,11 +47,14 @@ get "/*" do |path|
end end
end end
convert.ordered_dither "o8x8" if DITHER
convert.monochrome convert.ordered_dither "o8x8"
convert.monochrome
end
convert << @dithered.path convert << @dithered.path
convert.call convert.call
content_type "image/png" content_type CONTENT_TYPE
File.open(@dithered.path) File.open(@dithered.path)
end end