ProductPromotion
Logo

Kotlin

made by https://0x3d.site

GitHub - Ashampoo/kim: Image metadata manipulation library for Kotlin Multiplatform
Image metadata manipulation library for Kotlin Multiplatform - Ashampoo/kim
Visit Site

GitHub - Ashampoo/kim: Image metadata manipulation library for Kotlin Multiplatform

GitHub - Ashampoo/kim: Image metadata manipulation library for Kotlin Multiplatform

Kim - Kotlin Image Metadata

Kotlin JVM Android iOS Windows Linux macOS JS WASM Coverage

Kim is a Kotlin Multiplatform library for reading and writing image metadata.

It's part of Ashampoo Photo Organizer.

Features

  • JPG: Read & Write EXIF, IPTC & XMP
  • PNG: Read & Write eXIf chunk & XMP
    • Also read non-standard EXIF & IPTC from tEXt/zTXt chunk
  • WebP: Read & Write EXIF & XMP
  • HEIC / AVIF: Read EXIF & XMP
  • JXL: Read & Write EXIF & XMP of uncompressed files
  • TIFF / RAW: Read EXIF & XMP
    • Full support for Adobe DNG, Canon CR2, Canon CR3 & Fujifilm RAF
    • Support for Nikon NEF, Sony ARW & Olympus ORF without lens info
    • Support for Panasonic RW2 without lens info and image size
    • API for preview image extraction of DNG, CR2, CR3, RAF, NEF, ARW & RW2
  • Handling of XMP content through XMP Core for Kotlin Multiplatform
  • Convenient Kim.update() API to perform updates to the relevant places
    • JPG: Lossless rotation by modifying only one byte (where present)

The future development of features on our part is driven entirely by the needs of Ashampoo Photo Organizer, which, in turn, is driven by user community feedback.

Installation

implementation("com.ashampoo:kim:0.20")

For the targets wasmJs & js you also need to specify this:

implementation(npm("pako", "2.1.0"))

Sample usages

Read metadata

Kim.readMetadata() takes kotlin.ByteArray on all platforms and depending on the platform also kotlinx.io.files.Path, Ktor Source & ByteReadChannel, java.io.File, java.io.InputStream, NSData and String paths.

val bytes: ByteArray = loadBytes()

val metadata = Kim.readMetadata(bytes)

/* ImageMetadata has a proper toString() similar to the output of ExifTool */
println(metadata)

val orientation = metadata.findShortValue(TiffTag.TIFF_TAG_ORIENTATION)

println("Orientation: $orientation")

val takenDate = metadata.findStringValue(ExifTag.EXIF_TAG_DATE_TIME_ORIGINAL)

println("Taken date: $takenDate")

Create high level summary object

This creates an instance of PhotoMetadata. It contains the following:

  • Image size
  • Orientation
  • Taken date
  • GPS coordinates
  • Camera make & model
  • Lens make & model
  • ISO, Exposure time, F-Number, Focal length
  • Rating
  • Keywords
  • Faces (XMP-mwg-rs regions, used by Picasa and others)
  • Persons in image
val bytes: ByteArray = loadBytes()

val photoMetadata = Kim.readMetadata(bytes).convertToPhotoMetadata()

Change orientation using low level API

val inputFile = File("myphoto.jpg")
val outputFile = File("myphoto_changed.jpg")

val metadata = Kim.readMetadata(inputFile)

val outputSet: TiffOutputSet = metadata.exif?.createOutputSet() ?: TiffOutputSet()

val rootDirectory = outputSet.getOrCreateRootDirectory()

rootDirectory.removeField(TiffTag.TIFF_TAG_ORIENTATION)
rootDirectory.add(TiffTag.TIFF_TAG_ORIENTATION, 8)

OutputStreamByteWriter(outputFile.outputStream()).use { outputStreamByteWriter ->

    JpegRewriter.updateExifMetadataLossless(
        byteReader = JvmInputStreamByteReader(inputFile.inputStream(), inputFile.length()),
        byteWriter = outputStreamByteWriter,
        outputSet = outputSet
    )
}

See the example project for more details.

Change orientation using Kim.update() API

val bytes: ByteArray = loadBytes()

val newBytes = Kim.update(
    bytes = bytes,
    update = MetadataUpdate.Orientation(TiffOrientation.ROTATE_RIGHT)
)

See AbstractUpdaterTest for more samples.

Update thumbnail using Kim.update() API

val bytes: ByteArray = loadBytes()
val thumbnailBytes: ByteArray = loadThumbnailBytes()

val newBytes = Kim.updateThumbnail(
    bytes = bytes,
    thumbnailBytes = thumbnailBytes
)

Using Java

See the Java example project how to use Kim in Java projects.

Limitations

  • Inability to update EXIF, IPTC and XMP in JPG files simultaneously.
  • Does not read the image size and orientation for HEIC, AVIF & JPEG XL.
  • Does not read brotli compressed metadata of JPEG XL due to missing brotli KMP libs.
  • MakerNote support is experimental and limited.
    • Can't extract preview image of ORF as offsets are burried into MakerNote.
    • Can't identify lens info of NEF, ARW, RW2 & ORF because this is constructed from MakerNote fields.
    • Missing image size for RW2 as this is also burried in MakerNotes.
  • There is right now no convienient tooling for GeoTiff like there is for GPS.

Regarding HEIC & AVIF metadata

In the processing of HEIC and AVIF files, we handle them as standard ISOBMFF-based files, adhering rigorously to the EIC/ISO 14496-12 specification. To preempt potential legal issues, we intentionally omit certain boxes outlined in the HEIC specification, notably the image size ("ispe") and image rotation ("irot") boxes. This approach extends to AVIF images, as they repurpose the same boxes.

Contributions

Contributions to Ashampoo Kim are welcome! If you encounter any issues, have suggestions for improvements, or would like to contribute new features, please feel free to submit a pull request.

Acknowledgements

License

This code is under the Apache License 2.0.

See the NOTICE.txt file for required notices and attributions.

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory