dmmyix 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 +30 -0
- data/Rakefile +24 -0
- data/app/controllers/dmmyix/application_controller.rb +7 -0
- data/app/controllers/dmmyix/images_controller.rb +11 -0
- data/config/routes.rb +5 -0
- data/lib/dmmyix/engine.rb +7 -0
- data/lib/dmmyix/image.rb +69 -0
- data/lib/dmmyix/version.rb +5 -0
- data/lib/dmmyix.rb +7 -0
- data/lib/tasks/dmmyix_tasks.rake +4 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 49c6d041b8440ea5da8aec4360947bcfb6af77c1
|
4
|
+
data.tar.gz: 4f9fba644917ea148cb881e49654209565725243
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 60e9ea306cad76824cee50f3e652f094aa602f0e8ececd1f323f994945724e050749c6d038c86f72eaee5d2dceca6aeffa669c635e40f55cf01e8bf7c9a3a12a
|
7
|
+
data.tar.gz: d6c09ad779d7fb3ddf92a99f377d61d31c1c6f4a493bd4a5b60cd1f53446d38630ca9d90eccbff48ca0b1fd22ecf88b90287b2123402dd3bb13c9628c68d07d5
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2016 Koji Shimba
|
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,30 @@
|
|
1
|
+
# Dmmyix
|
2
|
+
|
3
|
+
A dummy of [Imgix](https://www.imgix.com/) for Rails applications.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add this routing to your `routes.rb`:
|
8
|
+
|
9
|
+
```rb
|
10
|
+
Rails.application.routes.draw do
|
11
|
+
mount Dmmyix::Engine, at: "/dmmyix" if Rails.env.development?
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```rb
|
20
|
+
gem "dmmyix"
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
```bash
|
26
|
+
$ bundle
|
27
|
+
```
|
28
|
+
|
29
|
+
## License
|
30
|
+
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,24 @@
|
|
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 = 'Dmmyix'
|
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
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
require 'bundler/gem_tasks'
|
24
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dmmyix
|
4
|
+
class ImagesController < Dmmyix::ApplicationController
|
5
|
+
def show
|
6
|
+
image = Dmmyix::Image.new(params)
|
7
|
+
image = image.convert
|
8
|
+
send_file(image.path, type: image.mime_type, disposition: "inline")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
data/config/routes.rb
ADDED
data/lib/dmmyix/image.rb
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dmmyix
|
4
|
+
class Image
|
5
|
+
def initialize(params)
|
6
|
+
@params = params
|
7
|
+
@image = MiniMagick::Image.open(image_path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def convert
|
11
|
+
@image.combine_options do |b|
|
12
|
+
b.gravity(image_gravity)
|
13
|
+
|
14
|
+
if @params[:fit] == "crop"
|
15
|
+
resize_params = if resized_image_height < image_height
|
16
|
+
"x#{image_height}"
|
17
|
+
else
|
18
|
+
"#{image_width}x"
|
19
|
+
end
|
20
|
+
b.resize(resize_params)
|
21
|
+
b.extent("#{image_width}x#{image_height}")
|
22
|
+
else
|
23
|
+
b.resize("#{image_width}x#{image_height}")
|
24
|
+
end
|
25
|
+
|
26
|
+
b.blur("0x#{image_blur}")
|
27
|
+
b.strip
|
28
|
+
end
|
29
|
+
@image.format("jpg")
|
30
|
+
@image.write("/tmp/#{@image.signature}.jpg")
|
31
|
+
@image
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def image_path
|
37
|
+
path = "public/#{@params[:path]}"
|
38
|
+
return path if @params[:format].blank?
|
39
|
+
"#{path}.#{@params[:format]}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def image_width
|
43
|
+
(@params[:w].presence || @image.width).to_i
|
44
|
+
end
|
45
|
+
|
46
|
+
def image_height
|
47
|
+
(@params[:h].presence || @image.height).to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def resized_image_height
|
51
|
+
(@image.height * image_width) / @image.width
|
52
|
+
end
|
53
|
+
|
54
|
+
def image_gravity
|
55
|
+
case @params[:crop]
|
56
|
+
when "top" then "North"
|
57
|
+
when "bottom" then "South"
|
58
|
+
when "left" then "West"
|
59
|
+
when "right" then "East"
|
60
|
+
else
|
61
|
+
"Center"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def image_blur
|
66
|
+
(@params[:blur].presence || 0).to_i / 10
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/dmmyix.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dmmyix
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Koji Shimba
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-12 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: 5.0.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 5.0.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 5.0.0
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 5.0.0.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mini_magick
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 4.5.0
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 4.5.0
|
47
|
+
description: A dummy of Imgix for Rails applications.
|
48
|
+
email:
|
49
|
+
- me@shimba.co
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- MIT-LICENSE
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- app/controllers/dmmyix/application_controller.rb
|
58
|
+
- app/controllers/dmmyix/images_controller.rb
|
59
|
+
- config/routes.rb
|
60
|
+
- lib/dmmyix.rb
|
61
|
+
- lib/dmmyix/engine.rb
|
62
|
+
- lib/dmmyix/image.rb
|
63
|
+
- lib/dmmyix/version.rb
|
64
|
+
- lib/tasks/dmmyix_tasks.rake
|
65
|
+
homepage: https://github.com/annict/dmmyix
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.5.1
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: A dummy of Imgix for Rails applications.
|
89
|
+
test_files: []
|