class HexaPDF::Type::Image

Parent

Represents an image XObject of a PDF document.

See: PDF1.7 s8.8

Constants

Info

The structure that is returned by the #info method.

Attributes

source_path[RW]

Returns the source path that was used when creating the image object.

This value is only set when the image object was created by using the image loading facility and not when the image is part of a loaded PDF file.

Public Instance Methods

height()

Returns the height of the image.

info()

Returns an Info structure with information about the image.

Available accessors:

type

The type of the image. Either :jpeg, :jp2, :jbig2, :ccitt or :png.

width

The width of the image.

height

The height of the image.

color_space

The color space the image uses. Either :rgb, :cmyk, :gray or :other.

indexed

Whether the image uses an indexed color space or not.

components

The number of color components of the color space, or -1 if the number couldn't be determined.

bits_per_component

The number of bits per color component.

writable

Whether the image can be written by HexaPDF.

extension

The file extension that would be used when writing the file. Either jpg, jpx or png. Only meaningful when writable is true.

width()

Returns the width of the image.

write(basename)
write(io)

Saves this image XObject to the file with the given name and appends the correct extension (if the name already contains this extension, the name is used as is), or the given IO object.

Raises an error if the image format is not supported.

The output format and extension depends on the image type as returned by the info method:

:jpeg

Saved as a JPEG file with the extension '.jpg'

:jp2

Saved as a JPEG2000 file with the extension '.jpx'

:png

Saved as a PNG file with the extension '.png'