#walkzzz/image.mbt/meta

    元数据处理(EXIF 读写、PNG 元数据)

    #概览

    项目数量
    公开函数10
    公开类型2
    常量0
    错误类型0

    #类型

    pub(all) struct ExifInfo {
    pub(all) struct PngTextChunk {

    #API

    pub fn create_exif_segment(ExifInfo) -> Bytes
    pub fn read_exif_from_bytes(Bytes) -> ExifInfo?
    pub fn read_png_text_chunks(Bytes) -> Array[PngTextChunk]
    pub fn write_exif_to_bytes(ExifInfo, Bytes) -> Bytes raise @types.LoadError
    pub fn ExifInfo::equal(Self, Self) -> Bool
    pub fn ExifInfo::not_equal(Self, Self) -> Bool
    pub fn ExifInfo::to_repr(Self) -> @debug.Repr
    pub fn PngTextChunk::equal(Self, Self) -> Bool
    pub fn PngTextChunk::not_equal(Self, Self) -> Bool
    pub fn PngTextChunk::to_repr(Self) -> @debug.Repr

    #纯 MoonBit 实现

    本包不依赖任何 C FFI,四目标(native/wasm-gc/js/wasm)均可编译运行。

    ExifInfo

    pub(all) struct ExifInfo {
    make : String
    model : String
    orientation : Int
    date_time : String
    } derive(Default, Eq,
    Debug
    )

    EXIF 元数据信息

    ExifInfo::default

    fn ExifInfo::default() -> ExifInfo
    automatically derived

    ExifInfo::equal

    fn ExifInfo::equal(ExifInfo, ExifInfo) -> Bool
    automatically derived

    ExifInfo::not_equal

    fn ExifInfo::not_equal(x : ExifInfo, y : ExifInfo) -> Bool
    automatically derived

    ExifInfo::to_repr

    automatically derived

    ExifInfoExtended

    pub(all) struct ExifInfoExtended {
    make : String
    model : String
    orientation : Int
    date_time : String
    exposure_time : String
    f_number : Double
    iso : Int
    focal_length : Double
    exposure_mode : Int
    white_balance : Int
    flash : Int
    gps_latitude : Double
    gps_longitude : Double
    gps_altitude : Double
    pixel_x_dim : Int
    pixel_y_dim : Int
    } derive(Default, Eq,
    Debug
    )

    扩展 EXIF 元数据信息

    ExifInfoExtended::default

    automatically derived

    ExifInfoExtended::equal

    automatically derived

    ExifInfoExtended::not_equal

    fn ExifInfoExtended::not_equal(x : ExifInfoExtended, y : ExifInfoExtended) -> Bool
    automatically derived

    ExifInfoExtended::to_repr

    automatically derived

    IptcInfo

    pub(all) struct IptcInfo {
    title : String
    keywords : String
    creator : String
    creator_title : String
    city : String
    country : String
    caption : String
    caption_writer : String
    date_created : String
    category : String
    urgency : Int
    raw_records : Array[(Int, Int, String)]
    } derive(Default, Eq,
    Debug
    )

    IPTC IIM 元数据(常用字段)

    IptcInfo::default

    fn IptcInfo::default() -> IptcInfo
    automatically derived

    IptcInfo::equal

    fn IptcInfo::equal(IptcInfo, IptcInfo) -> Bool
    automatically derived

    IptcInfo::not_equal

    fn IptcInfo::not_equal(x : IptcInfo, y : IptcInfo) -> Bool
    automatically derived

    IptcInfo::to_repr

    automatically derived

    PngTextChunk

    pub(all) struct PngTextChunk {
    keyword : String
    text : String
    } derive(Default, Eq,
    Debug
    )

    PNG text chunk(关键字-文本对)

    PngTextChunk::default

    fn PngTextChunk::default() -> PngTextChunk
    automatically derived

    PngTextChunk::equal

    automatically derived

    PngTextChunk::not_equal

    fn PngTextChunk::not_equal(x : PngTextChunk, y : PngTextChunk) -> Bool
    automatically derived

    PngTextChunk::to_repr

    automatically derived

    XmpInfo

    pub(all) struct XmpInfo {
    creator : String
    title : String
    description : String
    subject : String
    keywords : String
    rights : String
    create_date : String
    modify_date : String
    software : String
    rating : Int
    raw_xml : String
    } derive(Default, Eq,
    Debug
    )

    XMP 元数据(常用字段)

    XmpInfo::default

    fn XmpInfo::default() -> XmpInfo
    automatically derived

    XmpInfo::equal

    fn XmpInfo::equal(XmpInfo, XmpInfo) -> Bool
    automatically derived

    XmpInfo::not_equal

    fn XmpInfo::not_equal(x : XmpInfo, y : XmpInfo) -> Bool
    automatically derived

    XmpInfo::to_repr

    automatically derived

    create_exif_segment

    fn create_exif_segment(info : ExifInfo) -> Bytes

    构造 EXIF APP1 segment 数据(不含 FF E1 前缀和长度)。 返回 "Exif\0\0" + TIFF 头(大端) + IFD0 + 数据区

    create_iptc_segment

    fn create_iptc_segment(info : IptcInfo) -> Bytes

    构造 IPTC APP13 段数据(不含 FF ED 前缀和长度)

    create_xmp_segment

    fn create_xmp_segment(info : XmpInfo) -> Bytes

    构造 XMP APP1 段数据(不含 FF E1 前缀和长度)

    read_exif_extended_from_bytes

    fn read_exif_extended_from_bytes(data : Bytes) -> ExifInfoExtended?

    从 JPEG 字节流读取扩展 EXIF 元数据 返回 None 如果不含 EXIF 数据

    read_exif_from_bytes

    fn read_exif_from_bytes(data : Bytes) -> ExifInfo?

    从 JPEG 字节流读取 EXIF 元数据。 返回 None 如果不含 EXIF 数据。

    read_iptc_from_bytes

    fn read_iptc_from_bytes(data : Bytes) -> IptcInfo?

    从 JPEG 字节流读取 IPTC IIM 元数据 返回 None 如果不含 IPTC 数据

    read_png_exif_from_bytes

    fn read_png_exif_from_bytes(data : Bytes) -> Bytes?

    从 PNG eXIf chunk 读取 EXIF 数据 返回原始 EXIF 字节(以 "MM" 或 "II" TIFF 头开头),不含 "Exif\0\0" 前缀

    read_png_text_chunks

    fn read_png_text_chunks(data : Bytes) -> Array[PngTextChunk]

    从 PNG 字节流读取 text chunks(tEXt 和 iTXt)。 返回关键字-文本对数组。不含 EXIF 等其他元数据。

    read_xmp_from_bytes

    fn read_xmp_from_bytes(data : Bytes) -> XmpInfo?

    从 JPEG 字节流读取 XMP 元数据 返回 None 如果不含 XMP 数据

    write_exif_to_bytes

    fn write_exif_to_bytes(info : ExifInfo, jpeg_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 EXIF 元数据写入 JPEG 字节流。 在 SOI (FF D8) 之后插入 APP1 segment。 如果已有 APP1 EXIF segment,替换之。

    write_iptc_to_bytes

    fn write_iptc_to_bytes(info : IptcInfo, jpeg_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 IPTC 写入 JPEG(在 SOI 后插入 APP13,已有则替换)

    write_png_exif_to_bytes

    fn write_png_exif_to_bytes(exif_data : Bytes, png_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 EXIF 数据写入 PNG eXIf chunk(在 IDAT 前插入) exif_data 应以 "MM" 或 "II" TIFF 头开头

    write_png_text_chunks

    fn write_png_text_chunks(chunks : Array[PngTextChunk], png_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 text chunks 写入 PNG(在 IDAT 前插入 tEXt chunks) 已有同名 keyword 的 tEXt 不做去重,直接追加

    write_xmp_to_bytes

    fn write_xmp_to_bytes(info : XmpInfo, jpeg_data : Bytes) -> Bytes raise
    core
    /types.LoadError

    将 XMP 写入 JPEG(在 SOI 后插入 APP1,已有则替换)