Carrierwave RMagick not removing transparency in convert to jpg

前端 未结 1 818
走了就别回头了
走了就别回头了 2021-01-24 21:14

I\'m trying to upload a PNG and save a bunch of thumbnails. The thumbnails should all be JPG and not have any transparency. Somehow the file is saved as jpg but it has transpare

相关标签:
1条回答
  • 2021-01-24 21:42

    There appears to be a quirk with imagemagick and order of operations when converting file types.

    Full github issue can be found here: https://github.com/carrierwaveuploader/carrierwave/issues/133#issuecomment-615254

    Basically manipulate is called once for every process you have. manipulate opens the current file path, makes changes then writes. Because of this it seems that any process lines that are called after the format conversion are performed on the original file, not the newly converted one.

    In order to fix this, you either have to do all of your process operations within a single manipulate block or make sure that the conversion is the last process to run.

    The example of this from the github issue is:

    process :convert_and_scale
    
    def convert_and_scale
      manipulate! do |img|
        img.format 'png'
        img.resize '100x32'
        img
      end
    end
    
    0 讨论(0)
提交回复
热议问题