waifu2x 0.1.0 → 0.2.1
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 +4 -4
- data/README.md +6 -0
- data/lib/waifu2x.rb +23 -15
- data/lib/waifu2x/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 711f2a3a411fa50f68a4ac8287c0e0d879d8170b
|
4
|
+
data.tar.gz: 5642040d68b9a617c05c0d41e8028c4fe882fe90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d704a1e76c5e09e4aa913a59207517efa70f672e7e2cbd144d1df7d5defcd93637939f88cd34b0717991c5f1db48e91a8838c2a93eec3edb1bbf85f8e38e88a
|
7
|
+
data.tar.gz: 4583ef9d0705d18b6ae2c1eb90c894244caeb87407833f98fd1a03aa7184252b56714356af2e8052dcf805e8f2678b7552eca9f35b08cbc9f98cf7dd94d48c25
|
data/README.md
CHANGED
@@ -30,6 +30,9 @@ bundle install
|
|
30
30
|
# convert image.png with 2x upscaling
|
31
31
|
Waifu2x.convert('image.png', nil, { scale: 2 })
|
32
32
|
|
33
|
+
# convert image.png from remote url
|
34
|
+
Waifu2x.convert('http://example.net/image.png', nil, { scale: 2 })
|
35
|
+
|
33
36
|
# convert image.png to converted.png without noise reduction and with 2x upscaling
|
34
37
|
Waifu2x.convert('image.png', 'converted.png', { noise: 0, scale: 2 })
|
35
38
|
```
|
@@ -40,6 +43,9 @@ Waifu2x.convert('image.png', 'converted.png', { noise: 0, scale: 2 })
|
|
40
43
|
# convert sample.jpg with 2x upscaling
|
41
44
|
waifu2x sample.jpg -s 2
|
42
45
|
|
46
|
+
# convert sample.jpg from remote url
|
47
|
+
waifu2x http://example.net/sample.jpg -s 2
|
48
|
+
|
43
49
|
# convert sample.jpg to output.jpg without noise reduction and with 2x upscaling
|
44
50
|
waifu2x sample.jpg output.jpg -n 0 -s 2
|
45
51
|
```
|
data/lib/waifu2x.rb
CHANGED
@@ -6,38 +6,46 @@ module Waifu2x
|
|
6
6
|
USER_AGENT = "Waifu2x Ruby Gem #{Waifu2x::VERSION}".freeze
|
7
7
|
API_ENDPOINT = 'http://waifu2x.udp.jp/api'.freeze
|
8
8
|
|
9
|
-
#
|
9
|
+
# Converts image from a local file or URL
|
10
10
|
#
|
11
|
-
# @param [String]
|
12
|
-
# @param [String, nil]
|
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
13
|
# @param [Hash] options
|
14
14
|
# @option options [Integer] :noise Noise reduction (0 - none, 1 - low, 2 - high), default: 2
|
15
15
|
# @option options [Integer] :scale Upscaling (0 - none, 1 - 1.6x, 2 - 2x), default: 0
|
16
|
-
# @
|
17
|
-
|
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={})
|
18
19
|
noise = options[:noise] || 2
|
19
20
|
scale = options[:scale] || 0
|
20
21
|
|
21
22
|
validate_options! noise, scale
|
22
23
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
if 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
|
27
32
|
end
|
28
33
|
|
29
34
|
response = Typhoeus.post(API_ENDPOINT,
|
30
35
|
headers: { 'User-Agent' => USER_AGENT },
|
31
|
-
body: { noise: noise
|
36
|
+
body: { noise: noise, scale: scale }.merge(source_params)
|
32
37
|
)
|
33
38
|
|
34
|
-
raise InvalidImage, response.body if response.body
|
39
|
+
raise InvalidImage, response.body if response.body.include?('ERROR')
|
35
40
|
raise Waifu2x::ServerError, "Request to Waifu2x API failed with response code: #{response.code}" if response.code != 200
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
49
|
end
|
42
50
|
|
43
51
|
# @private
|
data/lib/waifu2x/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: waifu2x
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nihad Abbasov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: typhoeus
|
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
122
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.5.0
|
124
124
|
signing_key:
|
125
125
|
specification_version: 4
|
126
126
|
summary: Ruby wrapper and CLI for waifu2x
|