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

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

Open
gomo opened this issue Dec 12, 2023 · 1 comment
Open

Comments

@gomo
Copy link

gomo commented Dec 12, 2023

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!.

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?

def convert(format, page=nil, &block)
minimagick!(block) do |builder|
builder = builder.convert(format)
builder = builder.loader(page: page) if page
builder
end
end

@gomo gomo changed the title The file name extension does not change after changing the file type in minimagick! The file extension does not change after changing the file type in minimagick! Dec 12, 2023
@gomo
Copy link
Author

gomo commented Dec 13, 2023

I forgot to write the versions.

  • rails (7.1.1)
  • carrierwave (3.0.5)

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant