avatars_for_rails 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 63ef1090f4e07e335c723459840581f7def14992
4
- data.tar.gz: 774ff99df0041eac6cb9102cd0bfa782087a2d25
3
+ metadata.gz: 4ebebb8262563aef39e2d376b00a5d2f2839ef29
4
+ data.tar.gz: 6f0b38c248043d84f949d73d2d5307b3851abed9
5
5
  SHA512:
6
- metadata.gz: 1ad93d034158dc05bc6df8bae686ead9c6d0eb2df439b6d8c426c3c799785acf47c742758cb073f3414a7790f233a0ee9930be98d71143b9b76c092e7cd163a5
7
- data.tar.gz: 3a7dfb5677270b6c0471d77cb11cb0b0c57af8d0520fcc9eb85c3b2878171d897a0fc5cb62b37d680fb0c5293f5413b9795b9cbd92478139d06fe1c3275404ac
6
+ metadata.gz: 0473b4237bdba0f6e32462b4b13fe98ddc0ae568d4878914ef9528e96986a94e48b9f34eb658fa0a1a1af362b2aeedfe94447453fd42de667ff7e4862d29a18c
7
+ data.tar.gz: f2fce31f7c0490717adbf2df9e42238b9b0c793386e68ebce7d39891a69e1acf841efea49f228f754b4a104583b1fc729e44d9261934ab7c2c6625b2df4c22c0
@@ -46,13 +46,20 @@ var AvatarForRails = AvatarForRails || (function($, undefined) {
46
46
  };
47
47
 
48
48
  var initCrop = function(data) {
49
- var div = $('section.avatar .update');
49
+ var div = $('section.avatar .update'),
50
+ img,
51
+ ar;
52
+
50
53
  div.html(data);
51
- div.find('img.crop').Jcrop({
54
+
55
+ img = div.find('img.crop'),
56
+ ar = parseInt(img.attr('data-aspect_ratio'), 10);
57
+
58
+ img.Jcrop({
52
59
  bgColor: 'clear',
53
60
  bgOpacity: 0.6,
54
- setSelect: [ 0, 0, 200, 200 ],
55
- aspectRatio: 1,
61
+ setSelect: [ 0, 0, 200, 200 / ar ],
62
+ aspectRatio: ar,
56
63
  onSelect: updateCrop,
57
64
  onChange: updateCrop
58
65
  });
@@ -71,7 +78,6 @@ var AvatarForRails = AvatarForRails || (function($, undefined) {
71
78
  $('input[name*="logo_crop_x"]').val(coords.x / iW);
72
79
  $('input[name*="logo_crop_y"]').val(coords.y / iH);
73
80
  $('input[name*="logo_crop_w"]').val(coords.w / iW);
74
- $('input[name*="logo_crop_h"]').val(coords.h / iH);
75
81
  };
76
82
 
77
83
  addEditCallback(initFileUpload);
@@ -1,7 +1,7 @@
1
- <%= image_tag avatarable.avatar_tmp_public_path(root_path), class: 'crop' %>
1
+ <%= image_tag avatarable.avatar_tmp_public_path(root_path), class: 'crop', "data-aspect_ratio" => avatarable.class.logo_aspect_ratio %>
2
2
 
3
3
  <%= form_for avatarable, url: avatar_path, multipart: true do |f| %>
4
- <% %w( x y w h ).each do |attr| %>
4
+ <% %w( x y w ).each do |attr| %>
5
5
  <%= f.hidden_field "logo_crop_#{ attr }" %>
6
6
  <% end %>
7
7
  <%= f.hidden_field :avatar_tmp_basename %>
@@ -3,6 +3,9 @@ module AvatarsForRails
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  included do
6
+ cattr_accessor :logo_aspect_ratio
7
+ self.logo_aspect_ratio = 1
8
+
6
9
  attr_accessor :logo_crop, :logo_crop_x, :logo_crop_y, :logo_crop_w, :logo_crop_h,
7
10
  :avatar_tmp_basename
8
11
 
@@ -43,7 +46,7 @@ module AvatarsForRails
43
46
  def validate_crop_params
44
47
  return if logo_crop_x.blank?
45
48
 
46
- %w( x y w h ).each do |attr|
49
+ %w( x y w ).each do |attr|
47
50
  send "logo_crop_#{ attr }=", send("logo_crop_#{ attr }").to_f
48
51
  end
49
52
 
@@ -57,10 +60,12 @@ module AvatarsForRails
57
60
 
58
61
  width, height = avatar_tmp_file_dimensions
59
62
 
60
- avatar_magick_image.crop!(logo_crop_x * width,
61
- logo_crop_y * height,
62
- logo_crop_w * width,
63
- logo_crop_h * height)
63
+ crop_x = (logo_crop_x * width).round
64
+ crop_y = (logo_crop_y * height).round
65
+ crop_w = (logo_crop_w * width).round
66
+ crop_h = crop_w / self.class.logo_aspect_ratio
67
+
68
+ avatar_magick_image.crop!(crop_x, crop_y, crop_w, crop_h)
64
69
 
65
70
  avatar_magick_image.write(avatar_tmp_full_path)
66
71
 
@@ -1,3 +1,3 @@
1
1
  module AvatarsForRails
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avatars_for_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jaime Castro Montero
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-08 00:00:00.000000000 Z
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: jquery-rails