magick_pipe 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7b011b30bea993e2c44f4cc87dfa037715cf8ee
4
+ data.tar.gz: 5f7dade42dfdffaf995be729f2349c49a6e87b71
5
+ SHA512:
6
+ metadata.gz: d95c03d160120f9c438b3a74f6353c01dc7d55c27da46c00def9dfc6b48af38f17b920973a183fb215f467f5c17e783891fa100338dc1109edbaff0b052fdd21
7
+ data.tar.gz: b19686863d7fbc54d0e514c11fa6c2cfb0d591855661cf26479ded1caca4c30d5402195ce0bbc050a94f7d2330800a9e70dab6e4f6bc0b70839ef9def3ee8ab2
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem 'rmagick', :require => 'RMagick'
10
+ gem "rspec", "~> 2.14.0"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "bundler", "~> 1.0"
13
+ gem "jeweler", "~> 2.0.1"
14
+ gem "simplecov", ">= 0"
15
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,75 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
6
+ descendants_tracker (0.0.4)
7
+ thread_safe (~> 0.3, >= 0.3.1)
8
+ diff-lcs (1.2.5)
9
+ docile (1.1.5)
10
+ faraday (0.9.0)
11
+ multipart-post (>= 1.2, < 3)
12
+ git (1.2.8)
13
+ github_api (0.12.2)
14
+ addressable (~> 2.3)
15
+ descendants_tracker (~> 0.0.4)
16
+ faraday (~> 0.8, < 0.10)
17
+ hashie (>= 3.3)
18
+ multi_json (>= 1.7.5, < 2.0)
19
+ nokogiri (~> 1.6.3)
20
+ oauth2
21
+ hashie (3.3.2)
22
+ highline (1.6.21)
23
+ jeweler (2.0.1)
24
+ builder
25
+ bundler (>= 1.0)
26
+ git (>= 1.2.5)
27
+ github_api
28
+ highline (>= 1.6.15)
29
+ nokogiri (>= 1.5.10)
30
+ rake
31
+ rdoc
32
+ json (1.8.1)
33
+ jwt (1.2.0)
34
+ mini_portile (0.6.1)
35
+ multi_json (1.10.1)
36
+ multi_xml (0.5.5)
37
+ multipart-post (2.0.0)
38
+ nokogiri (1.6.5)
39
+ mini_portile (~> 0.6.0)
40
+ oauth2 (1.0.0)
41
+ faraday (>= 0.8, < 0.10)
42
+ jwt (~> 1.0)
43
+ multi_json (~> 1.3)
44
+ multi_xml (~> 0.5)
45
+ rack (~> 1.2)
46
+ rack (1.6.0)
47
+ rake (10.4.2)
48
+ rdoc (3.12.2)
49
+ json (~> 1.4)
50
+ rmagick (2.13.4)
51
+ rspec (2.14.1)
52
+ rspec-core (~> 2.14.0)
53
+ rspec-expectations (~> 2.14.0)
54
+ rspec-mocks (~> 2.14.0)
55
+ rspec-core (2.14.8)
56
+ rspec-expectations (2.14.5)
57
+ diff-lcs (>= 1.1.3, < 2.0)
58
+ rspec-mocks (2.14.6)
59
+ simplecov (0.9.1)
60
+ docile (~> 1.1.0)
61
+ multi_json (~> 1.0)
62
+ simplecov-html (~> 0.8.0)
63
+ simplecov-html (0.8.0)
64
+ thread_safe (0.3.4)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ bundler (~> 1.0)
71
+ jeweler (~> 2.0.1)
72
+ rdoc (~> 3.12)
73
+ rmagick
74
+ rspec (~> 2.14.0)
75
+ simplecov
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Julik Tarkhanov
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,58 @@
1
+ # magick_pipe
2
+
3
+ **WARNING: this is a proof-of-concept/experimental library. Expect things to break.**
4
+
5
+ Serialize RMagick operations into a processing pipeline that can be executed out-of-process.
6
+
7
+ To set up a processing pipe:
8
+
9
+ script = MagickPipe.new("/Users/julik/VFX_Projectery/MattePaintings/IMG_9500.psd", frame: 0)
10
+ script.auto_orient
11
+ script.strip!
12
+ script.geometry! '512x512'
13
+ script.sharpen 0.0, 0.85
14
+ script.write("/Users/julik/VFX_Projectery/MattePaintings/IMG_9500_tiny.png")
15
+
16
+ No images are allocated at this point. Only when you call
17
+
18
+ script.execute!
19
+
20
+ will the actual reading of the image happen. All the images allocated at the various stages
21
+ of the processing will be deallocated using `Magick::Image#destroy!` at the end of the method.
22
+
23
+ ## Why is this actually useful?
24
+
25
+ Well, you could do this (using [exceptional_fork](https://github.com/julik/exceptional_fork)):
26
+
27
+ ExceptionalFork.fork_and_wait { script.execute! }
28
+
29
+ This will put all the image allocations _outside_ of your main Ruby process. This will ensure
30
+ that the fabulous RMagick memory leaks or bad deallocations will die together with the process
31
+ that has been spun up.
32
+
33
+ ## Calling convention
34
+
35
+ Every method that is available on a `Magick::Image` object is available in the `MagickPipe`
36
+ object. Blocks will be preserved where possible. Since `change_geometry` with the default block is
37
+ used so often it is made available under
38
+
39
+ ## Future problems
40
+
41
+ The idea is to be able to actually _serialize_ the whole processing pipe so that it can be
42
+ passed via JSON or a query string.
43
+
44
+ ## Contributing to image_pipeline
45
+
46
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
47
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
48
+ * Fork the project.
49
+ * Start a feature/bugfix branch.
50
+ * Commit and push until you are happy with your contribution.
51
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
52
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
53
+
54
+ ## Copyright
55
+
56
+ Copyright (c) 2014 Julik Tarkhanov. See LICENSE.txt for
57
+ further details.
58
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ require_relative 'lib/version'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
18
+ gem.version = MagickPipe::VERSION
19
+ gem.name = "magick_pipe"
20
+ gem.homepage = "http://github.com/julik/magick_pipe"
21
+ gem.license = "MIT"
22
+ gem.summary = %Q{ Serialize RMagick processing steps }
23
+ gem.description = %Q{ and run them in a forked subprocess, later }
24
+ gem.email = "me@julik.nl"
25
+ gem.authors = ["Julik Tarkhanov"]
26
+ # Remove the huge PSD
27
+ gem.files.exclude "spec/*.psd"
28
+ # dependencies defined in Gemfile
29
+ end
30
+ Jeweler::RubygemsDotOrgTasks.new
31
+
32
+ require 'rspec/core'
33
+ require 'rspec/core/rake_task'
34
+ RSpec::Core::RakeTask.new(:spec) do |spec|
35
+ spec.pattern = FileList['spec/**/*_spec.rb']
36
+ end
37
+
38
+ desc "Code coverage detail"
39
+ task :simplecov do
40
+ ENV['COVERAGE'] = "true"
41
+ Rake::Task['spec'].execute
42
+ end
43
+
44
+ task :default => :spec
45
+
46
+ require 'rdoc/task'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "magick_pipe #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
@@ -0,0 +1,57 @@
1
+ require 'RMagick'
2
+ require_relative 'version'
3
+ class MagickPipe
4
+ NOOP_PROC = Proc.new {} # To prevent allocating new Procs every time we have a method with no Proc
5
+
6
+ # Initialize a processing script with a path to the source file and the frame to use.
7
+ # To reliably "squash" Photoshop documents that have been saved with "Maximize Compatibiliy"
8
+ # enabled, set the frame to 0 (this is also the default). This will preserve the transparency
9
+ # throughout the whole script.
10
+ def initialize(source_path, frame: 0)
11
+ @source_path = source_path
12
+ @frame = frame.to_i
13
+ @steps = []
14
+ end
15
+
16
+ # Shorcut for change_geometry() with a block argument
17
+ def geometry!(geometry_argument)
18
+ change_geometry(geometry_argument) do | rows, cols, img |
19
+ img.resize(rows, cols)
20
+ end
21
+ end
22
+
23
+ # Perform all the recorded steps in sequence, and
24
+ # deallocate all of the Magick::Image objects at the end.
25
+ def execute!
26
+ allocated_images = []
27
+ allocated_images << Magick::Image.read(@source_path)[0]
28
+ @steps.each do | (method_name, tail_args, block_proc) |
29
+ last_image = allocated_images[-1]
30
+
31
+ # Apply the method to the image, and grab the return result
32
+ result = last_image.public_send(method_name, *tail_args, &block_proc)
33
+
34
+ # If that is a new image - put it on the stack
35
+ if result.is_a?(Magick::Image) && result.object_id != last_image.object_id
36
+ allocated_images << result
37
+ end
38
+ end
39
+ ensure
40
+ allocated_images.each {|i| i.destroy! unless i.destroyed? }
41
+ GC.start
42
+ end
43
+
44
+ # Will tell whether a method is available on Magick::Image objects.
45
+ def respond_to_missing?(m, *a)
46
+ Magick::Image.public_instance_methods.include?(m)
47
+ end
48
+
49
+ # Save the method name, it's tail arguments and the optional block
50
+ # for later execution.
51
+ def method_missing(m, *a)
52
+ return super unless respond_to?(m)
53
+ proc_block = block_given? ? Proc.new : NOOP_PROC
54
+ @steps << [m, a, proc_block]
55
+ end
56
+ end
57
+
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ class MagickPipe
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,76 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "MagickPipe" do
4
+ after :each do
5
+ File.unlink('out.png') if File.exist?('out.png')
6
+ end
7
+
8
+ it "responds to Magick::Image methods" do
9
+ subject = MagickPipe.new("/foo.tif")
10
+ expect(subject).to respond_to(:resize)
11
+ expect(subject).to respond_to(:sharpen)
12
+ end
13
+
14
+ it 'resizes and sharpens the PSD file using change_geometry and a block' do
15
+ path = File.dirname(__FILE__) + '/IMG_3241.psd'
16
+
17
+ subject = MagickPipe.new(path)
18
+ subject.change_geometry('64x64') do |r, c, img|
19
+ img.resize(r, c)
20
+ end
21
+ subject.sharpen 0.0, 0.85
22
+ subject.write('out.png')
23
+
24
+ expect(File).not_to be_exist('out.png')
25
+ subject.execute!
26
+ expect(File).to be_exist('out.png')
27
+
28
+ image = Magick::Image.read('out.png')[0]
29
+ expect(image.rows).to be <= 64
30
+ expect(image.columns).to be <= 64
31
+ end
32
+
33
+ it 'runs a GC after execution' do
34
+ path = File.dirname(__FILE__) + '/IMG_3241.psd'
35
+
36
+ subject = MagickPipe.new(path)
37
+ subject.write('out.png')
38
+
39
+ expect(GC).to receive(:start).once
40
+ subject.execute!
41
+ end
42
+
43
+ it 'resizes and sharpens the PSD file using geometry!' do
44
+ path = File.dirname(__FILE__) + '/IMG_3241.psd'
45
+
46
+ subject = MagickPipe.new(path)
47
+ subject.geometry! '64x64'
48
+ subject.sharpen 0.0, 0.85
49
+ subject.write('out.png')
50
+
51
+ expect(File).not_to be_exist('out.png')
52
+ subject.execute!
53
+ expect(File).to be_exist('out.png')
54
+
55
+ image = Magick::Image.read('out.png')[0]
56
+ expect(image.rows).to be <= 64
57
+ expect(image.columns).to be <= 64
58
+ end
59
+
60
+ it 'resizes and sharpens the PSD file using geometry!' do
61
+ path = File.dirname(__FILE__) + '/IMG_3241.psd'
62
+
63
+ subject = MagickPipe.new(path)
64
+ subject.geometry! '64x64'
65
+ subject.sharpen 0.0, 0.85
66
+ subject.write('out.png')
67
+
68
+ expect(File).not_to be_exist('out.png')
69
+ subject.execute!
70
+ expect(File).to be_exist('out.png')
71
+
72
+ image = Magick::Image.read('out.png')[0]
73
+ expect(image.rows).to be <= 64
74
+ expect(image.columns).to be <= 64
75
+ end
76
+ end
@@ -0,0 +1,29 @@
1
+ require 'simplecov'
2
+
3
+ module SimpleCov::Configuration
4
+ def clean_filters
5
+ @filters = []
6
+ end
7
+ end
8
+
9
+ SimpleCov.configure do
10
+ clean_filters
11
+ load_profile 'test_frameworks'
12
+ end
13
+
14
+ ENV["COVERAGE"] && SimpleCov.start do
15
+ add_filter "/.rvm/"
16
+ end
17
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
18
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
19
+
20
+ require 'rspec'
21
+ require 'magick_pipe'
22
+
23
+ # Requires supporting files with custom matchers and macros, etc,
24
+ # in ./support/ and its subdirectories.
25
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
+
27
+ RSpec.configure do |config|
28
+ config.mock_with :rspec
29
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magick_pipe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Julik Tarkhanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rmagick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.14.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.14.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jeweler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.0.1
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.0.1
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: " and run them in a forked subprocess, later "
98
+ email: me@julik.nl
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files:
102
+ - LICENSE.txt
103
+ - README.md
104
+ files:
105
+ - ".document"
106
+ - ".rspec"
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - lib/magick_pipe.rb
113
+ - lib/version.rb
114
+ - spec/magick_pipe_spec.rb
115
+ - spec/spec_helper.rb
116
+ homepage: http://github.com/julik/magick_pipe
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.2.2
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Serialize RMagick processing steps
140
+ test_files: []