balloon 1.1.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc46fceeceeb3953a4fb862908220119cc1948b056abc8cbe1e8ad4fa8092780
4
- data.tar.gz: 15eb52b4210ccb0498ecdaa1711cf6b5b4ae0198245d4cf45a2fe63d36c00ea0
3
+ metadata.gz: 909d8652d1b69823ed4a0a65e8802e5adf41fe37183111ad6d0f9e4035e7e882
4
+ data.tar.gz: 23e566f565e83f05d92740761ad7b9d1c6b851e73e038d23d9cac833ae09f483
5
5
  SHA512:
6
- metadata.gz: 9d72137b38be30a8258aff896766de9e24aac3462cb3d760975a1eab78ba4c6251776416619201915238d9f0185439432a2fd6de124d8314a508d96505f29374
7
- data.tar.gz: f9046e55e3387ecd448b0b5caaf3f38e41decf4e41f50d9f5d70545e93c46f89c62f7295353bbb362b45c16cf0e2eb9b4013162a5c3ff86f23cefbc7dae949f1
6
+ metadata.gz: 99174822071a213f398c7fcec40c40f232852dce889f095241df9a7225099040cef5834104b878a1a41398231fad1624b29e286ca5b8063f5629cec017249459
7
+ data.tar.gz: 4c12e055ccc06b235e951b3edeb0f5adad4d04f58a2ff9a282827302199c1422bcb8f481884313143e9c32046e9599117e24fa6a9c4f6e6d8c92ceaf19d64b18
data/README.md CHANGED
@@ -145,9 +145,14 @@ class CreateImages < ActiveRecord::Migration
145
145
  t.integer :width
146
146
  t.integer :height
147
147
  t.string :content_type
148
- t.integer :file_size
148
+ t.bigint :file_size
149
149
  t.string :storage
150
- t.datetime :created_at
150
+
151
+ # Postgresql 可以JSONB 作为metadata格式
152
+ t.jsonb :metadata
153
+ # Mysql和其它需要使用text
154
+ t.text :metadata
155
+
151
156
  t.timestamps
152
157
  end
153
158
  end
data/examples/upload.rb CHANGED
@@ -10,7 +10,7 @@ class Upload < Balloon::Base
10
10
  uploader :image
11
11
  uploader_dir 'uploads'
12
12
  uploader_mimetype_white %w[image/jpeg image/png image/gif image/webp]
13
- uploader_name_format name: "output", format: 'upcase'
13
+ uploader_name_format name: 'output', format: 'upcase'
14
14
  uploader_type_format 'webp'
15
15
  uploader_size thumb: '200x', small: '600x>', large: '800x>'
16
16
  end
@@ -5,6 +5,7 @@ module Balloon
5
5
  extend ActiveSupport::Concern
6
6
 
7
7
  def image_processing(image)
8
+ data = {}
8
9
  ext = image.extension
9
10
 
10
11
  if respond_to?(:uploader_type_format)
@@ -12,8 +13,10 @@ module Balloon
12
13
  end
13
14
 
14
15
  processed_img = handle_original(image, ext)
16
+ data[:original] = get_image_data(processed_img)
15
17
 
16
- handle_resize(image, ext)
18
+ resized_img = handle_resize(image, ext)
19
+ data.merge!(resized_img)
17
20
 
18
21
  mime_type = processed_img.mime_type
19
22
  extension = FileExtension.get_extension(mime_type)
@@ -26,7 +29,8 @@ module Balloon
26
29
  size: processed_img.size,
27
30
  filename: filename,
28
31
  mime_type: mime_type,
29
- extension: extension
32
+ extension: extension,
33
+ data: data
30
34
  }
31
35
  end
32
36
 
@@ -46,8 +50,9 @@ module Balloon
46
50
  end
47
51
 
48
52
  def handle_resize(file, ext)
49
- return unless self.respond_to?(:uploader_size)
50
- return if store_storage.to_s == "upyun" && upyun_is_image
53
+ return {} unless self.respond_to?(:uploader_size)
54
+ return {} if store_storage.to_s == "upyun" && upyun_is_image
55
+ data = {}
51
56
 
52
57
  uploader_size.each do |size, o|
53
58
  img = MiniMagick::Image.open(file.path)
@@ -64,8 +69,11 @@ module Balloon
64
69
  convert << cache_file
65
70
  convert.call
66
71
 
67
- # img.write File.join(cache_path, "#{file.basename}_#{size}.#{ext}")
72
+ processed_img = MiniMagick::Image.open(cache_file)
73
+ data[size] = get_image_data(processed_img)
68
74
  end
75
+
76
+ return data
69
77
  end
70
78
 
71
79
  def resize(convert, image, size)
@@ -78,7 +86,6 @@ module Balloon
78
86
  else
79
87
  convert.resize "#{width}x#{height}#{symbol}"
80
88
  end
81
-
82
89
  return
83
90
  end
84
91
 
@@ -86,19 +93,18 @@ module Balloon
86
93
  shave(convert, image)
