首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何规范CarrierWave MiniMagick操作

如何规范CarrierWave MiniMagick操作
EN

Stack Overflow用户
提问于 2018-03-03 01:18:03
回答 1查看 620关注 0票数 2

在我的CarrierWave上传工具上为我的"auto_orient“实现编写RSpec测试时遇到了麻烦。我也没有在网上找到太多关于这件事的爱。

我知道操纵方法将由gem指定,但我只想用RSpec验证我的ImageUploader是否正确地实现了它。

代码语言:javascript
复制
    class ImageUploader < CarrierWave::Uploader::Base
      include CarrierWave::MiniMagick

      ...

      version :tile do
        process :auto_orient
      end

      # Fix images being uploaded the wrong orientation
      def auto_orient
        manipulate! do |img|
          img = img.auto_orient
        end
      end



    let(:uploader) { ImageUploader.new(profile, :avatar) }

    before do
      ImageUploader.enable_processing = true
      File.open(File.join(Rails.root, '/spec/support/images/logo.png')) { |f| uploader.store!(f) }
    end

    after do
      ImageUploader.enable_processing = false
      uploader.remove!
    end

    xit 'runs auto_orient on the image' do
      # ???
    end

谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-04-07 01:51:37

我不是100%确定如何在MiniMagick中做到这一点,但这里是我如何使用RMagick解决这个问题的,如果这有帮助的话。我想应该是一种类似的方法。

代码语言:javascript
复制
uploader.cache_stored_file!
# For minimagick, you would probably use MiniMagick::Image::read
mg = ::Magick::Image::read(uploader.file.file).first
# Not sure if minimagick has an "orient" attribute, might try reading the data using something from here instead: https://github.com/probablycorey/mini_magick/blob/master/lib/mini_magick.rb#L204
expect(mg.orientation.to_i).to eq(1)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49074167

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档