Open gomo opened 10 months ago
I forgot to write the versions.
thx
To address issues with displaying HEIC images after upload using CarrierWave, follow these steps to convert HEIC files to JPEG format during the upload process:
ImageUploader
Ensure HEIC is included in the list of allowed file extensions:
def extension_white_list
%w(jpg jpeg gif png heic)
end
Add the following method to your ImageUploader
to convert HEIC images to JPEG:
process :convert_heic_to_jpeg , if: :heic?
private
def heic?(file)
file.content_type == 'image/heic' || file.extension.downcase == 'heic'
end
def convert_heic_to_jpeg
cache_stored_file! unless cached?
temp_path = current_path.sub(/\.\w+$/, '.jpg')
image = MiniMagick::Image.open(current_path)
image.format('jpg')
image.write(temp_path)
File.rename(temp_path, current_path.sub(/\.heic\z/i, '.jpg'))
end
jpg
, jpeg
, gif
, png
, heic
).MiniMagick
.This solution ensures compatibility of uploaded HEIC images across various browsers and image processing tools by converting them to JPEG format.
I want to convert heic to jpg using Mini magick, but it seems that
process convert: :jpg
does not allow to specifyquality
, so I created a method and tried to convert it usingminimagick!
.The file type is converted to jpg, but the filename extension remains heic.
CarrierWave::SanitizedFile(self.file)
in
convert_to_jpegchanges both content_type and file extension to jpg, but
CarrierWave::Storage:::Filein
filename 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 theconvert
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