### Home Classes Methods

### In Files

- lib/prawn/images/jpg.rb

### Parent

Object

### Methods

- ::new

### Files

- COPYING
- HACKING
- LICENSE
- README

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Core
- Prawn::Document
- Prawn::Document::Annotations
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::Destinations
- Prawn::Document::GraphicsState
- Prawn::Document::Internals
- Prawn::Document::PageGeometry
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::Images
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::Outline
- Prawn::Stamp
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::LineWrap
- File
- Numeric

No matching classes.

# Prawn::Images::JPG

A convenience class that wraps the logic for extracting the parts of a JPG image that we need to embed them in a PDF

### Constants

JPEG_APP_BLOCKS
JPEG_SOF_BLOCKS

### Attributes

bits[R]
channels[R]
height[R]
scaled_height[RW]
scaled_width[RW]
width[R]

### Public Class Methods

new(data) click to toggle source

Process a new JPG image

`:data` | A binary string of JPEG data

    # File lib/prawn/images/jpg.rb, line 26
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.