如何从此答案中发送命令:Crop or mask an image into a circle
载波中的?
编辑:我现在有这个:
version :thumb_circle do
# process 'convert -size 350x350 xc:transparent -fill original.jpeg -draw "circle 240,90 300,45" -crop 152x152+164+15 +repage thumb.png'
process :crop_to_circle
end
def crop_to_circle
manipulate! do |img|
img.crop "152x152+164+15"
end
end
我不知道如何从那里开始。我想做的是在注释行
答案 0 :(得分:1)
您可以使用process
传递必要的参数(也称为。命令)。例如:
process :size => [200, 200]
process :xc => 'none'
process :fill => 'walter.jpg'
# etc etc
答案 1 :(得分:0)
process convert: :png
def filename
"#{original_filename.split('.').first}.png" if original_filename
end
def cache_name
File.join(cache_id, [version_name, filename].compact.join('_')) if cache_id and original_filename
end
version :thumb do
process :crop_to_get_square_image # you already did this
process :round_image
process :any_resize_or_process
end
private
def round_image
manipulate! do |img|
path = img.path
new_tmp_path = File.join(Rails.root, 'public', cache_dir, "/round_#{File.basename(path)}")
width, height = img[:dimensions]
radius_point = ((width > height) ? [width / 2, height] : [width, height / 2]).join(',')
imagemagick_command = ['convert',
"-size #{ width }x#{ height }",
'xc:transparent',
"-fill #{ path }",
"-draw 'circle #{ width / 2 },#{ height / 2 } #{ radius_point }'",
"+repage #{new_tmp_path}"].join(' ')
system(imagemagick_command)
MiniMagick::Image.open(new_tmp_path)
end
end
编辑:这将使图像圆形化。