magro 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +2 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/lib/magro/io.rb +31 -4
- data/lib/magro/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f911e57e71f9fda41695c940712fd4e471d543dab28e924c9d15459cac02d62e
|
4
|
+
data.tar.gz: 37a3d0c6702219ec3cfee20fe9f319e2aff5945d1ed6d3ba28f842a9eee4a4c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff9033acf66ce81535d2c9aaa0e8843a35004cf9082b84b9aad1169c859074658e1b0bdb30b144d20f594264a7ad94c2be039f22462b1f8976edff9ffb08a01b
|
7
|
+
data.tar.gz: 938646fe6a9d838ec85f429a117f94ca44feb035d7e6b40ac8480549f81007b967a5ba6f79a204949848f5a4e9d17b25c360221744eb39b3d2f7beb6ec791d06
|
data/.github/workflows/build.yml
CHANGED
@@ -7,7 +7,7 @@ jobs:
|
|
7
7
|
runs-on: ubuntu-20.04
|
8
8
|
strategy:
|
9
9
|
matrix:
|
10
|
-
ruby: [ '2.5', '2.6', '2.7' ]
|
10
|
+
ruby: [ '2.5', '2.6', '2.7', '3.0' ]
|
11
11
|
steps:
|
12
12
|
- uses: actions/checkout@v2
|
13
13
|
- name: Install libpng and libjpeg
|
@@ -18,6 +18,6 @@ jobs:
|
|
18
18
|
ruby-version: ${{ matrix.ruby }}
|
19
19
|
- name: Build and test with Rake
|
20
20
|
run: |
|
21
|
-
gem install bundler
|
21
|
+
gem install --no-document bundler
|
22
22
|
bundle install --jobs 4 --retry 3
|
23
23
|
bundle exec rake
|
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/lib/magro/io.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'open-uri'
|
4
|
+
require 'tempfile'
|
5
|
+
|
3
6
|
module Magro
|
4
7
|
# IO module provides functions for input and output of image file.
|
5
8
|
module IO
|
6
9
|
module_function
|
7
10
|
|
8
11
|
# Loads an image from file.
|
9
|
-
# @param filename [String]
|
12
|
+
# @param filename [String] File path or URL of image file to be loaded.
|
10
13
|
# Currently, the following file formats are support:
|
11
14
|
# Portbale Network Graphics (*.png) and JPEG files (*.jpeg, *.jpg, *jpe).
|
12
15
|
# @raise [ArgumentError] This error is raised when filename is not String.
|
@@ -15,8 +18,27 @@ module Magro
|
|
15
18
|
# @return [Numo::UInt8] (shape: [height, width, n_channels]) Loaded image.
|
16
19
|
def imread(filename)
|
17
20
|
raise ArgumentError, 'Expect class of filename to be String.' unless filename.is_a?(String)
|
18
|
-
|
19
|
-
|
21
|
+
|
22
|
+
unless url?(filename)
|
23
|
+
return case filename.downcase
|
24
|
+
when /\.(jpeg|jpg|jpe)$/
|
25
|
+
read_jpg(filename)
|
26
|
+
when /\.png$/
|
27
|
+
read_png(filename)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
uri = URI.parse(filename)
|
32
|
+
ext = File.extname(uri.path).downcase
|
33
|
+
raise IOError, 'Failed to detect file extension from given URL.' unless ext =~ /\.(jpeg|jpg|jpe|png)$/
|
34
|
+
|
35
|
+
uri.open do |file|
|
36
|
+
temp = Tempfile.new(['magro_', ext])
|
37
|
+
temp.binmode
|
38
|
+
temp.write(file.read)
|
39
|
+
temp.rewind
|
40
|
+
imread(temp.path)
|
41
|
+
end
|
20
42
|
end
|
21
43
|
|
22
44
|
# Saves an image to file.
|
@@ -46,6 +68,11 @@ module Magro
|
|
46
68
|
false
|
47
69
|
end
|
48
70
|
|
49
|
-
|
71
|
+
def url?(str)
|
72
|
+
uri = URI.parse(str)
|
73
|
+
uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
|
74
|
+
end
|
75
|
+
|
76
|
+
private_class_method :read_jpg, :read_png, :save_jpg, :save_png, :url?
|
50
77
|
end
|
51
78
|
end
|
data/lib/magro/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yoshoku
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: numo-narray
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
- !ruby/object:Gem::Version
|
84
84
|
version: '0'
|
85
85
|
requirements: []
|
86
|
-
rubygems_version: 3.2.
|
86
|
+
rubygems_version: 3.2.7
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: Magro is a minimal image processing library for Ruby.
|