DITHER=0 to disable dithering
This commit is contained in:
@@ -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
|
||||||
|
|
||||||
|
if DITHER
|
||||||
convert.ordered_dither "o8x8"
|
convert.ordered_dither "o8x8"
|
||||||
convert.monochrome
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user