easy_imaging 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 80aefea77861cab38aa0a490897ed90e50e54aa5
4
+ data.tar.gz: 0a60a2dab12acea8b685745023b78f1daec7ac7a
5
+ SHA512:
6
+ metadata.gz: 37bcf052bcd9414a63b4f3831e421059e4bb6742a771816f17b9bb256361962bdafd90acf987f4b03315f4cd80bb3e51af465ecffb8829b2ec6943746dcf1eee
7
+ data.tar.gz: 1cfb3188713606fb9ec7b612c506dd9fa2f18f20e4cece187869b19263fec092b2ac9fc288f6ddda38ffdf7daca4193163a6966b1268decbdb77b59941f3b60c
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in easy_imaging.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Hethe Berg
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.
@@ -0,0 +1,153 @@
1
+ # EasyImaging
2
+
3
+ If you are using the [Paperclip Gem](http://github.com/thoughtbot/paperclip) to store your files but would also like to be able to run manipulate the images in your app, then this is the easiest Gem to get you started.
4
+
5
+ You can use any of the [ImageMagick](http://www.imagemagick.org/script/command-line-options.php) (or even Graphicsmagick) methods.
6
+
7
+ Find a list of image manipulation options here:
8
+ http://www.imagemagick.org/script/command-line-options.php
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'easy_imaging'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install easy_imaging
25
+
26
+
27
+ ## 2 ways to use this Gem
28
+
29
+ Any of the following examples will be for a 'User' model with a Paperclip image attribute name of 'avatar'.
30
+
31
+ Example Model I'll be referencing:
32
+ ```ruby
33
+
34
+ class User < ActiveRecord::Base
35
+ validates :avatar, presence: true
36
+
37
+ # Paperclip details:
38
+ has_attached_file :avatar,
39
+ styles: {
40
+ large: '640x480>',
41
+ thumb: '105x105>',
42
+ listing: '225x225>',
43
+ general: '640x480>'
44
+ },
45
+ :url => "/avatars/:class/:style/:id",
46
+ :path => ":rails_root/public/avatars/:class/:style/:id"
47
+ end
48
+
49
+ ```
50
+
51
+
52
+ #### 1) Use it through the EasyImaging Module.
53
+
54
+
55
+ Any model instance with a Paperclip image attached can now run any of [ImageMagick's methods](http://www.imagemagick.org/script/command-line-options.php).
56
+
57
+ You have the option of applying manipulation to all the instance's style keys, or to all style keys but the original. To apply to all including the original, add a "bang" to the end of the method.
58
+
59
+
60
+ ###### Apply to all styles but the original:
61
+
62
+ EasyImaging.#{method}_image(*args)
63
+
64
+ Example, if you want to rotate the image:
65
+
66
+ ```ruby
67
+
68
+ # Reflect the scanlines in the vertical direction. The image will be mirrored upside-down.
69
+ EasyImaging.flip_image
70
+
71
+ # Reflect the scanlines in the horizontal direction, just like the image in a vertical mirror.
72
+ EasyImaging.flop_image
73
+
74
+ # Rotate the picture 90 degrees counter clockwise.
75
+ EasyImaging.rotate_image(@user.avatar, "-90")
76
+
77
+ # Crop the image at these xy points in the picture.
78
+ EasyImaging.crop_image(@user.avatar, "120x120+10+5")
79
+
80
+ ```
81
+
82
+ ###### Apply to all styles, including original:
83
+
84
+ ```ruby
85
+
86
+ # Reflect the scanlines in the vertical direction. The image will be mirrored upside-down.
87
+ EasyImaging.flip_image!
88
+
89
+ # Reflect the scanlines in the horizontal direction, just like the image in a vertical mirror.
90
+ EasyImaging.flop_image!
91
+
92
+ # Rotate the picture 90 degrees counter clockwise.
93
+ EasyImaging.rotate_image!(@user.avatar, "-90")
94
+
95
+ # Crop the image at these xy points in the picture.
96
+ EasyImaging.crop_image!(@user.avatar, "120x120+10+5")
97
+
98
+ ```
99
+
100
+ #### 2) Perform the image manipulation through instance methods.
101
+
102
+ You can actually apply the methods onto the Paperclip image's model and use the methods as instance methods.
103
+
104
+ You'll need to add 2 things to your model which has the image instance in order to do this. 1) 'include EasyImaging' inside your model. 2) define a paperclip_image method which returns the attribute holding your image.
105
+
106
+ For an example, I'll add the instance methods to a 'User' Model which calls it's Paperclip image attribute 'avatar'
107
+
108
+ ```ruby
109
+
110
+ class User < ActiveRecord::Base
111
+
112
+ include EasyImaging
113
+
114
+ ...
115
+
116
+ def paperclip_image
117
+ avatar
118
+ end
119
+ end
120
+
121
+ ```
122
+
123
+
124
+ Once you are ready to use the instance methods:
125
+ ```ruby
126
+
127
+ # Reflect the scanlines in the vertical direction. The image will be mirrored upside-down.
128
+ @user.avatar_image!
129
+
130
+ # Reflect the scanlines in the horizontal direction, just like the image in a vertical mirror.
131
+ @user.avatar_image!
132
+
133
+ # Rotate the picture 90 degrees counter clockwise.
134
+ @user.avatarte_image!(@user.avatar, "-90")
135
+
136
+ # Crop the image at these xy points in the picture.
137
+ @user.avatar_image!(@user.avatar, "120x120+10+5")
138
+
139
+ ```
140
+
141
+ ## Development
142
+
143
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
144
+
145
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
146
+
147
+ ## Contributing
148
+
149
+ 1. Fork it ( https://github.com/[my-github-username]/easy_imaging/fork )
150
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
151
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
152
+ 4. Push to the branch (`git push origin my-new-feature`)
153
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ module EasyImaging
2
+ class ApplicationController < ActionController::Base
3
+ layout 'application'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module EasyImaging
2
+ class ImagesController < ApplicationController
3
+ def index
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module EasyImaging
2
+ module ApplicationHelper
3
+ include Rails.application.routes.url_helpers
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "easy_imaging"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ EasyImaging::Engine.routes.draw do
2
+ root to: "images#index"
3
+ end
Binary file
Binary file
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'easy_imaging/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "easy_imaging"
8
+ spec.version = EasyImaging::VERSION
9
+ spec.authors = ["Hethe Berg"]
10
+ spec.email = ["growthcode@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby on Rails gem which grants easy to use instance methods for image manipulation to models using the Paperclip gem.}
13
+ spec.description = %q{If you are using the Paperclip Gem to store your files but would also like to be able to run manipulate the images in your app, then this is the easiest Gem to get you started. You can use any of the ImageMagick (or even Graphicsmagick) methods. Find a list of image manipulation options here: http://www.imagemagick.org/script/command-line-options.php.}
14
+ spec.homepage = "http://github.com/growthcode/easy_imaging"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "mini_magick", "~> 4.2"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.8"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,71 @@
1
+ require "easy_imaging/version"
2
+ require "easy_imaging/engine"
3
+ require "mini_magick"
4
+
5
+ module EasyImaging
6
+ AVAILABLE_METHODS = ["adaptive-blur", "adaptive-resize", "adaptive-sharpen", "adjoin", "affine", "alpha", "annotate", "antialias", "append", "authenticate", "auto-gamma", "auto-level", "auto-orient", "background", "bench", "bias", "black-threshold", "blue-primary", "blue-shift", "blur", "border", "bordercolor", "brightness-contrast", "canny", "caption", "cdl", "channel", "charcoal", "chop", "clip", "clamp", "clip-mask", "clip-path", "clut", "complexoperator", "connected-components", "contrast-stretch", "coalesce", "colorize", "color-matrix", "colors", "colorspace", "combine", "comment", "compose", "composite", "compress", "contrast", "convolve", "crop", "cycle", "decipher", "debug", "define", "deconstruct", "delay", "delete", "density", "depth", "despeckle", "direction", "display", "dispose", "distort", "distribute-cache", "dither", "draw", "duplicate", "edge", "emboss", "encipher", "encoding", "endian", "enhance", "equalize", "evaluate", "evaluate-sequence", "extent", "extract", "family", "features", "fft", "fill", "filter", "flatten", "flip", "floodfill", "flop", "font", "format", "frame", "function", "fuzz", "fx", "gamma", "gaussian-blur", "geometry", "gravity", "grayscale", "green-primary", "help", "hough-lines", "identify", "ifft", "implode", "insert", "intensity", "intent", "interlace", "interline-spacing", "interpolate", "interword-spacing", "kerning", "kuwahara", "label", "lat", "layers", "level", "limit", "linear-stretch", "liquid-rescale", "log", "loop", "mask", "mattecolor", "median", "mean-shift", "metric", "mode", "modulate", "monitor", "monochrome", "morph", "morphology", "motion-blur", "negate", "noise", "normalize", "opaque", "ordered-dither", "orient", "page", "paint", "perceptible", "ping", "pointsize", "polaroid", "poly", "posterize", "precision", "preview", "print", "process", "profile", "quality", "quantize", "quiet", "radial-blur", "raise", "random-threshold", "red-primary", "regard-warnings", "region", "remap", "render", "repage", "resample", "resize", "respect-parentheses", "roll", "rotate", "sample", "sampling-factor", "scale", "scene", "seed", "segment", "selective-blur", "separate", "sepia-tone", "set", "shade", "shadow", "sharpen", "shave", "shear", "sigmoidal-contrast", "size", "sketch", "smush", "solarize", "splice", "spread", "statistic", "strip", "stroke", "strokewidth", "stretch", "style", "swap", "swirl", "synchronize", "texture", "threshold", "thumbnail", "tile", "tile-offset", "tint", "transform", "transparent", "transparent-color", "transpose", "transverse", "treedepth", "trim", "type", "undercolor", "unique-colors", "units", "unsharp", "verbose", "version", "view", "vignette", "virtual-pixel", "wave", "weight", "white-point", "white-threshold", "write"]
7
+
8
+ # 'include EasyImaging' will give you this method on your object
9
+ # on the model you include it with.
10
+ # Safe Original: This will process all styles of images except the original.
11
+ AVAILABLE_METHODS.each do |action|
12
+ define_method("#{action}_image") do |*args|
13
+ method_called = action
14
+ paperclip_image.styles.keys.each do |style|
15
+ self.process(style, method_called, *args)
16
+ end
17
+ end
18
+ end
19
+
20
+ # 'include EasyImaging' will give you this method on your object
21
+ # on the model you include it with.
22
+ # Unsafe Original: processes all styles of images.
23
+ AVAILABLE_METHODS.each do |action|
24
+ define_method("#{action}_image!") do |*args|
25
+ method_called = action
26
+ (paperclip_image.styles.keys + [:original]).each do |style|
27
+ self.process(style, method_called, *args)
28
+ end
29
+ end
30
+ end
31
+
32
+ def process(style, method_called, *args)
33
+ path = self.paperclip_image.path(style)
34
+ source = MiniMagick::Image.open(path)
35
+ source = source.send(method_called, *args)
36
+ source.write(path)
37
+ end
38
+
39
+ module ModuleMethods
40
+ # Use this by 'EasyMagick.rotate_image(@user.image, "-90")'
41
+ # Safe Original: This will process all styles of images except the original.
42
+ AVAILABLE_METHODS.each do |action|
43
+ define_method("#{action}_image") do |attr_image, *args|
44
+ method_called = action
45
+ attr_image.styles.keys.each do |style|
46
+ self.process_image(style, method_called, attr_image, *args)
47
+ end
48
+ end
49
+ end
50
+
51
+ # Use this like 'EasyMagick.rotate_image!(@user.image, "-90")'
52
+ # Unsafe Original: processes all styles of images.
53
+ AVAILABLE_METHODS.each do |action|
54
+ define_method("#{action}_image!") do |attr_image, *args|
55
+ styles = attr_image.styles.keys
56
+ method_called = action
57
+ styles.each do |style|
58
+ self.process_image(style, method_called, attr_image, *args)
59
+ end
60
+ end
61
+ end
62
+
63
+ def process_image(style, method_called, attr_image, *args)
64
+ path = attr_image.path(style)
65
+ source = MiniMagick::Image.open(path)
66
+ source = source.send(method_called, *args)
67
+ source.write(path)
68
+ end
69
+ end
70
+ extend ModuleMethods
71
+ end
@@ -0,0 +1,5 @@
1
+ module EasyImaging
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace EasyImaging
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module EasyImaging
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy_imaging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Hethe Berg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_magick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: 'If you are using the Paperclip Gem to store your files but would also
56
+ like to be able to run manipulate the images in your app, then this is the easiest
57
+ Gem to get you started. You can use any of the ImageMagick (or even Graphicsmagick)
58
+ methods. Find a list of image manipulation options here: http://www.imagemagick.org/script/command-line-options.php.'
59
+ email:
60
+ - growthcode@gmail.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - CODE_OF_CONDUCT.md
69
+ - Gemfile
70
+ - LICENSE.txt
71
+ - README.md
72
+ - Rakefile
73
+ - app/controllers/easy_imaging/application_controller.rb
74
+ - app/controllers/easy_imaging/images_controller.rb
75
+ - app/helpers/easy_imaging/application_helper.rb
76
+ - app/views/easy_imaging/images/index.html.erb
77
+ - bin/console
78
+ - bin/setup
79
+ - config/routes.rb
80
+ - easy_imaging-0.1.0.gem
81
+ - easy_imaging-0.1.1.gem
82
+ - easy_imaging.gemspec
83
+ - lib/easy_imaging.rb
84
+ - lib/easy_imaging/engine.rb
85
+ - lib/easy_imaging/version.rb
86
+ homepage: http://github.com/growthcode/easy_imaging
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.4.6
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: Ruby on Rails gem which grants easy to use instance methods for image manipulation
110
+ to models using the Paperclip gem.
111
+ test_files: []