fix: uninterlace only interlaced png
This commit is contained in:
parent
46edaed6bc
commit
7529294845
1 changed files with 6 additions and 1 deletions
|
@ -4,11 +4,16 @@ module UninterlacePngConcern
|
|||
private
|
||||
|
||||
def uninterlace_png(uploaded_file)
|
||||
if uploaded_file&.content_type == 'image/png'
|
||||
if uploaded_file&.content_type == 'image/png' && interlaced?(uploaded_file.tempfile.to_path)
|
||||
chunky_img = ChunkyPNG::Image.from_io(uploaded_file.to_io)
|
||||
chunky_img.save(uploaded_file.tempfile.to_path, interlace: false)
|
||||
uploaded_file.tempfile.reopen(uploaded_file.tempfile.to_path, 'rb')
|
||||
end
|
||||
uploaded_file
|
||||
end
|
||||
|
||||
def interlaced?(png_path)
|
||||
png = MiniMagick::Image.open(png_path)
|
||||
png.data["interlace"] != "None"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue