The file extension does not change after changing the file type in `minimagick!`

Author: gomoCreated Dec 12, 2023Updated Dec 7, 2024

I want to convert heic to jpg using Mini magick, but it seems that process convert: :jpg does not allow to specify quality, so I created a method and tried to convert it using minimagick!.

ruby
class FileItemUploader < CarrierWave::Uploader::Base
  include CarrierWave::MiniMagick

  process :convert_to_jpeg, if: :heic?

  def filename
    @secure_name ||= "#{SecureRandom.uuid}.#{file.extension}"
    @secure_name
  end

  private

    def heic?(new_file)
      new_file.content_type == 'image/heic'
    end

    def convert_to_jpeg
      minimagick! do |image|
        image
          .quality(80)
          .convert('jpg')
      end
    end
end

The file type is converted to jpg, but the filename extension remains heic.

CarrierWave::SanitizedFile(self.file)inconvert_to_jpegchanges both content_type and file extension to jpg, butCarrierWave::Storage:::Fileinfilename Fog::File(self.file)` is heic.

What I found strange is that converting with process convert: :jpg also changes the extension. It's pretty much the same as the convert source, but my method didn't change it. How can I change it?

https://github.com/carrierwaveuploader/carrierwave/blob/20c6d753f8720c63718de44595351086d71b15bd/lib/carrierwave/processing/mini_magick.rb#L101-L107

Source: carrierwaveuploader/carrierwave