Class: ODDB::Text::Picture
Constant Summary collapse
- TWIP =
20
- PCNT =
100
- BDNS =
base density
180
- DMAX =
maximum density
360
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#height_goal ⇒ Object
Returns the value of attribute height_goal.
-
#width ⇒ Object
Returns the value of attribute width.
-
#width_goal ⇒ Object
Returns the value of attribute width_goal.
-
#xscale ⇒ Object
Returns the value of attribute xscale.
-
#yscale ⇒ Object
Returns the value of attribute yscale.
Instance Method Summary collapse
- #_xscale ⇒ Object
- #_yscale ⇒ Object
- #blob ⇒ Object
- #digest ⇒ Object
- #empty? ⇒ Boolean
- #filename ⇒ Object
- #finalize! ⇒ Object
- #formats ⇒ Object
- #image ⇒ Object
-
#initialize ⇒ Picture
constructor
A new instance of Picture.
- #path(fn = filename) ⇒ Object
- #set_format(*ignore) ⇒ Object
- #to_png ⇒ Object
- #to_s ⇒ Object
Methods inherited from String
Constructor Details
#initialize ⇒ Picture
Returns a new instance of Picture.
16 17 18 |
# File 'lib/oddb/text/picture.rb', line 16 def initialize super('') end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
11 12 13 |
# File 'lib/oddb/text/picture.rb', line 11 def height @height end |
#height_goal ⇒ Object
Returns the value of attribute height_goal.
11 12 13 |
# File 'lib/oddb/text/picture.rb', line 11 def height_goal @height_goal end |
#width ⇒ Object
Returns the value of attribute width.
11 12 13 |
# File 'lib/oddb/text/picture.rb', line 11 def width @width end |
#width_goal ⇒ Object
Returns the value of attribute width_goal.
11 12 13 |
# File 'lib/oddb/text/picture.rb', line 11 def width_goal @width_goal end |
#xscale ⇒ Object
Returns the value of attribute xscale.
11 12 13 |
# File 'lib/oddb/text/picture.rb', line 11 def xscale @xscale end |
#yscale ⇒ Object
Returns the value of attribute yscale.
11 12 13 |
# File 'lib/oddb/text/picture.rb', line 11 def yscale @yscale end |
Instance Method Details
#_xscale ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/oddb/text/picture.rb', line 73 def _xscale if @xscale @xscale elsif @width && @width_goal PCNT * @width_goal / @width else PCNT end end |
#_yscale ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/oddb/text/picture.rb', line 82 def _yscale if @yscale @yscale elsif @height && @height_goal PCNT * @height_goal / @height else PCNT end end |
#blob ⇒ Object
19 20 21 |
# File 'lib/oddb/text/picture.rb', line 19 def blob [self].pack('H*') end |
#digest ⇒ Object
22 23 24 |
# File 'lib/oddb/text/picture.rb', line 22 def digest @digest ||= Digest::MD5.hexdigest(self) end |
#empty? ⇒ Boolean
25 26 27 28 29 30 31 32 |
# File 'lib/oddb/text/picture.rb', line 25 def empty? super #|| !image rescue StandardError => err ODDB.logger.error("Text::Picture") { sprintf "%s: %s", err.class, err. } true end |
#filename ⇒ Object
53 54 55 |
# File 'lib/oddb/text/picture.rb', line 53 def filename @filename ||= "%s.png" % digest end |
#finalize! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/oddb/text/picture.rb', line 33 def finalize! wmf = File.join ODDB.config.var, path("%s.wmf" % digest) FileUtils.mkdir_p File.dirname(wmf) File.open(wmf, 'w') { |fh| fh.puts blob } twidth = @width ? @width * _xscale / PCNT : @width_goal theight = @height ? @height * _yscale / PCNT : @height_goal geom = sprintf("%ix%i!", twidth / TWIP, theight / TWIP) path = File.join ODDB.config.var, path("%s.png" % digest) # let imagemagick take care of file-conversion externally out = %x{convert -resize #{geom} #{wmf} #{path}} if $? != 0 raise out end png = File.read path replace png.unpack('H*').first end |
#formats ⇒ Object
56 57 58 |
# File 'lib/oddb/text/picture.rb', line 56 def formats [] end |
#image ⇒ Object
59 60 61 |
# File 'lib/oddb/text/picture.rb', line 59 def image Magick::Image.from_blob(blob).first end |
#path(fn = filename) ⇒ Object
62 63 64 |
# File 'lib/oddb/text/picture.rb', line 62 def path(fn = filename) File.join('/images', fn[0,2], fn) end |
#set_format(*ignore) ⇒ Object
65 66 |
# File 'lib/oddb/text/picture.rb', line 65 def set_format(*ignore) end |
#to_png ⇒ Object
67 68 69 |
# File 'lib/oddb/text/picture.rb', line 67 def to_png blob end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/oddb/text/picture.rb', line 70 def to_s image.inspect end |