2024-07-04 17:16:52 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class UninterlaceService
|
|
|
|
def process(file)
|
|
|
|
uninterlace_png(file)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def uninterlace_png(uploaded_file)
|
|
|
|
if interlaced?(uploaded_file.to_path)
|
|
|
|
chunky_img = ChunkyPNG::Image.from_io(uploaded_file.to_io)
|
|
|
|
chunky_img.save(uploaded_file.to_path, interlace: false)
|
|
|
|
uploaded_file.reopen(uploaded_file.to_path, 'rb')
|
|
|
|
end
|
|
|
|
uploaded_file
|
|
|
|
end
|
|
|
|
|
|
|
|
def interlaced?(png_path)
|
2024-10-24 18:13:00 +02:00
|
|
|
return false if png_path.blank?
|
2024-07-04 17:16:52 +02:00
|
|
|
png = MiniMagick::Image.open(png_path)
|
|
|
|
png.data["interlace"] != "None"
|
|
|
|
end
|
|
|
|
end
|