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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1017c6415c59c2229b1acc8578eb7ce8bb3eb6e114f8b97089beac2c8d9805ab
4
- data.tar.gz: 55ce42e8bb8fa6c98f586d3d54315e76a3d7a95ffc232c08b6bc7717ff4131a9
3
+ metadata.gz: f911e57e71f9fda41695c940712fd4e471d543dab28e924c9d15459cac02d62e
4
+ data.tar.gz: 37a3d0c6702219ec3cfee20fe9f319e2aff5945d1ed6d3ba28f842a9eee4a4c0
5
5
  SHA512:
6
- metadata.gz: 6a59aeddd2b9f6f8a469fbae9c89313a163370b04c83dfd82a31d6cc770b4b313e7c9dfa88bcc620972dec7f8e899907c874623dc5dcaf6b31d9cd3573f89503
7
- data.tar.gz: 05c4091e37f4cba235f4f05e069ea886be7f9e687a2609cfe6ebbbd60d2ab1d4533eaee3461611aaf9113b6baa7884924be5de9e37868490c38591c9b9c9de6b
6
+ metadata.gz: ff9033acf66ce81535d2c9aaa0e8843a35004cf9082b84b9aad1169c859074658e1b0bdb30b144d20f594264a7ad94c2be039f22462b1f8976edff9ffb08a01b
7
+ data.tar.gz: 938646fe6a9d838ec85f429a117f94ca44feb035d7e6b40ac8480549f81007b967a5ba6f79a204949848f5a4e9d17b25c360221744eb39b3d2f7beb6ec791d06
@@ -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
@@ -1,3 +1,7 @@
1
+ # 0.4.3
2
+ - Fix imread method to read image from URL.
3
+ - Fix some configulation files.
4
+
1
5
  # 0.4.2
2
6
  - Add GC guard to reading and writing image methods.
3
7
 
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem 'bundler', '~> 2.0'
7
- gem 'rake', '~> 12.0'
7
+ gem 'rake', '~> 13.0'
8
8
  gem 'rake-compiler', '~> 1.0'
9
9
  gem 'rspec', '~> 3.0'
10
10
  gem 'simplecov', '~> 0.19'
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] Path to image file to be loaded.
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
- return read_jpg(filename) if filename.downcase =~ /\.(jpeg|jpg|jpe)$/
19
- return read_png(filename) if filename.downcase =~ /\.png$/
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
- private_class_method :read_jpg, :read_png, :save_jpg, :save_png
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
@@ -3,5 +3,5 @@
3
3
  # Magro is an image processing library in Ruby.
4
4
  module Magro
5
5
  # The version of Magro you are using.
6
- VERSION = '0.4.2'
6
+ VERSION = '0.4.3'
7
7
  end
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.2
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-01-23 00:00:00.000000000 Z
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.3
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.