Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep original image format when using MiniMagick unless explicited #2626

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions lib/carrierwave/processing/mini_magick.rb
Expand Up @@ -289,22 +289,25 @@ def manipulate!
#
# [CarrierWave::ProcessingError] if processing failed.
def minimagick!(block = nil)
builder = ImageProcessing::MiniMagick.source(current_path)
builder = yield(builder)
builder = ImageProcessing::MiniMagick.source(current_path).convert(content_type)

original_format = builder.options[:format]
builder = yield(builder)
new_format = builder.options[:format]
result = builder.call
result.close

# backwards compatibility (we want to eventually move away from MiniMagick::Image)
if block
# TODO: do we want to still support this, or remove it?
image = ::MiniMagick::Image.new(result.path, result)
image = block.call(image)
result = image.instance_variable_get(:@tempfile)
end

FileUtils.mv result.path, current_path

if File.extname(result.path) != File.extname(current_path)
if original_format != new_format
move_to = current_path.chomp(File.extname(current_path)) + File.extname(result.path)
file.content_type = Marcel::Magic.by_path(move_to).try(:type)
file.move_to(move_to, permissions, directory_permissions)
Expand Down