easy_optimise 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/.gitignore +15 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +65 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/easy_optimise.gemspec +29 -0
- data/lib/easy_optimise.rb +29 -0
- data/lib/easy_optimise/version.rb +4 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e2ccdd3504eb83a0a1f00aef4aeb5a1c009ef56
|
4
|
+
data.tar.gz: 6a4d1d5dd11ef341c71599f0034b5810932c0c45
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bceb2698e7abd9b69ed9a160c518eb51f584cac9daa54710fbe19a4f80653bf4891e58ce324ac96bba4a46fe59ec78448d8d93173f76ce81536cba9fe8417b0
|
7
|
+
data.tar.gz: 2dfb2abde53999e3da29ae7db80b706905507bb15ab6084c00cdc0951486077487af50e597f0d1e57ce0255b8ebcdeaf8963a75a445f5b986ef27b5ee868bbef
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# EasyOptimise
|
2
|
+
|
3
|
+
A wrapper built on the <a href="https://github.com/thoughtbot/paperclip" target="_blank">Paperclip</a> attachment gem. EasyOptimise adds the abililty to optimise image sizes for web using sane defaults for compression and quality. The image optimisation is applied using ImageMagick utility functions.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'easy_optimise'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself using Rubygems:
|
18
|
+
|
19
|
+
$ gem install easy_optimise
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
In paperclip you might:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
has_attached_file :avatar,
|
27
|
+
styles: { medium: "300x300>",
|
28
|
+
thumb: "100x100>" },
|
29
|
+
default_url: "/images/:style/missing.png"
|
30
|
+
```
|
31
|
+
|
32
|
+
With EasyOptimise, to optimise the images you serve up, just extend the gem in your model:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
extend EasyOptimise
|
36
|
+
```
|
37
|
+
|
38
|
+
and then slip in one sneaky word in your attachment method:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
has_attached_optimised_file :avatar,
|
42
|
+
styles: { medium: "300x300>",
|
43
|
+
thumb: "100x100>" },
|
44
|
+
default_url: "/images/:style/missing.png"
|
45
|
+
```
|
46
|
+
|
47
|
+
If you want to keep a particular style unoptimised for precise quality (or because you like big slow websites and that's just how you roll), then:
|
48
|
+
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
has_attached_optimised_file :avatar,
|
52
|
+
styles: { medium: "300x300>",
|
53
|
+
thumb: "100x100>" },
|
54
|
+
unoptimised_styles: { banner: "1200x800#" },
|
55
|
+
default_url: "/images/:style/missing.png"
|
56
|
+
```
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
1. Fork it ( https://github.com/PhilipCastiglione/easy_optimise/fork )
|
61
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
62
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
63
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
64
|
+
5. Create a new Pull Request
|
65
|
+
6. Party
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "easy_optimise"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'easy_optimise/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "easy_optimise"
|
8
|
+
spec.version = EasyOptimise::VERSION
|
9
|
+
spec.date = EasyOptimise::DATE
|
10
|
+
|
11
|
+
spec.summary = "A simple paperclip attachment image optimiser."
|
12
|
+
spec.description = "A wrapper of the paperclip attachment handler that uses sane defaults to optimally compress attached images using imagemagick utility functions."
|
13
|
+
|
14
|
+
spec.authors = ["Philip Castiglione"]
|
15
|
+
spec.email = ["philipcastiglione@gmail.com"]
|
16
|
+
spec.homepage = "https://github.com/PhilipCastiglione/easy_optimise"
|
17
|
+
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
spec.bindir = "exe"
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "paperclip", "~> 4.2"
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "easy_optimise/version"
|
2
|
+
|
3
|
+
module EasyOptimise
|
4
|
+
def self.extended(base)
|
5
|
+
base.class_eval do
|
6
|
+
def self.has_attached_optimised_file(name, options={})
|
7
|
+
full_options = Marshal.load(Marshal.dump(options))
|
8
|
+
|
9
|
+
unoptimised_styles = full_options.delete(:unoptimised_styles)
|
10
|
+
full_options[:styles].update(unoptimised_styles) if unoptimised_styles
|
11
|
+
|
12
|
+
has_attached_file(name, full_options)
|
13
|
+
|
14
|
+
optimised_styles = (options[:styles])? options[:styles].keys : []
|
15
|
+
|
16
|
+
optimised_styles.each do |style|
|
17
|
+
self.send("after_#{name}_post_process", Proc.new {
|
18
|
+
attachment = self.send(name)
|
19
|
+
path = attachment.queued_for_write[style].path
|
20
|
+
width = attachment.styles[style].geometry.split('x').first.to_i
|
21
|
+
Paperclip.run('convert', "-filter Triangle -define filter:support=2 -thumbnail #{width} -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB -strip #{path} #{path}")
|
22
|
+
})
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_optimise
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Philip Castiglione
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: paperclip
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.2'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.2'
|
55
|
+
description: A wrapper of the paperclip attachment handler that uses sane defaults
|
56
|
+
to optimally compress attached images using imagemagick utility functions.
|
57
|
+
email:
|
58
|
+
- philipcastiglione@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/console
|
69
|
+
- bin/setup
|
70
|
+
- easy_optimise.gemspec
|
71
|
+
- lib/easy_optimise.rb
|
72
|
+
- lib/easy_optimise/version.rb
|
73
|
+
homepage: https://github.com/PhilipCastiglione/easy_optimise
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 2.4.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A simple paperclip attachment image optimiser.
|
97
|
+
test_files: []
|