carrierwave-picture 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +79 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/carrierwave-picture.gemspec +29 -0
- data/lib/carrierwave-picture.rb +11 -0
- data/lib/carrierwave-picture/picture_converter.rb +6 -0
- data/lib/carrierwave-picture/picture_helper.rb +19 -0
- data/lib/carrierwave-picture/railtie.rb +11 -0
- data/lib/carrierwave-picture/version.rb +5 -0
- metadata +122 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 98e71f0be4ced345296e247099d14591026aa6e1eff3399115d6cc03d261686f
|
4
|
+
data.tar.gz: cc4db588cae4ba8e28fad273739ce396d0282952d7cf738faef1f4606a4cec28
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f91a31e20da2a0c234928b3f37e02c6bc64d0c779bc41450821db24201c5a3ce34e1b8fcf559b45a094a8bc5b59c338341e7ab551720566aae34434970bfdaaa
|
7
|
+
data.tar.gz: 1e37881210c3d454f27e9dff9dd4e6298514ab784be17bb1671e20cd90d59107cf04b9fd1a8654ff82e2a61e9ea1b5fed7e0a5f38bd0ed0b38c55f6ca4a156ba
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Igor Pavlov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Carrierwave::Picture
|
2
|
+
|
3
|
+
Simple gem for converting images to webp and progressive jpeg via imagemagic and add picture_tag to action view.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Check that you have installed imagemagick:
|
8
|
+
|
9
|
+
$ convert -version
|
10
|
+
|
11
|
+
If not, type in your OSX console:
|
12
|
+
|
13
|
+
$ brew install imagemagick
|
14
|
+
|
15
|
+
Or in your Debian, Ubuntu console:
|
16
|
+
|
17
|
+
apt-get -y install imagemagick
|
18
|
+
|
19
|
+
Or in your CentOS, Fedora console:
|
20
|
+
|
21
|
+
yum -y install ImageMagick
|
22
|
+
|
23
|
+
After ImageMagic installed add this line to your application's Gemfile:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
gem 'carrierwave-picture'
|
27
|
+
```
|
28
|
+
|
29
|
+
And then execute:
|
30
|
+
|
31
|
+
$ bundle
|
32
|
+
|
33
|
+
Or install it yourself as:
|
34
|
+
|
35
|
+
$ gem install carrierwave-picture
|
36
|
+
|
37
|
+
## Usage
|
38
|
+
|
39
|
+
Include CarrierWave::Picture into your CarrierWave uploader and call prepare_picture method after carrierwave store:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class ImageUploader < CarrierWave::Uploader::Base
|
43
|
+
include CarrierWave::Picture
|
44
|
+
|
45
|
+
after :store, :prepare_picture
|
46
|
+
end
|
47
|
+
```
|
48
|
+
|
49
|
+
This will automatically create webp and jpg versions of the image. Now you can call picture_tag in your views:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
<%= picture_tag image_path, options_hash %>
|
53
|
+
```
|
54
|
+
|
55
|
+
Example:
|
56
|
+
```ruby
|
57
|
+
<%= picture_tag 'image.png', class: 'card' %>
|
58
|
+
```
|
59
|
+
|
60
|
+
It is return html code like:
|
61
|
+
```html
|
62
|
+
<picture class="card">
|
63
|
+
<source srcset="image.png.webp" type="image/webp" style="height: inherit; width: inherit">
|
64
|
+
<source srcset="image.png.jpg" type="image/jpeg" style="height: inherit; width: inherit">
|
65
|
+
<img style="height: inherit; width: inherit" src="image.png" alt="">
|
66
|
+
</picture>
|
67
|
+
```
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
1. Fork it
|
72
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
73
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
74
|
+
4. Push to the branch (git push origin my-new-feature)
|
75
|
+
5. Create new Pull Request
|
76
|
+
|
77
|
+
## License
|
78
|
+
|
79
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "carrierwave/picture"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "carrierwave-picture/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "carrierwave-picture"
|
8
|
+
spec.version = Carrierwave::Picture::VERSION
|
9
|
+
spec.authors = ["Igor Pavlov"]
|
10
|
+
spec.email = ["igor@snega.pro"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple gem for use new web image formats with Carriewave.}
|
13
|
+
spec.description = %q{Converting images to webp and progressive jpeg via imagemagic and add picture_tag to action view.}
|
14
|
+
spec.homepage = "https://github.com/PavlovIgor/carrierwave-picture"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "carrierwave", [">= 0.8", "< 2.0"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "carrierwave-picture/version"
|
2
|
+
require "carrierwave-picture/picture_converter"
|
3
|
+
require "carrierwave-picture/picture_helper"
|
4
|
+
|
5
|
+
module CarrierWave::Picture
|
6
|
+
require 'carrierwave-picture/railtie' if defined?(Rails)
|
7
|
+
|
8
|
+
def prepare_picture(options = {})
|
9
|
+
PictureConverter.convert(current_path)
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
module PictureConverter
|
2
|
+
def self.convert(current_path)
|
3
|
+
system "convert -interlace Plane -quality 80 #{current_path} #{current_path}.webp" unless File.extname(current_path) == "webp"
|
4
|
+
system "convert -interlace Plane -quality 80 #{current_path} #{current_path}.jpg" unless File.extname(current_path) == "jpg"
|
5
|
+
end
|
6
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PictureHelper
|
2
|
+
def picture_tag(path, options = {})
|
3
|
+
|
4
|
+
content_tag(:picture, options) do
|
5
|
+
concat content_tag :source,
|
6
|
+
nil,
|
7
|
+
srcset: "#{path}.webp",
|
8
|
+
type: "image/webp",
|
9
|
+
style: "height: inherit; width: inherit" if File.exist?(Rails.root.join("public/#{path}.webp"))
|
10
|
+
concat content_tag :source,
|
11
|
+
nil,
|
12
|
+
srcset: "#{path}.jpg",
|
13
|
+
type: "image/jpeg",
|
14
|
+
style: "height: inherit; width: inherit" if File.exist?(Rails.root.join("public/#{path}.jpg"))
|
15
|
+
concat image_tag path, style: "height: inherit; width: inherit"
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-picture
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Igor Pavlov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carrierwave
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.8'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: bundler
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.16'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.16'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rake
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '10.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rspec
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
description: Converting images to webp and progressive jpeg via imagemagic and add
|
76
|
+
picture_tag to action view.
|
77
|
+
email:
|
78
|
+
- igor@snega.pro
|
79
|
+
executables: []
|
80
|
+
extensions: []
|
81
|
+
extra_rdoc_files: []
|
82
|
+
files:
|
83
|
+
- ".gitignore"
|
84
|
+
- ".rspec"
|
85
|
+
- ".travis.yml"
|
86
|
+
- Gemfile
|
87
|
+
- LICENSE.txt
|
88
|
+
- README.md
|
89
|
+
- Rakefile
|
90
|
+
- bin/console
|
91
|
+
- bin/setup
|
92
|
+
- carrierwave-picture.gemspec
|
93
|
+
- lib/carrierwave-picture.rb
|
94
|
+
- lib/carrierwave-picture/picture_converter.rb
|
95
|
+
- lib/carrierwave-picture/picture_helper.rb
|
96
|
+
- lib/carrierwave-picture/railtie.rb
|
97
|
+
- lib/carrierwave-picture/version.rb
|
98
|
+
homepage: https://github.com/PavlovIgor/carrierwave-picture
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.7.2
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: A simple gem for use new web image formats with Carriewave.
|
122
|
+
test_files: []
|