IMF 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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +18 -0
- data/CHANGES.md +3 -0
- data/Gemfile +4 -0
- data/IMF.gemspec +24 -0
- data/LICENSE.txt +20 -0
- data/README.md +36 -0
- data/Rakefile +4 -0
- data/TODO.md +64 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/IMF.rb +8 -0
- data/lib/IMF/file_formats.rb +9 -0
- data/lib/IMF/file_formats/gif_format.rb +24 -0
- data/lib/IMF/file_formats/jpeg_format.rb +27 -0
- data/lib/IMF/file_formats/png_format.rb +24 -0
- data/lib/IMF/file_formats/webp_format.rb +31 -0
- data/lib/IMF/image.rb +29 -0
- data/lib/IMF/image/format_management.rb +28 -0
- data/lib/IMF/version.rb +3 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ecc29fa3026f2dbd532cebc04189dd97a52d10f6
|
4
|
+
data.tar.gz: 0421f8260d2a3fa544926deaefd0da6cfc9aa0b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57763e8b770ebc9f92fd567590fca60b90dd76433bfbe869f5218c3d0640d7a61731c888cba5f299f41267b08d4c29753022f8bece9de505429da396894178ca
|
7
|
+
data.tar.gz: d8bc00a6a86900e39cb1b89eb0185a39359e6c210bc3fb40a02e9f5691ca9e4481c19beb672fdbf54f3d943b0bad3bd0bdc5202b00ede0b21c75d5d45f9eb4e6
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
---
|
2
|
+
language: ruby
|
3
|
+
rvm:
|
4
|
+
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
- 2.1.7
|
7
|
+
- 2.2.3
|
8
|
+
- ruby-head
|
9
|
+
- jruby
|
10
|
+
- rbx-2
|
11
|
+
before_install:
|
12
|
+
- gem install bundler
|
13
|
+
script: rake spec
|
14
|
+
matrix:
|
15
|
+
allow_failures:
|
16
|
+
- rvm: 1.9.3
|
17
|
+
- rvm: jruby
|
18
|
+
- rvm: rbx-2
|
data/CHANGES.md
ADDED
data/Gemfile
ADDED
data/IMF.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'IMF/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "IMF"
|
8
|
+
spec.version = IMF::VERSION
|
9
|
+
spec.authors = ["Kenta Murata"]
|
10
|
+
spec.email = ["mrkn@mrkn.jp"]
|
11
|
+
|
12
|
+
spec.summary = %q{Image Manipulation Framework}
|
13
|
+
spec.description = %q{IMF is a library that provides image manipulation framework for Ruby scripts.}
|
14
|
+
spec.homepage = "https://github.com/mrkn/IMF"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.4"
|
24
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
Copyright © 2015 Kenta Murata
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the “Software”), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/mrkn/IMF.svg?branch=master)](https://travis-ci.org/mrkn/IMF)
|
2
|
+
|
3
|
+
# IMF
|
4
|
+
|
5
|
+
IMF is a library that provides image manipulation framework for Ruby scripts.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'IMF'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install IMF
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mrkn/IMF.
|
36
|
+
|
data/Rakefile
ADDED
data/TODO.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# File format
|
2
|
+
|
3
|
+
- [x] JPEG detection
|
4
|
+
- [ ] JPEG loading
|
5
|
+
- [ ] JPEG saving
|
6
|
+
- [x] PNG detection
|
7
|
+
- [ ] PNG loading
|
8
|
+
- [ ] PNG saving
|
9
|
+
- [x] GIF detection
|
10
|
+
- [ ] GIF loading
|
11
|
+
- [ ] GIF saving
|
12
|
+
- [x] WEBP detection
|
13
|
+
- [ ] WEBP loading
|
14
|
+
- [ ] WEBP saving
|
15
|
+
- [ ] BMP detection
|
16
|
+
- [ ] BMP loading
|
17
|
+
- [ ] BMP saving
|
18
|
+
- [ ] TIFF detection
|
19
|
+
- [ ] TIFF loading
|
20
|
+
- [ ] TIFF saving
|
21
|
+
|
22
|
+
# Color spaces
|
23
|
+
|
24
|
+
- [ ] Grayscale support
|
25
|
+
- [ ] RGBA support
|
26
|
+
- [ ] CMYK support
|
27
|
+
- [ ] HSV support
|
28
|
+
- [ ] HSL support
|
29
|
+
- [ ] Lab support
|
30
|
+
- [ ] YCbCr support
|
31
|
+
|
32
|
+
# Operation
|
33
|
+
|
34
|
+
- [ ] crop
|
35
|
+
- [ ] paste
|
36
|
+
- [ ] resize
|
37
|
+
- [ ] transpose
|
38
|
+
- [ ] convolution
|
39
|
+
- [ ] fft
|
40
|
+
- [ ] tone curve
|
41
|
+
- [ ] gamma correction
|
42
|
+
- [ ] convert to nmatrix
|
43
|
+
- [ ] blending
|
44
|
+
- [ ] affine transform
|
45
|
+
|
46
|
+
# Resampling methods
|
47
|
+
|
48
|
+
- [ ] nearest neighbor
|
49
|
+
- [ ] bilinear
|
50
|
+
- [ ] bicubic
|
51
|
+
- [ ] waifu2x
|
52
|
+
|
53
|
+
# Drawing
|
54
|
+
|
55
|
+
- [ ] postscript like path drawing
|
56
|
+
- [ ] text drawing
|
57
|
+
|
58
|
+
# Etc.
|
59
|
+
|
60
|
+
- [ ] Animation GIF
|
61
|
+
- [ ] Glitch
|
62
|
+
- [ ] Simple displaying
|
63
|
+
- [ ] IRuby support
|
64
|
+
- [ ] screenshot
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "IMF"
|
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
data/lib/IMF.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module IMF
|
2
|
+
module FileFormats
|
3
|
+
class GifFormat
|
4
|
+
FORMAT = :gif
|
5
|
+
|
6
|
+
EXTENSIONS = %w[
|
7
|
+
.gif
|
8
|
+
].map(&:freeze).freeze
|
9
|
+
|
10
|
+
MIME = 'image/gif'.freeze
|
11
|
+
|
12
|
+
MAGIC = "GIF8"
|
13
|
+
|
14
|
+
def self.detect(io)
|
15
|
+
magic = io.read(MAGIC.size)
|
16
|
+
io.rewind
|
17
|
+
MAGIC === magic
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'IMF/image'
|
22
|
+
IMF::Image.register_format(GifFormat)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module IMF
|
2
|
+
module FileFormats
|
3
|
+
class JpegFormat
|
4
|
+
FORMAT = :jpeg
|
5
|
+
|
6
|
+
EXTENSIONS = %w[
|
7
|
+
.jfif
|
8
|
+
.jpe
|
9
|
+
.jpg
|
10
|
+
.jpeg
|
11
|
+
].map(&:freeze).freeze
|
12
|
+
|
13
|
+
MIME = 'image/jpeg'.freeze
|
14
|
+
|
15
|
+
MAGIC = "\xff\xd8".b.freeze
|
16
|
+
|
17
|
+
def self.detect(io)
|
18
|
+
magic = io.read(MAGIC.size)
|
19
|
+
io.rewind
|
20
|
+
MAGIC === magic
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
require 'IMF/image'
|
25
|
+
IMF::Image.register_format(JpegFormat)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module IMF
|
2
|
+
module FileFormats
|
3
|
+
class PngFormat
|
4
|
+
FORMAT = :png
|
5
|
+
|
6
|
+
EXTENSIONS = %w[
|
7
|
+
.png
|
8
|
+
].map(&:freeze).freeze
|
9
|
+
|
10
|
+
MIME = 'image/png'.freeze
|
11
|
+
|
12
|
+
MAGIC = "\x89PNG\x0d\x0a\x1a\x0a".b.freeze
|
13
|
+
|
14
|
+
def self.detect(io)
|
15
|
+
magic = io.read(MAGIC.size)
|
16
|
+
io.rewind
|
17
|
+
MAGIC === magic
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'IMF/image'
|
22
|
+
IMF::Image.register_format(PngFormat)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module IMF
|
2
|
+
module FileFormats
|
3
|
+
class WebpFormat
|
4
|
+
FORMAT = :webp
|
5
|
+
|
6
|
+
EXTENSIONS = %w[
|
7
|
+
.webp
|
8
|
+
].map(&:freeze).freeze
|
9
|
+
|
10
|
+
MIME = 'image/png'.freeze
|
11
|
+
|
12
|
+
PREFIX_SIZE = 16
|
13
|
+
MAGICS = {
|
14
|
+
0...4 => "RIFF".b.freeze,
|
15
|
+
8...12 => "WEBP".b.freeze,
|
16
|
+
12...16 => /\AVP8[ XL]\z/,
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
def self.detect(io)
|
20
|
+
prefix = io.read(PREFIX_SIZE)
|
21
|
+
io.rewind
|
22
|
+
MAGICS.all? do |range, magic|
|
23
|
+
magic === prefix[range]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'IMF/image'
|
29
|
+
IMF::Image.register_format(WebpFormat)
|
30
|
+
end
|
31
|
+
end
|
data/lib/IMF/image.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'pathname'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
module IMF
|
6
|
+
class Image
|
7
|
+
require 'IMF/image/format_management'
|
8
|
+
extend FormatManagement
|
9
|
+
|
10
|
+
def self.detect_format(file)
|
11
|
+
case file
|
12
|
+
when String, Pathname, URI
|
13
|
+
io = Kernel.open(file, 'rb')
|
14
|
+
when -> (obj) { obj.respond_to?(:read) }
|
15
|
+
io = file
|
16
|
+
else
|
17
|
+
raise ArgumentError, "The argument must be a filename or a reeadable IO"
|
18
|
+
end
|
19
|
+
each_registered_format do |format_name, format_plugin|
|
20
|
+
if format_plugin.detect(io)
|
21
|
+
return format_name
|
22
|
+
end
|
23
|
+
end
|
24
|
+
nil
|
25
|
+
ensure
|
26
|
+
io.close if io && io != file
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module IMF
|
2
|
+
class Image
|
3
|
+
module FormatManagement
|
4
|
+
def register_format(format_plugin)
|
5
|
+
check_requirements(format_plugin)
|
6
|
+
add_format(format_plugin)
|
7
|
+
end
|
8
|
+
|
9
|
+
def each_registered_format
|
10
|
+
registered_formats.each(&proc)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def check_requirements(format_plugin)
|
16
|
+
format_plugin::FORMAT
|
17
|
+
end
|
18
|
+
|
19
|
+
def registered_formats
|
20
|
+
@registered_formats ||= {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_format(format_plugin)
|
24
|
+
registered_formats[format_plugin::FORMAT] = format_plugin
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/IMF/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: IMF
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kenta Murata
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-22 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.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.4'
|
55
|
+
description: IMF is a library that provides image manipulation framework for Ruby
|
56
|
+
scripts.
|
57
|
+
email:
|
58
|
+
- mrkn@mrkn.jp
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- CHANGES.md
|
67
|
+
- Gemfile
|
68
|
+
- IMF.gemspec
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- TODO.md
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- lib/IMF.rb
|
76
|
+
- lib/IMF/file_formats.rb
|
77
|
+
- lib/IMF/file_formats/gif_format.rb
|
78
|
+
- lib/IMF/file_formats/jpeg_format.rb
|
79
|
+
- lib/IMF/file_formats/png_format.rb
|
80
|
+
- lib/IMF/file_formats/webp_format.rb
|
81
|
+
- lib/IMF/image.rb
|
82
|
+
- lib/IMF/image/format_management.rb
|
83
|
+
- lib/IMF/version.rb
|
84
|
+
homepage: https://github.com/mrkn/IMF
|
85
|
+
licenses: []
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.5.0
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Image Manipulation Framework
|
107
|
+
test_files: []
|