Class: Prawn::Images::JPG
- Inherits:
-
Object
- Object
- Prawn::Images::JPG
- Defined in:
- lib/prawn/images/jpg.rb
Overview
A convenience class that wraps the logic for extracting the parts of a JPG image that we need to embed them in a PDF
Constant Summary collapse
- JPEG_SOF_BLOCKS =
%W(\xc0 \xc1 \xc2 \xc3 \xc5 \xc6 \xc7 \xc9 \xca \xcb \xcd \xce \xcf)
- JPEG_APP_BLOCKS =
%W(\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef)
Instance Attribute Summary collapse
-
#bits ⇒ Object
readonly
Returns the value of attribute bits.
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#scaled_height ⇒ Object
Returns the value of attribute scaled_height.
-
#scaled_width ⇒ Object
Returns the value of attribute scaled_width.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
-
#initialize(data) ⇒ JPG
constructor
Process a new JPG image.
Constructor Details
#initialize(data) ⇒ JPG
Process a new JPG image
:data
-
A binary string of JPEG data
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/prawn/images/jpg.rb', line 27 def initialize(data) data = StringIO.new(data.dup) c_marker = "\xff" # Section marker. data.read(2) # Skip the first two bytes of JPEG identifier. loop do marker, code, length = data.read(4).unpack('aan') raise "JPEG marker not found!" if marker != c_marker if JPEG_SOF_BLOCKS.include?(code) @bits, @height, @width, @channels = data.read(6).unpack("CnnC") break end buffer = data.read(length - 2) end end |
Instance Attribute Details
#bits ⇒ Object (readonly)
Returns the value of attribute bits.
17 18 19 |
# File 'lib/prawn/images/jpg.rb', line 17 def bits @bits end |
#channels ⇒ Object (readonly)
Returns the value of attribute channels.
17 18 19 |
# File 'lib/prawn/images/jpg.rb', line 17 def channels @channels end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
17 18 19 |
# File 'lib/prawn/images/jpg.rb', line 17 def height @height end |
#scaled_height ⇒ Object
Returns the value of attribute scaled_height.
18 19 20 |
# File 'lib/prawn/images/jpg.rb', line 18 def scaled_height @scaled_height end |
#scaled_width ⇒ Object
Returns the value of attribute scaled_width.
18 19 20 |
# File 'lib/prawn/images/jpg.rb', line 18 def scaled_width @scaled_width end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
17 18 19 |
# File 'lib/prawn/images/jpg.rb', line 17 def width @width end |