Class: EmbedXMP::JPEG

Inherits:
JFIF show all
Defined in:
lib/embed_xmp/jpeg.rb

Overview

JPEG images

Constant Summary collapse

JPEG_AP1 =
"\xFF\xE1".b
JPEG_IMG =
"\xFF\xDA".b
JPEG_XMP =
"http://ns.adobe.com/xap/1.0/\0".b
JPEG_EXF =
"Exif\0\0".b

Constants inherited from JFIF

EmbedXMP::JFIF::JFIF_END, EmbedXMP::JFIF::JFIF_SOI

Instance Method Summary collapse

Methods inherited from JFIF

#check_file_markers, #new_segment, #remove_segment, #segment

Methods inherited from ImageFile

#initialize, #insert_into_file, #read_io_or_string, #write

Constructor Details

This class inherits a constructor from EmbedXMP::ImageFile

Instance Method Details

#join_sidecar(sidecar_file, xpacked: false) ⇒ Object

Join an XMP sidecar file into the image file.



17
18
19
20
21
22
23
24
25
# File 'lib/embed_xmp/jpeg.rb', line 17

def join_sidecar(sidecar_file, xpacked: false)
  check_file_markers
  remove_xmp

  sidecar = read_io_or_string(sidecar_file)
  xmp_chunk = create_xmp_segment(sidecar, xpacked)

  insert_into_file(find_xmp_insertion_offset, xmp_chunk)
end

#remove_xmpObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/embed_xmp/jpeg.rb', line 27

def remove_xmp
  offset = JFIF_SOI.length
  while offset < @image_data.length
    marker, length, = segment(offset)

    break if [JPEG_IMG, JFIF_END, nil].include?(marker)

    if segment_is_app1_xmp(offset, marker)
      remove_segment(offset)
      next
    end

    offset += length
  end
end