waifu2x-harrisbaird 0.2.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: 692f70c9063b3914c9a03e5796edd0c5e20c0094
4
+ data.tar.gz: 3056faa7524273366a09574bb50592d7e88e02d9
5
+ SHA512:
6
+ metadata.gz: 17757735e97a50014b676a3dd552bf42539be9e7177f05cf7fce2faf7aa603c245d2761713bba00351d9b0734658fba443c5e59228fa8aeb638df6baea81aa58
7
+ data.tar.gz: a0afdf6aec1b2abc22b43035ae421f58d9a8f5c0ceb2255ed3fc5587bc9e0dfdd44a1f6b3339f65ad1caf9af5f3b9c5dfb55379bbed35c11a3f5a8b25cc9f03b
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in waifu2x.gemspec
4
+ gemspec
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2015, Nihad Abbasov <mail@narkoz.me>
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24
+ POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,55 @@
1
+ # Waifu2x [![Build Status](https://travis-ci.org/NARKOZ/waifu2x.svg)](https://travis-ci.org/NARKOZ/waifu2x)
2
+
3
+ Waifu2x is a ruby wrapper and CLI for
4
+ [waifu2x](https://github.com/nagadomi/waifu2x), which provides Noise Reduction
5
+ and 2x Upscaling for anime style images.
6
+
7
+ ## Installation
8
+
9
+ Install it from rubygems:
10
+
11
+ ```sh
12
+ gem install waifu2x
13
+ ```
14
+
15
+ Or add to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'waifu2x'
19
+ ```
20
+
21
+ and run:
22
+
23
+ ```sh
24
+ bundle install
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ ```ruby
30
+ # convert image.png with 2x upscaling
31
+ Waifu2x.convert('image.png', nil, { scale: 2 })
32
+
33
+ # convert image.png from remote url
34
+ Waifu2x.convert('http://example.net/image.png', nil, { scale: 2 })
35
+
36
+ # convert image.png to converted.png without noise reduction and with 2x upscaling
37
+ Waifu2x.convert('image.png', 'converted.png', { noise: 0, scale: 2 })
38
+ ```
39
+
40
+ ## CLI usage
41
+
42
+ ```sh
43
+ # convert sample.jpg with 2x upscaling
44
+ waifu2x sample.jpg -s 2
45
+
46
+ # convert sample.jpg from remote url
47
+ waifu2x http://example.net/sample.jpg -s 2
48
+
49
+ # convert sample.jpg to output.jpg without noise reduction and with 2x upscaling
50
+ waifu2x sample.jpg output.jpg -n 0 -s 2
51
+ ```
52
+
53
+ ## License
54
+
55
+ Released under the BSD 2-clause license. See LICENSE.txt for details.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'waifu2x'
5
+ require 'pry'
6
+
7
+ Pry.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,59 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'waifu2x'
4
+ require 'optparse'
5
+
6
+ options = {}
7
+
8
+ optparse = OptionParser.new do |opts|
9
+ opts.banner = 'Usage: waifu2x image <filename>'
10
+ opts.separator ''
11
+ opts.separator 'Options:'
12
+
13
+ opts.on_tail('-n', '--noise NOISE', 'Noise reduction (0 - none, 1 - low, 2 - high), default: 2') do |noise|
14
+ options[:noise] = noise.to_i
15
+ end
16
+
17
+ opts.on_tail('-s', '--scale SCALE', 'Upscaling (0 - none, 1 - 1.6x, 2 - 2x), default: 0') do |scale|
18
+ options[:scale] = scale.to_i
19
+ end
20
+
21
+ opts.on_tail('-h', '--help', 'Prints this help message') do
22
+ puts opts
23
+ exit
24
+ end
25
+
26
+ opts.on_tail('-v', '--version', 'Prints version') do
27
+ puts "Waifu2x Version #{Waifu2x::VERSION}"
28
+ exit
29
+ end
30
+ end
31
+
32
+ begin
33
+ optparse.parse!
34
+ rescue OptionParser::ParseError
35
+ puts optparse
36
+ exit 1
37
+ end
38
+
39
+ if ARGV.empty?
40
+ puts optparse
41
+ exit 1
42
+ end
43
+
44
+ image = ARGV[0]
45
+ filename = ARGV[1]
46
+ start_time = Time.now.to_i
47
+
48
+ puts 'Processing...'
49
+
50
+ begin
51
+ waifu2x = Waifu2x.convert(image, filename, options)
52
+ rescue Waifu2x::Error => e
53
+ abort e.message
54
+ end
55
+
56
+ finish_time = Time.now.to_i
57
+ duration = finish_time - start_time
58
+
59
+ puts "Upload took ~#{duration} seconds. Created file #{waifu2x}"
@@ -0,0 +1,70 @@
1
+ require 'waifu2x/version'
2
+ require 'waifu2x/errors'
3
+ require 'typhoeus'
4
+
5
+ module Waifu2x
6
+ USER_AGENT = "Waifu2x Ruby Gem #{Waifu2x::VERSION}".freeze
7
+ API_ENDPOINT = 'http://waifu2x.udp.jp/api'.freeze
8
+
9
+ # Converts image from a local file or URL
10
+ #
11
+ # @param [String] source Source of image to convert (url or filename)
12
+ # @param [String, nil] output_file Name of output image file (with extension)
13
+ # @param [Hash] options
14
+ # @option options [Integer] :noise Noise reduction (0 - none, 1 - low, 2 - high), default: 2
15
+ # @option options [Integer] :scale Upscaling (0 - none, 1 - 1.6x, 2 - 2x), default: 0
16
+ # @option options [Boolean] :raw When true will return a converted image in raw data (binary)
17
+ # @return [String] converted image in raw data (binary) or output filename
18
+ def self.convert(source, output_file=nil, options={})
19
+ noise = options[:noise] || 2
20
+ scale = options[:scale] || 0
21
+
22
+ validate_options! noise, scale
23
+
24
+ if source.is_a?(String) && source.start_with?('http', 'ftp')
25
+ source_params = { url: source }
26
+ else
27
+ begin
28
+ source_params = { file: File.open(source) }
29
+ rescue
30
+ raise InvalidImage, "Can't open image file: #{source}"
31
+ end
32
+ end
33
+
34
+ response = Typhoeus.post(API_ENDPOINT,
35
+ headers: { 'User-Agent' => USER_AGENT },
36
+ body: { noise: noise.to_s, scale: scale.to_s }.merge(source_params)
37
+ )
38
+
39
+ raise InvalidImage, response.body if response.body.include?('ERROR')
40
+ raise Waifu2x::ServerError, "Request to Waifu2x API failed with response code: #{response.code}" if response.code != 200
41
+
42
+ if options[:raw]
43
+ response.body
44
+ else
45
+ output_file = output_filename(source) if output_file.to_s.strip.empty?
46
+ File.write(output_file, response.body)
47
+ output_file
48
+ end
49
+ end
50
+
51
+ # @private
52
+ def self.output_filename(file)
53
+ file_ext = File.extname(file)
54
+ orig_name = File.basename(file, file_ext)
55
+ timestamp = Time.now.to_i
56
+
57
+ "#{orig_name}_#{timestamp}#{file_ext}"
58
+ end
59
+ private_class_method :output_filename
60
+
61
+ # @private
62
+ def self.validate_options!(noise, scale)
63
+ valid_options = [0, 1, 2]
64
+
65
+ unless valid_options.include?(noise) && valid_options.include?(scale)
66
+ raise InvalidArgument, 'Valid noise and scale options: 0, 1 or 2'
67
+ end
68
+ end
69
+ private_class_method :validate_options!
70
+ end
@@ -0,0 +1,13 @@
1
+ module Waifu2x
2
+ # Custom error class for rescuing from all Waifu2x errors.
3
+ class Error < StandardError; end
4
+
5
+ # Raised when invalid image file is passed.
6
+ class InvalidImage < Error; end
7
+
8
+ # Raised when invalid option is passed.
9
+ class InvalidArgument < Error; end
10
+
11
+ # Raised when Waifu2x API server doesn't return the HTTP status code 200 (OK).
12
+ class ServerError < Error; end
13
+ end
@@ -0,0 +1,3 @@
1
+ module Waifu2x
2
+ VERSION = "0.2.2"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'waifu2x/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "waifu2x-harrisbaird"
8
+ spec.version = Waifu2x::VERSION
9
+ spec.authors = ["Nihad Abbasov"]
10
+ spec.email = ["mail@narkoz.me"]
11
+
12
+ spec.summary = %q{Ruby wrapper and CLI for waifu2x}
13
+ spec.description = %q{Noise Reduction and 2x Upscaling for anime style images}
14
+ spec.homepage = "https://github.com/NARKOZ/waifu2x"
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_runtime_dependency 'typhoeus'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "pry", "~> 0.10"
26
+ spec.add_development_dependency "minitest"
27
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: waifu2x-harrisbaird
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.2
5
+ platform: ruby
6
+ authors:
7
+ - Nihad Abbasov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: typhoeus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.10'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.10'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Noise Reduction and 2x Upscaling for anime style images
84
+ email:
85
+ - mail@narkoz.me
86
+ executables:
87
+ - waifu2x
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - exe/waifu2x
100
+ - lib/waifu2x.rb
101
+ - lib/waifu2x/errors.rb
102
+ - lib/waifu2x/version.rb
103
+ - waifu2x.gemspec
104
+ homepage: https://github.com/NARKOZ/waifu2x
105
+ licenses: []
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.6.3
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Ruby wrapper and CLI for waifu2x
127
+ test_files: []