jpeginfo-wrapper
v1.0.0
Published
TypeScript wrapper for jpeginfo command - prints information and tests integrity of JPEG/JFIF files
Maintainers
Readme
jpeginfo-wrapper
A TypeScript wrapper for the jpeginfo command-line tool that prints information and tests integrity of JPEG/JFIF files.
Features
- 🖼️ Complete jpeginfo support - All command-line options and features
- 📊 Multiple output formats - Normal, CSV, and JSON output
- 🔍 Integrity testing - Test JPEG file integrity
- 🔐 Checksum calculation - MD5, SHA-1, SHA-256, SHA-512
- 🐳 Docker support - Ubuntu environment with jpeginfo pre-installed
- 📝 TypeScript support - Full type definitions and IntelliSense
- 🧪 Comprehensive testing - Jest test suite
Installation
Prerequisites
You need to have jpeginfo installed on your system. You can install it via:
Ubuntu/Debian:
sudo apt-get install jpeginfomacOS:
brew install jpeginfoFrom source:
git clone https://github.com/tjko/jpeginfo.git
cd jpeginfo
./configure
make
sudo make installInstall the package
npm install jpeginfo-wrapperQuick Start
import { JpegInfo, getJpegInfo } from 'jpeginfo-wrapper';
// Using the class
const jpeginfo = new JpegInfo();
const result = await jpeginfo.getInfo('image.jpg');
console.log(result.data);
// Using convenience function
const info = await getJpegInfo(['image1.jpg', 'image2.jpg']);
console.log(info.data);Usage Examples
Basic Information
import { JpegInfo } from 'jpeginfo-wrapper';
const jpeginfo = new JpegInfo();
// Get basic information about a JPEG file
const result = await jpeginfo.getInfo('photo.jpg');
console.log(result.data[0]);
// Output:
// {
// filename: 'photo.jpg',
// filesize: 1234567,
// fileDate: '2023:12:25 10:30:45',
// cameraMake: 'Canon',
// cameraModel: 'EOS R5',
// dateTime: '2023:12:25 10:30:45',
// resolution: { width: 8192, height: 5464 },
// flash: false,
// focalLength: 50,
// focalLength35mm: 50,
// exposureTime: '1/125',
// aperture: 'f/2.8',
// ...
// }Multiple Files
// Process multiple files
const result = await jpeginfo.getInfo(['photo1.jpg', 'photo2.jpg', 'photo3.jpg']);
// Process all JPEG files in a directory
const files = ['*.jpg']; // or use glob patterns
const result = await jpeginfo.getInfo(files);Output Formats
// CSV output
const csvData = await jpeginfo.getCsvOutput('photo.jpg');
console.log(csvData);
// Output: Array of objects with CSV headers as keys
// JSON output
const jsonData = await jpeginfo.getJsonOutput('photo.jpg');
console.log(jsonData);
// Output: Array of objects in JSON format
// Concise output (single line per file)
const concise = await jpeginfo.getInfo('photo.jpg', { concise: true });Integrity Testing
// Test file integrity
const integrity = await jpeginfo.testIntegrity('photo.jpg');
console.log(integrity);
// Output:
// {
// success: true,
// exitCode: 0,
// validFiles: ['photo.jpg'],
// invalidFiles: [],
// errorDetails: {}
// }
// Test multiple files
const testResult = await jpeginfo.testIntegrity(['photo1.jpg', 'photo2.jpg']);
if (testResult.invalidFiles.length > 0) {
console.log('Corrupted files:', testResult.invalidFiles);
}Checksum Calculation
// Calculate MD5 checksum
const checksums = await jpeginfo.calculateChecksums('photo.jpg', ['md5']);
console.log(checksums[0].md5);
// Calculate multiple checksums
const multiChecksums = await jpeginfo.calculateChecksums('photo.jpg', ['md5', 'sha1', 'sha256']);
console.log(multiChecksums[0]);
// Output:
// {
// filename: 'photo.jpg',
// filesize: 1234567,
// md5: 'd41d8cd98f00b204e9800998ecf8427e',
// sha1: 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
// sha256: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
// }Advanced Options
// Detailed information with all options
const detailed = await jpeginfo.getInfo('photo.jpg', {
detailed: true, // Show coding, density, CCIR601 sampling
verbose: true, // Verbose output
md5: true, // Calculate MD5
sha256: true, // Calculate SHA-256
format: 'json', // JSON output
header: true // Include headers
});
// Process files from stdin
const stdinResult = await jpeginfo.processStdin({ format: 'csv' });
// Process files from a file list
const fileListResult = await jpeginfo.processFromFile('filelist.txt');API Reference
JpegInfo Class
Constructor
new JpegInfo(jpeginfoBinary?: string)jpeginfoBinary(optional): Path to jpeginfo binary (default: 'jpeginfo')
Methods
getInfo(files, options?)
Get information about JPEG files.
async getInfo(
files: string | string[],
options?: JpegInfoOptions
): Promise<JpegInfoResult>testIntegrity(files)
Test integrity of JPEG files.
async testIntegrity(files: string | string[]): Promise<JpegInfoTestResult>getCsvOutput(files, options?)
Get CSV formatted output.
async getCsvOutput(
files: string | string[],
options?: Omit<JpegInfoOptions, 'format'>
): Promise<JpegInfoCsvOutput[]>getJsonOutput(files, options?)
Get JSON formatted output.
async getJsonOutput(
files: string | string[],
options?: Omit<JpegInfoOptions, 'format'>
): Promise<JpegInfoJsonOutput[]>calculateChecksums(files, types?)
Calculate checksums for JPEG files.
async calculateChecksums(
files: string | string[],
types?: ('md5' | 'sha1' | 'sha256' | 'sha512')[]
): Promise<JpegInfoChecksumOutput[]>Options
JpegInfoOptions
interface JpegInfoOptions {
concise?: boolean; // Concise output (one line)
verbose?: boolean; // Verbose output
quiet?: boolean; // Quiet mode
listingFormat?: boolean; // Alternative listing format
detailed?: boolean; // Show detailed information
test?: boolean; // Test file integrity
errorsOnly?: boolean; // Show only files with errors
md5?: boolean; // Calculate MD5 checksum
sha1?: boolean; // Calculate SHA-1 checksum
sha256?: boolean; // Calculate SHA-256 checksum
sha512?: boolean; // Calculate SHA-512 checksum
format?: 'normal' | 'csv' | 'json'; // Output format
header?: boolean; // Include column headers
stdin?: boolean; // Read from stdin
filesFrom?: string; // Read file list from file
filesStdin?: boolean; // Read file list from stdin
files?: string[]; // Additional files to process
}Docker Support
The package includes Docker support for testing and development:
# Build the Docker image
npm run docker:build
# Run tests in Docker
npm run docker:test
# Or run manually
docker run --rm -v $(pwd):/workspace jpeginfo-wrapper bashThe Docker image includes:
- Ubuntu 22.04 LTS
- Node.js 18.x LTS
- jpeginfo v1.7.1 (latest)
- All necessary build dependencies
Development
Setup
# Clone the repository
git clone https://github.com/your-username/jpeginfo-wrapper.git
cd jpeginfo-wrapper
# Install dependencies
npm install
# Build the project
npm run buildTesting
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watchCode Quality
# Lint code
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run formatLicense
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
Related Projects
- jpeginfo - The original jpeginfo command-line tool
- exif-parser - EXIF data parser
- sharp - High performance image processing
Support
If you encounter any issues or have questions:
- Check the issues page
- Create a new issue with detailed information
- Include your operating system, Node.js version, and jpeginfo version
