BigW Consortium Gitlab

Commit 78588cfc by Johann Pardanaud

Improve user experience for avatar cropping

- Avoid incomprehensible errors on non-integer cropping values - Set the default cropping area to 80%
parent 3ca16ec2
......@@ -31,7 +31,6 @@ class @Profile
setTimeout ( -> # The cropper must be asynchronously initialized
$modalCropImg.cropper
aspectRatio: 1
autoCropArea: 1
modal: false
scalable: false
rotatable: false
......
......@@ -10,8 +10,15 @@ class AvatarUploader < CarrierWave::Uploader::Base
process :cropper
def is_integer? string
true if Integer(string) rescue false
end
def cropper
if model.instance_of? User
is_compliant = model.kind_of?(User) && is_integer?(model.avatar_crop_size)
is_compliant = is_compliant && is_integer?(model.avatar_crop_x) && is_integer?(model.avatar_crop_y)
if is_compliant
manipulate! do |img|
img.crop "#{model.avatar_crop_size}x#{model.avatar_crop_size}+#{model.avatar_crop_x}+#{model.avatar_crop_y}"
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment