如何使用ImageMagick在其中心裁剪头像图像

时间:2015-06-28 22:26:24

标签: css ruby-on-rails imagemagick avatar

我试图在它的中心裁剪阿凡达。我在使用CarrierWave gem上传后调整了图像的大小。我遇到的问题是,将头像放在一个圆圈中,它不会居中,也不会填充。

  # encoding: utf-8

  class AvatarUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
    include CarrierWave::RMagick
  # include CarrierWave::MiniMagick

  # Choose what kind of storage to use for this uploader:
     storage :file
   # storage :fog

   # Override the directory where uploaded files will be stored.
   # This is a sensible default for uploaders that are meant to be mounted:
   def store_dir
    "images"
   end

   # Provide a default URL as a default if there hasn't been a file     uploaded:
   # def default_url
   #   # For Rails 3.1+ asset pipeline compatibility:
   #   # ActionController::Base.helpers.asset_path("fallback/" +  [version_name, "default.png"].compact.join('_'))
   #
   #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
   # end

   # Process files as they are uploaded:
     process :scale => [400, 300]
   #
     def scale(width, height)
   #   # do something
     end

    # Create different versions of your uploaded files:

    version :profile_pic do
     process :resize_to_fit => [300, 300]
    end

    version :comment do
      process :resize_to_fit => [80, 80]
    end

   version :logged_in do
     process :resize_to_fit => [40, 40]
   end

    version :backer_avatar_page_view do
      process :resize_to_fit => [80, 80]
    end

    version  :avatar_page_view do 
      process :resize_to_fit => [300, 300]
    end

    version :page_profile_pic do
      process :resize_to_fit => [350, 350]
    end

     version :comment_post_avatar do
       process :resize_to_fit => [50, 50]
     end

     version :dropdown do
       process :resize_to_fit => [50, 50]
     end

     version :backer_avatar do
       process :resize_to_fit => [60, 60]
      end

      end

enter image description here enter image description here

0 个答案:

没有答案