Fix optimizer temporary file

This commit is contained in:
Vasily Fedoseyev
2024-04-09 23:02:54 +03:00
parent eb26524abe
commit 3e12446120

View File

@@ -22,8 +22,9 @@ module Paperclip
dst_shell = dst_file.path.shellescape
cmd = case real_content_type
when 'image/jpeg', 'image/jpg', 'image/pjpeg'
# TODO: --stdout > #{dst_shell}
"cp #{src_shell} #{dst_shell} && jpegoptim --all-progressive -q --strip-com --strip-exif --strip-iptc -- #{dst_shell}"
# NB: --stdout не работает, там бывают пустые файлы если оно решило ничего не делать
# нельзя `cp`, надо чтобы открытый файл указывал куда надо, поэтому `cat>`
"cat #{src_shell} > #{dst_file} && jpegoptim --all-progressive -q --strip-com --strip-exif --strip-iptc --stdout -- #{dst_shell}"
when 'image/png', 'image/x-png'
"pngcrush -rem alla -q #{src_shell} #{dst_shell}"
when 'image/gif'
@@ -32,6 +33,7 @@ module Paperclip
return
end
run_and_verify!(cmd)
dst_file.tap(&:flush).tap(&:rewind)
dst_file
rescue StandardError => e
dst_file.close!