Skip to content

Commit

Permalink
Fix optimizer temporary file
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasfed committed Apr 9, 2024
1 parent eb26524 commit 3e12446
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/paperclip/optimizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def optimize(_file)
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'
Expand All @@ -32,6 +33,7 @@ def optimize(_file)
return
end
run_and_verify!(cmd)
dst_file.tap(&:flush).tap(&:rewind)
dst_file
rescue StandardError => e
dst_file.close!
Expand Down

0 comments on commit 3e12446

Please sign in to comment.