Commit 78588cfc authored by Johann Pardanaud's avatar 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 ...@@ -31,7 +31,6 @@ class @Profile
setTimeout ( -> # The cropper must be asynchronously initialized setTimeout ( -> # The cropper must be asynchronously initialized
$modalCropImg.cropper $modalCropImg.cropper
aspectRatio: 1 aspectRatio: 1
autoCropArea: 1
modal: false modal: false
scalable: false scalable: false
rotatable: false rotatable: false
......
...@@ -10,8 +10,15 @@ class AvatarUploader < CarrierWave::Uploader::Base ...@@ -10,8 +10,15 @@ class AvatarUploader < CarrierWave::Uploader::Base
process :cropper process :cropper
def is_integer? string
true if Integer(string) rescue false
end
def cropper 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| manipulate! do |img|
img.crop "#{model.avatar_crop_size}x#{model.avatar_crop_size}+#{model.avatar_crop_x}+#{model.avatar_crop_y}" img.crop "#{model.avatar_crop_size}x#{model.avatar_crop_size}+#{model.avatar_crop_x}+#{model.avatar_crop_y}"
end 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