photofy 0.0.2 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/photofy.rb +57 -7
- metadata +17 -18
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec1560ea85ea9034a20b8a76dd3ceb0c9d5198d4
|
4
|
+
data.tar.gz: 84bb74cf0fdee32a3af2bdbc9977e1921473a4be
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4eb138ccebf70a8ff9dc724b5ed5e8b426f0f57a3a430caa285c50688a0c16c3758fe39debd9bec688c708d331710ea25a5c6e583d83e80eb04481aec96e5304
|
7
|
+
data.tar.gz: 98662d31c2e5d0ee89245997eb76ffd22a914230daa6303d8fef8c61d9bcfc8733a343e00175f3348d4582fcca1fa7a072f441ac237abf957250c036fec22ddd
|
data/lib/photofy.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
begin
|
2
|
+
require "RMagick"
|
3
|
+
rescue Exception => e
|
4
|
+
puts "Unable to load 'RMagick' for after_photofy methods"
|
5
|
+
end
|
6
|
+
|
1
7
|
module Photofy
|
2
8
|
def self.included(base)
|
3
9
|
base.extend(ClassMethods)
|
@@ -9,6 +15,49 @@ module Photofy
|
|
9
15
|
attr_accessor :photo_repository
|
10
16
|
attr_accessor :photo_formats
|
11
17
|
|
18
|
+
#Generates photo field from photo_field argument which can be used to store a post processed image(using rmagick) of originally uploaded.
|
19
|
+
#Takes two arguments:
|
20
|
+
#1. field name
|
21
|
+
#2. Proc with rmagick img object
|
22
|
+
#return value should be an object of rmagick's image object
|
23
|
+
#
|
24
|
+
#Example usage..
|
25
|
+
#after_photofy :stamp, Proc.new{|img| img.scale(25, 25)}
|
26
|
+
#will give a 'stamp' attribute which on save of main photo filed will scale it to 25 x 25 dimesnions
|
27
|
+
#after_photofy :portfolio, Proc.new{|img| img.scale(150, 250)}
|
28
|
+
#will give a 'portfolio' attribute which on save of main photo filed will scale it to 150 x 250 dimesnions
|
29
|
+
def after_photofy(photo_field, p = Proc.new { |img| puts "Rmagick image: #{img.inspect}" })
|
30
|
+
define_method "#{photo_field}" do
|
31
|
+
File.exist?(send("#{photo_field}_path")) ? File.read(send("#{photo_field}_path")) : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
define_method "#{photo_field}_path" do
|
35
|
+
directoy_path = FileUtils.mkdir_p File.join(self.class.photo_repository, self.class.photo_field.to_s)
|
36
|
+
File.join(directoy_path, "#{photo_field}.jpg")
|
37
|
+
end
|
38
|
+
|
39
|
+
define_method "process_n_save_#{photo_field}" do
|
40
|
+
begin
|
41
|
+
mphoto_f = self.class.photo_field
|
42
|
+
if File.exist?(send("#{mphoto_f}_path"))
|
43
|
+
img = Magick::Image.read(send("#{mphoto_f}_path")).first # path of Orignal image that has to be worked upon
|
44
|
+
img = p.call(img)
|
45
|
+
img.write(send("#{photo_field}_path"))
|
46
|
+
end
|
47
|
+
rescue Exception => e
|
48
|
+
puts "Unable to process_n_save_#{photo_field} due to #{e.message}"
|
49
|
+
e.backtrace.each { |trace| puts trace }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
define_method "destroy_#{photo_field}" do
|
54
|
+
File.delete(send("#{photo_field}_path")) if File.exist?(send("#{photo_field}_path"))
|
55
|
+
end
|
56
|
+
|
57
|
+
send(:after_save, "process_n_save_#{photo_field}")
|
58
|
+
send(:after_destroy, "destroy_#{photo_field}")
|
59
|
+
end
|
60
|
+
|
12
61
|
#Getter to check if model is enabled with photofied
|
13
62
|
def is_photofield?
|
14
63
|
@photofield_flag.nil? ? false : @photofield_flag
|
@@ -21,12 +70,12 @@ module Photofy
|
|
21
70
|
|
22
71
|
#Generates photo filed from photo_field arguments and provides methods like
|
23
72
|
#if photo_filed is "collage" then it provides methods on top of it as
|
24
|
-
#collage
|
25
|
-
#collage =
|
26
|
-
#collage_path
|
27
|
-
#collage_persisted?
|
28
|
-
#collage_store!
|
29
|
-
#collage_destroy!
|
73
|
+
#collage >> Getter,
|
74
|
+
#collage = >> Setter. Accepted inputs are file upload(ActionDispatch::Http::UploadedFile), filer handle and String(format validation is ignored),
|
75
|
+
#collage_path >> Getter of filepath,
|
76
|
+
#collage_persisted? >> true if provided file/data is stored on disk,
|
77
|
+
#collage_store! >> to store provided file/data on disk,
|
78
|
+
#collage_destroy! >> to store destroy stored file/data from disk
|
30
79
|
def photofy(photo_filed, options = {})
|
31
80
|
if options.is_a?(Hash)
|
32
81
|
@photo_formats = options[:formats].is_a?(Array) ? options[:formats].collect { |x| x.starts_with?(".") ? x : ".#{x}" } : [".bmp", ".jpg", ".jpeg"]
|
@@ -84,8 +133,9 @@ module Photofy
|
|
84
133
|
def photo_repository
|
85
134
|
@photo_repository ||= FileUtils.mkdir_p File.join(Rails.root, "photofied", self.name)
|
86
135
|
end
|
136
|
+
|
87
137
|
end
|
88
138
|
|
89
139
|
end
|
90
140
|
|
91
|
-
ActiveRecord::Base.send(:include, Photofy)
|
141
|
+
ActiveRecord::Base.send(:include, Photofy)
|
metadata
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: photofy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Praveen Kumar Sinha
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2012-
|
11
|
+
date: 2012-03-15 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
|
-
description:
|
15
|
-
getter setter methods of it and save on model object commit
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
filer handle and String(no format validation is ignored)
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
description: |-
|
14
|
+
A gem to provide simple method to do file upload of pictures and provides getter setter methods of it and save on model object commit.
|
15
|
+
#Generates photo filed from photo_field arguments and provides methods like
|
16
|
+
#if photo_filed is "collage" then it provides methods on top of it as
|
17
|
+
#collage >> Getter,
|
18
|
+
#collage = >> Setter. Accepted inputs are file upload(ActionDispatch::Http::UploadedFile), filer handle and String(no format validation is ignored),
|
19
|
+
#collage_path >> Getter of filepath,
|
20
|
+
#collage_persisted? >> true if provided file/data is stored on disk,
|
21
|
+
#collage_store! >> to store provided file/data on disk,
|
22
|
+
#collage_destroy! >> to store destroy stored file/data from disk
|
23
23
|
email: praveen.kumar.sinha@gmail.com
|
24
24
|
executables: []
|
25
25
|
extensions: []
|
@@ -28,26 +28,25 @@ files:
|
|
28
28
|
- lib/photofy.rb
|
29
29
|
homepage: https://github.com/praveenkumarsinha/Photofy
|
30
30
|
licenses: []
|
31
|
+
metadata: {}
|
31
32
|
post_install_message:
|
32
33
|
rdoc_options: []
|
33
34
|
require_paths:
|
34
35
|
- lib
|
35
36
|
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
42
|
requirements:
|
44
|
-
- -
|
43
|
+
- - '>='
|
45
44
|
- !ruby/object:Gem::Version
|
46
45
|
version: '0'
|
47
46
|
requirements: []
|
48
47
|
rubyforge_project:
|
49
|
-
rubygems_version:
|
48
|
+
rubygems_version: 2.0.0.rc.2
|
50
49
|
signing_key:
|
51
|
-
specification_version:
|
50
|
+
specification_version: 4
|
52
51
|
summary: Photofy
|
53
52
|
test_files: []
|