87
94
  value = (width.to_f / image[:width].to_f) * 100
88
95
  convert.resize "#{value}%"
89
- else
90
- if width.empty?
91
- value = (height.to_f / image[:height].to_f) * 100
92
- convert.resize "#{value}%"
93
- elsif height.empty?
94
- value = (width.to_f / image[:width].to_f) * 100
95
- convert.resize "#{value}%"
96
- else
97
- convert.resize "#{width}x#{height}"
98
- end
96
+ return
99
97
  end
100
98
 
101
- return
99
+ if width.empty?
100
+ value = (height.to_f / image[:height].to_f) * 100
101
+ convert.resize "#{value}%"
102
+ elsif height.empty?
103
+ value = (width.to_f / image[:width].to_f) * 100
104
+ convert.resize "#{value}%"
105
+ else
106
+ convert.resize "#{width}x#{height}"
107
+ end
102
108
  end
103
109
 
104
110
  def shave(convert, image)
@@ -107,10 +113,11 @@ module Balloon
107
113
  if w > h
108
114
  shave_off = ((w - h) / 2).round
109
115
  convert.shave "#{shave_off}x0"
110
- else
111
- shave_off = ((h - w) / 2).round
112
- convert.shave "0x#{shave_off}"
116
+ return
113
117
  end
118
+
119
+ shave_off = ((h - w) / 2).round
120
+ convert.shave "0x#{shave_off}"
114
121
  end
115
122
 
116
123
  def auto_orient!(img, covert)
@@ -119,6 +126,14 @@ module Balloon
119
126
  end
120
127
  end
121
128
 
129
+ def get_image_data(img)
130
+ return {
131
+ width: img.width,
132
+ height: img.height,
133
+ size: img.size
134
+ }
135
+ end
136
+
122
137
  # parseing the size string
123
138
  #
124
139
  # @return [Hash] the options for string
data/lib/balloon/up.rb CHANGED
@@ -51,6 +51,7 @@ module Balloon
51
51
  key :content_type, String
52
52
  key :file_size, Integer
53
53
  key :storage, String
54
+ key :metadata
54
55
  key :created_at
55
56
  elsif defined?(Mongoid)
56
57
  field :file_name, type: String
@@ -59,6 +60,7 @@ module Balloon
59
60
  field :content_type, type: String
60
61
  field :file_size, type: String
61
62
  field :storage, type: String
63
+ field :metadata
62
64
  field :created_at
63
65
  end
64
66
 
@@ -74,6 +76,9 @@ module Balloon
74
76
  self.storage = store_storage.to_s
75
77
  self.width = meta[:width]
76
78
  self.height = meta[:height]
79
+ if self.respond_to?(:metadata)
80
+ self.metadata = meta[:data]
81
+ end
77
82
  end
78
83
 
79
84
  def url(size_name = nil)
@@ -24,13 +24,13 @@ module Balloon
24
24
  file_mime_type = uploader_file_ext.mime_type
25
25
 
26
26
  if self.respond_to?(:uploader_mimetype_white)
27
- if !uploader_mimetype_white.include?(file_mime_type)
27
+ if !uploader_mimetype_white.include?(file_mime_type)
28
28
  raise Balloon::DownloadError, I18n.translate(:"errors.messages.down_mime_error")
29
29
  end
30
30
  end
31
-
31
+
32
32
  if self.respond_to?(:uploader_mimetype_black)
33
- if !uploader_mimetype_black.include?(file_mime_type)
33
+ if !uploader_mimetype_black.include?(file_mime_type)
34
34
  raise Balloon::DownloadError, I18n.translate(:"errors.messages.down_mime_error")
35
35
  end
36
36
  end
@@ -43,7 +43,8 @@ module Balloon
43
43
  height: @cache_meta[:height],
44
44
  size: @cache_meta[:size],
45
45
  mime_type: @cache_meta[:mime_type],
46
- extension: @cache_meta[:extension]
46
+ extension: @cache_meta[:extension],
47
+ data: @cache_meta[:data]
47
48
  }
48
49
  end
49
50
 
@@ -70,7 +71,7 @@ module Balloon
70
71
 
71
72
  def uploader_name_format(info)
72
73
  define_method "uploader_name_format" do
73
- name = info[:name].nil? ? info[:name] : info[:name].call(self)
74
+ name = info[:name].is_a?(Proc) ? info[:name].call(self) : info[:name].to_s
74
75
  { name: name, format: info[:format] }
75
76
  end
76
77
  end
@@ -1,3 +1,3 @@
1
1
  module Balloon
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -2,7 +2,7 @@ module Balloon
2
2
  module Generators
3
3
  class ConfigGenerator < Rails::Generators::Base
4
4
  desc "create the Balloon configuration at config/balloon.yml"
5
-
5
+
6
6
  def self.source_root
7
7
  @source_root ||= File.expand_path("../templates", __FILE__)
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: balloon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yeeli
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-07 00:00:00.000000000 Z
11
+ date: 2022-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport