photofy 0.5.5 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/photofy/core.rb +29 -16
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a52ce7b29743b3206b06d5f9e4cc7675942410a7
|
4
|
+
data.tar.gz: c9d927a0fe18e9cdf4a504468a76560c69a28e3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83f4520d79373a4986eedfd27ee7936d1a692a808e89d59a6d233bd7607389784fa66df1e062826a8401857b0eb6b9f3545e124536abf45a18c7502946dc405f
|
7
|
+
data.tar.gz: 4d42053a929877b537be04c3265847540b101e9a84a7481c71533e77257a8ae9857125ba8ca69d6ebd0a63a413cf75122c4ddf620c41577bfbe71231c026bc16
|
data/lib/photofy/core.rb
CHANGED
@@ -21,7 +21,7 @@ module Photofy
|
|
21
21
|
#will give a 'stamp' attribute which on save of 'profile' photo field will scale it to 25 x 25 dimensions
|
22
22
|
#after_photofy :profile, :portfolio, Proc.new{|img| img.scale(150, 250)}
|
23
23
|
#will give a 'portfolio' attribute which on save of 'profile' photo field will scale it to 150 x 250 dimensions
|
24
|
-
def after_photofy(parent_photo_field, photo_field, proc = Proc.new {
|
24
|
+
def after_photofy(parent_photo_field, photo_field, proc = Proc.new {|img| puts "Rmagick image: #{img.inspect}"})
|
25
25
|
photofy(photo_field, image_processor: proc, parent_photo_field: parent_photo_field)
|
26
26
|
end
|
27
27
|
|
@@ -97,11 +97,11 @@ module Photofy
|
|
97
97
|
send('initialize_photo_buffers')
|
98
98
|
|
99
99
|
if @photo_file_buffer[photo_field].nil?
|
100
|
-
if
|
100
|
+
if s3_connected?
|
101
101
|
if send("#{photo_field}_persisted?")
|
102
102
|
_file = nil
|
103
103
|
file = Tempfile.new('foo', :encoding => 'ascii-8bit')
|
104
|
-
s3_bucket.objects[send("#{photo_field}_path")].read {
|
104
|
+
s3_bucket.objects[send("#{photo_field}_path")].read {|chunk| file.write(chunk)}
|
105
105
|
file.rewind
|
106
106
|
_file = file.read
|
107
107
|
file.close
|
@@ -148,14 +148,27 @@ module Photofy
|
|
148
148
|
|
149
149
|
file_upload.rewind
|
150
150
|
elsif file_upload.class == String
|
151
|
-
|
152
|
-
#
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
151
|
+
|
152
|
+
# For handling base 64 encoded image
|
153
|
+
if file_upload.match(/\Adata:([-\w]+\/[-\w\+\.]+)?;base64,/)
|
154
|
+
file_upload_parts = file_upload.match(/\Adata:([-\w]+\/[-\w\+\.]+)?;base64,(.*)/m) || []
|
155
|
+
extension = MIME::Types[file_upload_parts[1]].first.preferred_extension
|
156
|
+
|
157
|
+
unless self.class.photo_formats[photo_field].include?(".#{extension}")
|
158
|
+
(@photo_fields_errors ||= {})[photo_field.to_sym] = options[:message]
|
159
|
+
return false
|
160
|
+
else
|
161
|
+
(@photo_fields_errors ||= {}).delete(photo_field.to_sym)
|
162
|
+
end
|
163
|
+
|
164
|
+
@photo_file_buffer[photo_field] = Base64.decode64(file_upload_parts[2])
|
165
|
+
@photo_file_ofn[photo_field] = "#{SecureRandom.uuid}.#{extension}"
|
166
|
+
|
167
|
+
else
|
168
|
+
@photo_file_buffer[photo_field] = file_upload
|
169
|
+
|
170
|
+
end
|
171
|
+
|
159
172
|
end
|
160
173
|
|
161
174
|
file_upload
|
@@ -186,7 +199,7 @@ module Photofy
|
|
186
199
|
_parent_file_path = send("#{parent_photo_field}_path")
|
187
200
|
_temp_file_path = File.join(Rails.root, File.basename(_parent_file_path))
|
188
201
|
file = File.open(_temp_file_path, 'wb')
|
189
|
-
s3_bucket.objects[_parent_file_path].read {
|
202
|
+
s3_bucket.objects[_parent_file_path].read {|chunk| file.write(chunk)}
|
190
203
|
file.close
|
191
204
|
file = File.open(_temp_file_path)
|
192
205
|
send("#{photo_field}=", file)
|
@@ -206,7 +219,7 @@ module Photofy
|
|
206
219
|
|
207
220
|
unless proc.nil?
|
208
221
|
file = Tempfile.new('foo', :encoding => 'ascii-8bit')
|
209
|
-
s3_bucket.objects[send("#{photo_field}_path")].read {
|
222
|
+
s3_bucket.objects[send("#{photo_field}_path")].read {|chunk| file.write(chunk)}
|
210
223
|
file.rewind
|
211
224
|
|
212
225
|
img = Magick::Image.read(file.path).first
|
@@ -217,8 +230,8 @@ module Photofy
|
|
217
230
|
file.unlink # deletes the temp file
|
218
231
|
end
|
219
232
|
else
|
220
|
-
File.delete(send("#{photo_field}_path")) if
|
221
|
-
File.open(send("#{photo_field}_path_to_write"), "wb+") {
|
233
|
+
File.delete(send("#{photo_field}_path")) if File.exist?(send("#{photo_field}_path")) #Clearing any existing file at the path
|
234
|
+
File.open(send("#{photo_field}_path_to_write"), "wb+") {|f| f.puts(@photo_file_buffer[photo_field])}
|
222
235
|
|
223
236
|
unless proc.nil?
|
224
237
|
FileUtils.copy(send("#{photo_field}_path_to_write"), send("#{photo_field}_path_to_write", "original_source"))
|
@@ -263,7 +276,7 @@ module Photofy
|
|
263
276
|
def collect_photo_formats(photo_field, options)
|
264
277
|
if options.is_a?(Hash)
|
265
278
|
@@photo_formats ||= {}
|
266
|
-
@@photo_formats[photo_field] = options[:formats].is_a?(Array) ? options[:formats].collect {
|
279
|
+
@@photo_formats[photo_field] = options[:formats].is_a?(Array) ? options[:formats].collect {|x| x.starts_with?(".") ? x : ".#{x}"} : [".jpeg", ".jpg", ".gif", ".png", ".bmp"]
|
267
280
|
else
|
268
281
|
raise 'InvalidArguments'
|
269
282
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: photofy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Praveen Kumar Sinha
|
@@ -10,11 +10,12 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: |2
|
16
16
|
A simple gem to add accessors on rails models for file upload of pictures/assets (which will be persisted on remote media's disk on object save).
|
17
17
|
Refer documentation for more help.
|
18
|
+
Latest happening: Now with Base64 encoded image support.
|
18
19
|
email: praveen.kumar.sinha@gmail.com
|
19
20
|
executables: []
|
20
21
|
extensions: []
|
@@ -45,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
46
|
version: '0'
|
46
47
|
requirements: []
|
47
48
|
rubyforge_project:
|
48
|
-
rubygems_version: 2.
|
49
|
+
rubygems_version: 2.6.12
|
49
50
|
signing_key:
|
50
51
|
specification_version: 4
|
51
52
|
summary: Photofy
|