def process_jpg(data)
      @type     = 5  # Excel Blip type (MSOBLIPTYPE).

      offset = 2
      data_length = data.bytesize

      # Search through the image data to find the 0xFFC0 marker. The height and
      # width are contained in the data for that sub element.
      while offset < data_length
        marker  = data[offset,   2].unpack("n")
        marker = marker[0]
        length  = data[offset+2, 2].unpack("n")
        length = length[0]

        if marker == 0xFFC0 || marker == 0xFFC2
          height = data[offset+5, 2].unpack("n")
          @height = height[0]
          width  = data[offset+7, 2].unpack("n")
          @width  = width[0]
          break
        end

        offset += length + 2
        break if marker == 0xFFDA
      end

      raise "#{@filename}: no size data found in jpeg image.\n" unless @height
    end
def process_jpg(data)
      @type     = 5  # Excel Blip type (MSOBLIPTYPE).

      offset = 2
      data_length = data.bytesize

      # Search through the image data to find the 0xFFC0 marker. The height and
      # width are contained in the data for that sub element.
      while offset < data_length
        marker  = data[offset,   2].unpack("n")
        marker = marker[0]
        length  = data[offset+2, 2].unpack("n")
        length = length[0]

        if marker == 0xFFC0 || marker == 0xFFC2
          height = data[offset+5, 2].unpack("n")
          @height = height[0]
          width  = data[offset+7, 2].unpack("n")
          @width  = width[0]
          break
        end

        offset += length + 2
        break if marker == 0xFFDA
      end

      raise "#{@filename}: no size data found in jpeg image.\n" unless @height
    end
Extract width and height information from a JPEG file.