scottmotte-amazonavatar 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,9 +4,10 @@ Upload avatars to amazonS3 on a User (or other) model. Simple and opinionated.
4
4
 
5
5
  == Notes
6
6
 
7
+ * rdoc is at: http://rdoc.info/projects/scottmotte/amazonavatar
7
8
  * I'm using it with merb and mongomapper.
8
9
  * Does resizing using minimagick
9
- * Uploads the images to your s3 account at /avatars/user_id/[original.png,thumb.png,mini.png]
10
+ * Uploads the images to your s3 account at / avatars / user_id / [original.png,thumb.png,mini.png]
10
11
  * Resizes a thumb to 48x48, and mini to 24x24. I told you it was opinionated.
11
12
 
12
13
  == Dependencies
@@ -36,7 +37,7 @@ On your computer
36
37
 
37
38
  Or for bundling
38
39
 
39
- dependency 'scottmotte-amazonavatar'
40
+ dependency 'scottmotte-amazonavatar', :require_as => 'amazonavatar'
40
41
 
41
42
  == Configuration
42
43
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/amazonavatar.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{amazonavatar}
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["scottmotte"]
9
- s.date = %q{2009-07-12}
9
+ s.date = %q{2009-07-21}
10
10
  s.email = %q{scott@scottmotte.com}
11
11
  s.extra_rdoc_files = [
12
12
  "LICENSE",
data/lib/amazonavatar.rb CHANGED
@@ -31,7 +31,7 @@ module AmazonAvatar
31
31
 
32
32
  # Defin connection using RightAws
33
33
  def self.connection
34
- @@connection ||= RightAws::S3.new(access_key_id, secret_access_key)
34
+ @@connection ||= RightAws::S3.new(access_key_id, secret_access_key, {:multi_thread => true})
35
35
  end
36
36
 
37
37
  # AmazonAvatar.bucket = "bucket_name"
@@ -75,35 +75,36 @@ module AmazonAvatar
75
75
  def put_avatar(avatar)
76
76
  # Original
77
77
  key1 = bucket.key("avatars/#{id}/#{@@avatars[:original][:filename]}")
78
- key1.put(avatar[:tempfile].read, 'public-read')
78
+ key1.put(avatar[:tempfile].read, 'public-read', {'Content-Type'=>'image/png','Cache-Control' => 'public,max-age=31536000'})
79
79
 
80
- # data
81
- data = MiniMagick::Image.from_file(avatar[:tempfile].path)
82
- # thumb
83
- key2 = bucket.key("avatars/#{id}/#{@@avatars[:thumb][:filename]}")
84
- key2.put(resize_and_crop(data, @@avatars[:thumb][:dimensions]).to_blob, 'public-read')
85
- # mini
86
- key3 = bucket.key("avatars/#{id}/#{@@avatars[:mini][:filename]}")
87
- key3.put(resize_and_crop(data, @@avatars[:mini][:dimensions]).to_blob, 'public-read')
80
+ # image
81
+ image = MiniMagick::Image.from_file(avatar[:tempfile].path)
82
+ # resized
83
+ put_resized(bucket,id,image)
88
84
  end
89
85
 
90
86
  # upload default start avatars. this needs to be replaced with a default image somehow
91
87
  def generate_default_avatar
92
88
  # Original
93
89
  key1 = bucket.key("avatars/#{id}/#{@@avatars[:original][:filename]}")
94
- key1.put(File.new("#{AmazonAvatar.dir}/default.png").read, 'public-read')
90
+ key1.put(File.new("#{AmazonAvatar.dir}/default.png").read, 'public-read', {'Content-Type'=>'image/png','Cache-Control' => 'public,max-age=31536000'})
95
91
 
96
92
  # image
97
93
  image = MiniMagick::Image.from_file("#{AmazonAvatar.dir}/default.png")
94
+ # resized
95
+ put_resized(bucket,id,image)
96
+ end
97
+
98
+ private
99
+ def put_resized(bucket,id,image)
98
100
  # thumb
99
101
  key2 = bucket.key("avatars/#{id}/#{@@avatars[:thumb][:filename]}")
100
- key2.put(resize_and_crop(image, @@avatars[:thumb][:dimensions]).to_blob, 'public-read')
102
+ key2.put(resize_and_crop(image, @@avatars[:thumb][:dimensions]).to_blob, 'public-read', {'Content-Type'=>'image/png','Cache-Control' => 'public,max-age=31536000'})
101
103
  # mini
102
104
  key3 = bucket.key("avatars/#{id}/#{@@avatars[:mini][:filename]}")
103
- key3.put(resize_and_crop(image, @@avatars[:mini][:dimensions]).to_blob, 'public-read')
105
+ key3.put(resize_and_crop(image, @@avatars[:mini][:dimensions]).to_blob, 'public-read', {'Content-Type'=>'image/png','Cache-Control' => 'public,max-age=31536000'})
104
106
  end
105
107
 
106
-
107
108
  def resize_and_crop(image, size)
108
109
  if image[:width] < image[:height]
109
110
  remove = ((image[:height] - image[:width])/2).round
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scottmotte-amazonavatar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - scottmotte
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-12 00:00:00 -07:00
12
+ date: 2009-07-21 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency