Module: Rixmap::ImageIO
- Defined in:
- lib/rixmap/imageio.rb
Constant Summary collapse
- MAGIC_BYTES_SIZE =
ファイルフォーマット識別用に読み取るマジックデータサイズ
16
Class Method Summary collapse
Class Method Details
.open(path, options = {}) ⇒ Rixmap::Image .open(path, format, options = {}) ⇒ Rixmap::Image
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rixmap/imageio.rb', line 24 def self.open(path, *args) # 引数をチェック format = nil = {} unless args[0].nil? if args[0].kind_of?(Hash) = args[0] else format = args[0] if !args[1].nil? && args[1].kind_of?(Hash) = args[1] end end end # ImageIOを探索 info = nil if format.nil? info = self.find(:path => path) if info.nil? # パスから判定できない場合はマジックデータから検索 magic = IO.binread(path, MAGIC_BYTES_SIZE) info = self.find(:magic => magic) end # 見つからない場合は例外を出す if info.nil? raise NotImplementedError.new("ImageIO Implementation for File is not found: #{path}") end else info = self.get(format) if info.nil? raise NotImplementedError.new("ImageIO Implementation for #{format} is not found.") end end # 読み込みを実施 iio = info.imageio.new() return iio.open(path) end |
.save(path, image, options = {}) ⇒ void .save(path, image, format, options = {}) ⇒ void
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/rixmap/imageio.rb', line 81 def self.save(path, image, *args) # パラメータ処理 format = nil = {} unless args[0].nil? if args[0].kind_of?(Hash) = args[0] else format = args[0] if !args[1].nil? && args[1].kind_of?(Hash) = args[1] end end end # ImgaeIO探索 info = nil if format.nil? info = self.find(:path => path) if info.nil? raise NotImplementedError.new("ImageIO Implementation for File is not found: #{path}") end else info = self.get(format) if info.nil? raise NotImplementedError.new("ImageIO Implementation for #{format} is not found.") end end # 書き込み可能かどうかをチェックしつつ書き込み. iio = info.imageio.new() if iio.writable?(image) return iio.save(path, image) else raise NotImplementedError.new("#{iio.class} is not designed for image #{image.inspect}") end end |