fdimage 0.1.0
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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +34 -0
- data/lib/fdimage.rb +102 -0
- data/lib/fdimage/fdimage_base64.rb +13 -0
- data/lib/fdimage/fdimage_gcloud.rb +5 -0
- data/lib/fdimage/fdimage_path.rb +8 -0
- data/lib/fdimage/version.rb +3 -0
- data/lib/tasks/fdimage_tasks.rake +4 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d5cd376c234c0896133d920c73ffaa351fb7fa1bd3948b994832c8c14dd9e52a
|
4
|
+
data.tar.gz: 92915e0c89c4679ee567af88ac714777655df55e6ae5cdcc5ab1746b6a968979
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 511a85cf43352d629f758f7761517fceaa29aefdcd110dbff3fcfc6a1d2a47f128c9752f5a2f03d324950837272a52b54bfc8856db89478a148f880b5e81be9a
|
7
|
+
data.tar.gz: 9293c404e1732c067be83ef8fa1dfaeb7a69cd7b1f7a804f7cb7891cc43222be41e06964c29c8d4af78db0d35808ecdd177f98e1331ffe44e3d5a6a923683eec
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 mtoribio
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# Fdimage
|
2
|
+
Short description and motivation.
|
3
|
+
|
4
|
+
## Usage
|
5
|
+
How to use my plugin.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'fdimage'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
```bash
|
21
|
+
$ gem install fdimage
|
22
|
+
```
|
23
|
+
|
24
|
+
## Contributing
|
25
|
+
Contribution directions go here.
|
26
|
+
|
27
|
+
## License
|
28
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Fdimage'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
data/lib/fdimage.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
class Fdimage
|
2
|
+
require 'fdimage/fdimage_base64'
|
3
|
+
require 'fdimage/fdimage_gcloud'
|
4
|
+
require 'fdimage/fdimage_path'
|
5
|
+
|
6
|
+
# Solo funciona al subir una nueva imagen y solo desde la plataforma, no desde la app
|
7
|
+
# TODO:
|
8
|
+
# Recortar archivos subidos
|
9
|
+
|
10
|
+
attr_accessor :archivo,
|
11
|
+
:params
|
12
|
+
|
13
|
+
def initialize(data, params: {})
|
14
|
+
self.archivo = Fdarchivo.new(data)
|
15
|
+
self.params = params
|
16
|
+
end
|
17
|
+
|
18
|
+
def fix_orientacion_apple
|
19
|
+
exif = MiniMagick::Image.open(self.archivo.path).exif
|
20
|
+
if exif['Orientation']
|
21
|
+
MiniMagick::Tool::Convert.new do |c|
|
22
|
+
c << self.archivo.path
|
23
|
+
case exif['Orientation']
|
24
|
+
when '6'
|
25
|
+
c.rotate << '90'
|
26
|
+
when '8'
|
27
|
+
c.rotate << '-90'
|
28
|
+
when '3'
|
29
|
+
c.rotate << '180'
|
30
|
+
end
|
31
|
+
c << '-strip'
|
32
|
+
c << self.archivo.path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def get_tmp_file
|
38
|
+
new_path = "#{Rails.root}/public/tmp/"
|
39
|
+
unless Dir.exist?(new_path)
|
40
|
+
FileUtils.mkpath(new_path)
|
41
|
+
end
|
42
|
+
new_path << "#{self.archivo.archivo.original_filename}"
|
43
|
+
FileUtils.mv(self.archivo.path, new_path)
|
44
|
+
self.archivo.path = new_path
|
45
|
+
end
|
46
|
+
|
47
|
+
def convert(parametros: self.params)
|
48
|
+
self.get_tmp_file
|
49
|
+
if parametros
|
50
|
+
MiniMagick::Tool::Convert.new do |c|
|
51
|
+
c << "#{self.archivo.path}"
|
52
|
+
if parametros[:rotate]!=0
|
53
|
+
c << '-rotate' << "#{parametros[:rotate].to_i}"
|
54
|
+
end
|
55
|
+
c << '-crop' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+#{parametros[:x].to_f}+#{parametros[:y].to_f}"
|
56
|
+
if parametros[:x].to_f<0 && parametros[:y].to_f<0
|
57
|
+
c << '-page' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+#{parametros[:x].to_f.abs}+#{parametros[:y].to_f.abs}"
|
58
|
+
elsif parametros[:y].to_f<0
|
59
|
+
c << '-page' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+0+#{parametros[:y].to_f.abs}"
|
60
|
+
elsif parametros[:x].to_f<0
|
61
|
+
c << '-page' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+#{parametros[:x].to_f.abs}+0"
|
62
|
+
else
|
63
|
+
c << '-page' << "#{parametros[:width].to_f}x#{parametros[:height].to_f}+0+0"
|
64
|
+
end
|
65
|
+
c << '-format' << 'jpeg'
|
66
|
+
c << '-background' << 'white'
|
67
|
+
c << '-depth' << '8'
|
68
|
+
c << '-density' << '72'
|
69
|
+
c << '+channel'
|
70
|
+
c << '-flatten'
|
71
|
+
c << '-strip'
|
72
|
+
c << '-gaussian-blur' << '0.05'
|
73
|
+
c << self.archivo.path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.tmp_multi_upload(paths, owner = nil)
|
79
|
+
code = Fdarchivo.gen_upload_code
|
80
|
+
paths.each do |path|
|
81
|
+
a = self.new(path)
|
82
|
+
a.fix_orientacion_apple
|
83
|
+
a.archivo.tmp_upload(owner, code: code)
|
84
|
+
end
|
85
|
+
code
|
86
|
+
end
|
87
|
+
def self.tmp_upload(path, owner = nil)
|
88
|
+
code = Fdarchivo.gen_upload_code
|
89
|
+
a = self.new(path)
|
90
|
+
a.fix_orientacion_apple
|
91
|
+
a.archivo.tmp_upload(owner, code: code)
|
92
|
+
code
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.upload(path, owner = nil)
|
96
|
+
code = Fdarchivo.gen_upload_code
|
97
|
+
a = self.new(path)
|
98
|
+
a.fix_orientacion_apple
|
99
|
+
a.archivo.upload(owner, code: code)
|
100
|
+
code
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module FDimageBase64
|
2
|
+
def initialize(data)
|
3
|
+
if check_base_64(data)
|
4
|
+
data = Base64.decode64(data)
|
5
|
+
@image = MiniMagick::Image.read(data)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
def check_base_64(str)
|
11
|
+
str =~ /^([A-Za-z0-9+\/]{4})*([A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}==)$/
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fdimage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- AdrianFP
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-06-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mini_magick
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fdarchivo
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Description of Fdimage.
|
56
|
+
email:
|
57
|
+
- adrian@fuenteposadilla.es
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.md
|
64
|
+
- Rakefile
|
65
|
+
- lib/fdimage.rb
|
66
|
+
- lib/fdimage/fdimage_base64.rb
|
67
|
+
- lib/fdimage/fdimage_gcloud.rb
|
68
|
+
- lib/fdimage/fdimage_path.rb
|
69
|
+
- lib/fdimage/version.rb
|
70
|
+
- lib/tasks/fdimage_tasks.rake
|
71
|
+
homepage:
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata: {}
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubygems_version: 3.0.8
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Summary of Fdimage.
|
94
|
+
test_files: []
|