### Install ExifReader with Bower Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use Bower to install the ExifReader package and save it as a dependency. ```bash bower install exifreader --save ``` -------------------------------- ### Install ExifReader with npm Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use npm to install the ExifReader package and save it as a dependency. ```bash npm install exifreader --save ``` -------------------------------- ### Import ExifReader using AMD modules Source: https://github.com/mattiasw/exifreader/blob/main/README.md This example shows how to load ExifReader using AMD module syntax with requirejs. ```javascript requirejs(['/path/to/exif-reader.js'], function (ExifReader) { ... }); ``` -------------------------------- ### Clone ExifReader from Git and Install Dependencies Source: https://github.com/mattiasw/exifreader/blob/main/README.md Clone the ExifReader git repository and install its dependencies using npm. ```bash git clone git@github.com:mattiasw/ExifReader.git cd ExifReader npm install ``` -------------------------------- ### Install ExifReader with Yarn 1 Source: https://github.com/mattiasw/exifreader/blob/main/README.md Command to add ExifReader to a project using Yarn 1. ```bash yarn add exifreader ``` -------------------------------- ### Run Linter and Tests Source: https://github.com/mattiasw/exifreader/blob/main/CONTRIBUTING.md Execute the linter and unit tests for code quality checks. Ensure npm install has been run prior to execution. ```bash npm run lint npm test ``` -------------------------------- ### Example of objectAssign for older runtime support Source: https://github.com/mattiasw/exifreader/blob/main/AGENTS.md Use objectAssign from src/utils.js instead of object spread or Object.assign for older runtime support to reduce bundle size. This ensures compatibility with older JavaScript environments. ```javascript const next = objectAssign({}, options, {async: true}); ``` -------------------------------- ### Display Thumbnail in Web Browser Source: https://github.com/mattiasw/exifreader/blob/main/README.md Extract the thumbnail image data from EXIF tags and display it in a web browser using a data URI. This example assumes the image buffer has already been loaded. ```javascript const tags = ExifReader.load(fileBuffer); imageElement.src = 'data:image/jpg;base64,' + tags['Thumbnail'].base64; ``` -------------------------------- ### Save Thumbnail to File in Node.js Source: https://github.com/mattiasw/exifreader/blob/main/README.md Save the extracted thumbnail image data to a new file in a Node.js environment. This example uses the `fs` module. ```javascript const fs = require('fs'); const tags = ExifReader.load(fileBuffer); fs.writeFileSync('/path/to/new/thumbnail.jpg', Buffer.from(tags['Thumbnail'].image)); ``` -------------------------------- ### Load Local Image File in React Native Source: https://github.com/mattiasw/exifreader/blob/main/README.md Load a local image file in React Native, convert it to a buffer, and then use ExifReader to extract EXIF tags. This example uses `react-native-fs` and `base64-arraybuffer`. ```javascript import RNFS from 'react-native-fs'; import {decode} from 'base64-arraybuffer'; import ExifReader from 'exifreader'; const b64Buffer = await RNFS.readFile('YOUR IMAGE URI', 'base64') // Where the URI looks like this: "file:///path/to/image/IMG_0123.HEIC" const fileBuffer = decode(b64Buffer) const tags = ExifReader.load(fileBuffer, {expanded: true}); ``` -------------------------------- ### Load Metadata with Offsets Source: https://github.com/mattiasw/exifreader/blob/main/README.md Load file data and include metadata offsets. The `metadataRange` object provides information about the start and end byte positions of metadata within the file. ```javascript const tags = ExifReader.load(fileBuffer, {expanded: true, includeOffsets: true}); tags.metadataRange.start // lowest block start (informational, can be deep // into the file for HEIC/AVIF; do NOT use as a // slice boundary, always slice from 0) tags.metadataRange.end // exclusive end. Store bytes 0..end to keep all metadata tags.metadataRange.complete // false when the input was truncated before all metadata tags.metadataRange.blocks // [{type, start, end}, ...] sorted by start ``` -------------------------------- ### Import ExifReader using ES module syntax Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use this syntax for importing ExifReader in environments that support ES modules. ```javascript import ExifReader from 'exifreader'; ``` -------------------------------- ### Fetch and Slice Metadata Source: https://github.com/mattiasw/exifreader/blob/main/README.md A typical workflow to fetch the initial bytes of a file, load metadata with offsets, and then slice the minimal metadata-bearing portion. This is useful for reducing the amount of data to upload or store. ```javascript const headChunk = await fetchFirstNBytes(url, 256 * 1024); const tags = ExifReader.load(headChunk, {expanded: true, includeOffsets: true}); if (!tags.metadataRange.complete) { // 256 KiB was not enough, fetch more } else { const minimalSlice = headChunk.slice(0, tags.metadataRange.end); await uploadMetadata(minimalSlice); } ``` -------------------------------- ### Import ExifReader using ES module syntax (alternative) Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use this alternative syntax if you encounter issues with the default export in TypeScript or Angular. ```javascript import * as ExifReader from 'exifreader'; ``` -------------------------------- ### ExifReader Custom Build: Include TIFF, Specific Exif Tags Source: https://github.com/mattiasw/exifreader/blob/main/README.md Configure ExifReader to include TIFF files and specific Exif tags like DateTime and GPS information. This results in a much smaller bundle size. ```json "exifreader": { "include": { "tiff": true, "exif": [ "DateTime", "GPSLatitude", "GPSLatitudeRef", "GPSLongitude", "GPSLongitudeRef", "GPSAltitude", "GPSAltitudeRef" ] } } ``` -------------------------------- ### ExifReader Custom Build: Include JPEG and Exif Source: https://github.com/mattiasw/exifreader/blob/main/README.md Configure ExifReader to only include JPEG files and Exif tags. This significantly reduces the bundle size compared to the full build. ```json "exifreader": { "include": { "jpeg": true, "exif": true } } ``` -------------------------------- ### Rebuild ExifReader with npm Source: https://github.com/mattiasw/exifreader/blob/main/README.md Command to rebuild the ExifReader library after changing its configuration in package.json, typically used with npm. ```bash npm rebuild exifreader ``` -------------------------------- ### Include ExifReader using a script tag Source: https://github.com/mattiasw/exifreader/blob/main/README.md This demonstrates how to include ExifReader directly in an HTML file using a script tag. ```html ``` -------------------------------- ### Rebuild ExifReader with Yarn 2+ Source: https://github.com/mattiasw/exifreader/blob/main/README.md Command to rebuild ExifReader with Yarn 2+. Requires 'node_modules' linker to be enabled. ```bash yarn rebuild exifreader ``` -------------------------------- ### Import ExifReader using CommonJS/Node modules Source: https://github.com/mattiasw/exifreader/blob/main/README.md This is the standard way to import ExifReader in Node.js environments using CommonJS. ```javascript const ExifReader = require('exifreader'); ``` -------------------------------- ### Import ExifReader in React Native Source: https://github.com/mattiasw/exifreader/blob/main/README.md Import the ExifReader library in a React Native project. Ensure the path to `node_modules` is correct. ```javascript import ExifReader from './node_modules/exifreader/src/exif-reader.js'; ``` -------------------------------- ### Load image tags with expanded grouping Source: https://github.com/mattiasw/exifreader/blob/main/README.md Pass an options object with 'expanded: true' to separate Exif, IPTC, and XMP tags if they have the same name. ```javascript const tags = ExifReader.load(fileBuffer, {expanded: true}); ``` -------------------------------- ### Read Partial File with Length Option Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use the `length` option to load only a specified portion of the image file. This is useful for optimizing read times when metadata is known to be at the beginning of the file. This option only works when ExifReader handles file loading. ```javascript const tags = await ExifReader.load(filename, {length: 128 * 1024}); ``` -------------------------------- ### Load image tags asynchronously Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use this asynchronous method when ExifReader should handle file loading. The 'file' can be a File object, a file path, or a URL. ```javascript const tags = await ExifReader.load(file); const imageDate = tags['DateTimeOriginal'].description; const unprocessedTagValue = tags['DateTimeOriginal'].value; ``` -------------------------------- ### Include Unknown Tags Source: https://github.com/mattiasw/exifreader/blob/main/README.md Pass includeUnknown: true to the load function to include tags that are not recognized by ExifReader. ```javascript const tags = ExifReader.load(fileBuffer, {includeUnknown: true}); ``` -------------------------------- ### ExifReader Custom Build: Exclude XMP Tags Source: https://github.com/mattiasw/exifreader/blob/main/README.md Configure ExifReader to exclude XMP tags from the build. This is useful if XMP data is not needed, further reducing bundle size. ```json "exifreader": { "exclude": { "xmp": true } } ``` -------------------------------- ### Load Tags Asynchronously Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use this when parsing specific PNG or JPEG XL files that require asynchronous processing for compressed metadata. Ensure your environment supports the Compression Streams API. ```javascript const tags = await ExifReader.load(file); // or const tags = await ExifReader.load(fileBuffer, {async: true}); ``` -------------------------------- ### Load image tags synchronously Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use this synchronous method when you have already loaded the image file into a buffer. The 'fileBuffer' can be an ArrayBuffer, SharedArrayBuffer, or Buffer. ```javascript const tags = ExifReader.load(fileBuffer); ``` -------------------------------- ### Read Metadata Bytes with length: 'auto' Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use `length: 'auto'` to download or store only the necessary metadata bytes. This requires `expanded: true` and `includeOffsets: true`. The snippet shows how to access the metadata range details. ```javascript const tags = await ExifReader.load(url, { length: 'auto', expanded: true, includeOffsets: true, excludeTags: {mpf: true}, // skip embedded preview; see note below }); tags.metadataRange.end // exact byte count needed for the metadata tags.metadataRange.buffer // bytes [0, end), sliced from what we read. // Same kind as the input (ArrayBuffer or // Node Buffer). Save this to disk to keep // only the metadata-bearing prefix. tags.metadataRange.fetched // bytes actually read. May be greater than // `end` because the loop reads in fixed-size // chunks and so may read a little past `end`. tags.metadataRange.requests // number of IO calls performed ``` -------------------------------- ### Include Only XMP Tags Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use includeTags to specify that only XMP tags should be returned, excluding all other groups. ```javascript const tags = ExifReader.load(fileBuffer, { includeTags: { xmp: true, } }); ``` -------------------------------- ### Generate Test Coverage Report Source: https://github.com/mattiasw/exifreader/blob/main/CONTRIBUTING.md Generate a test coverage report to identify untested code sections. The report will fail if coverage is reduced and provides an HTML version for visual inspection. ```bash npm run coverage ``` -------------------------------- ### Parse XMP Tags with xmldom Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use the 'xmldom' library to parse XMP tags in non-DOM environments like Node.js. Configure the DOMParser with an onError callback to prevent potential infinite loops with certain XML inputs. ```javascript import {DOMParser, onErrorStopParsing} from '@xmldom/xmldom'; // ... const tags = ExifReader.load(fileBuffer, {domParser: new DOMParser({onError: onErrorStopParsing})}); ``` -------------------------------- ### Custom Brotli Decompression with brotli-wasm Source: https://github.com/mattiasw/exifreader/blob/main/README.md Integrate the 'brotli-wasm' library for Brotli decompression when a custom function is needed. Ensure the library is imported and awaited before use. ```javascript import brotliPromise from 'brotli-wasm'; const brotli = await brotliPromise; const tags = await ExifReader.load(file, { async: true, decompress: { brotli: async (data) => brotli.decompress(data), } }); ``` -------------------------------- ### Custom Brotli Decompression Source: https://github.com/mattiasw/exifreader/blob/main/README.md Provide a custom Brotli decompression function when running in environments without native Brotli support in the Compression Streams API, such as Chrome. This function should accept compressed data and return decompressed data or a Promise resolving to it. ```javascript const tags = await ExifReader.load(file, { async: true, decompress: { brotli: async (compressedData) => myBrotliDecompress(compressedData), } }); ``` -------------------------------- ### Webpack 4/5 Buffer Shim Configuration Source: https://github.com/mattiasw/exifreader/blob/main/README.md For Webpack 4 or lower, this configuration prevents Webpack from including a Buffer shim in browser builds. Webpack 5 handles this automatically. ```javascript node: { Buffer: false } ``` -------------------------------- ### Limit Decompressed Metadata Size Source: https://github.com/mattiasw/exifreader/blob/main/README.md Override the default maximum size for decompressed metadata blocks to prevent excessive memory usage. Specify the limit in bytes. ```javascript const tags = await ExifReader.load(file, { async: true, decompress: { maxDecompressedSize: 16 * 1024 * 1024 // 16 MiB } }); ``` -------------------------------- ### Enable Computed Tag Values Source: https://github.com/mattiasw/exifreader/blob/main/README.md Pass `computed: true` in the options to enable the `computed` value for TIFF-parsed tags. This provides type-aware values for RATIONAL/SRATIONAL and ASCII tags. ```javascript const tags = ExifReader.load(fileBuffer, {computed: true}); const make = tags['Make'].computed; // e.g. "Apple" const xResolution = tags['XResolution'].computed; // e.g. 72 ``` -------------------------------- ### Exclude Specific Exif Tags Source: https://github.com/mattiasw/exifreader/blob/main/README.md Use excludeTags to omit specific tags like 'MakerNote' or tag ID 0x9286 from the Exif group. ```javascript const tags = ExifReader.load(fileBuffer, { excludeTags: { exif: ['MakerNote', 0x9286], } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.