media_image

package module
v0.0.0-...-de1b17a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 17, 2025 License: MIT Imports: 28 Imported by: 1

README

📷 media.image

Work in Progress Go Report Card GoDoc Release License

Overview

media.image is a specialized library within the SmartMediaFiles ecosystem. Its purpose is to define and categorize all file types and extensions related to raster images. This library provides the necessary definitions for the main @/media library to recognize and classify image files like JPEG, PNG, GIF, etc.

Features

  • File Type Definitions: Provides a list of FileType constants for each supported image format (e.g., ImageJpeg).
  • File Extension Definitions: Provides a list of all corresponding FileExtension constants (e.g., ExtensionJpg, ExtensionJpeg).
  • Type-to-Extension Mapping: Contains the ImageFileTypesExtensions map that links each file type to its extensions, which is then consumed by the central @/media registry.
  • Future-proofing: This library will be expanded to include functions for extracting image-specific metadata (e.g., EXIF data, dimensions).

Installation

go get -u github.com/smartmediafiles/media.image

Usage

You would typically use this library indirectly through the main @/media package. However, you can also use it directly if you are only working with image files.

package main

import (
	"fmt"
	"github.com/smartmediafiles/media.image"
)

func main() {
	// Get all extensions for the JPEG file type
	jpegExtensions := media_image.ImageFileTypesExtensions[media_image.ImageJpeg]
	fmt.Printf("JPEG extensions: %v\n", jpegExtensions)
}

License

This project is licensed under the MIT License - see the LICENSE.md file for details.


⚠️ Note: This README will be updated regularly as the project progresses. Check back often for the latest information!

Documentation

Index

Constants

View Source
const (
	ExtensionBmp  types.FileExtension = ".bmp"  // Bitmap Image
	ExtensionDib  types.FileExtension = ".dib"  // Device Independent Bitmap
	ExtensionGif  types.FileExtension = ".gif"  // Graphics Interchange Format (GIF)
	ExtensionHeic types.FileExtension = ".heic" // High Efficiency Image Container (HEIC)
	ExtensionHeif types.FileExtension = ".heif" // High Efficiency Image File Format (HEIF)
	ExtensionJpg  types.FileExtension = ".jpg"  // Joint Photographic Experts Group (JPEG)
	ExtensionJpeg types.FileExtension = ".jpeg" // Joint Photographic Experts Group (JPEG)
	ExtensionJpe  types.FileExtension = ".jpe"  // Joint Photographic Experts Group (JPEG)
	ExtensionJif  types.FileExtension = ".jif"  // Joint Photographic Experts Group (JPEG)
	ExtensionJfif types.FileExtension = ".jfif" // Joint Photographic Experts Group (JPEG)
	ExtensionJfi  types.FileExtension = ".jfi"  // Joint Photographic Experts Group (JPEG)
	ExtensionPng  types.FileExtension = ".png"  // Portable Network Graphics (PNG)
	ExtensionTiff types.FileExtension = ".tiff" // Tagged Image File Format (TIFF)
	ExtensionTif  types.FileExtension = ".tif"  // Tagged Image File Format (TIFF)
	ExtensionWebp types.FileExtension = ".webp" // Google WebP Image
)

List of supported media.Image file extensions.

View Source
const (
	ImageBmp  types.FileType = "bmp"  // Bitmap Image
	ImageGif  types.FileType = "gif"  // Graphics Interchange Format (GIF)
	ImageHeic types.FileType = "heic" // High Efficiency Image Container (HEIC)
	ImageHeif types.FileType = "heif" // High Efficiency Image File Format (HEIF)
	ImageJpeg types.FileType = "jpg"  // Joint Photographic Experts Group (JPEG)
	ImagePng  types.FileType = "png"  // Portable Network Graphics (PNG)
	ImageTiff types.FileType = "tiff" // Tagged Image File Format (TIFF)
	ImageWebp types.FileType = "webp" // Google WebP Image
)

List of supported media.Image file types.

Variables

ImageFileExtensions is a list of supported media.Image file extensions.

ImageFileTypes is a list of supported media.Image file types.

View Source
var ImageFileTypesExtensions = maps.MapFileTypeExtensions{
	ImageBmp:  {ExtensionBmp, ExtensionDib},
	ImageGif:  {ExtensionGif},
	ImageHeic: {ExtensionHeic},
	ImageHeif: {ExtensionHeif},
	ImageJpeg: {ExtensionJpg, ExtensionJpeg, ExtensionJpe, ExtensionJif, ExtensionJfif, ExtensionJfi},
	ImagePng:  {ExtensionPng},
	ImageTiff: {ExtensionTiff, ExtensionTif},
	ImageWebp: {ExtensionWebp},
}

ImageFileTypesExtensions is a map of media.Image file types to their file extensions.

Functions

func IsImage

func IsImage(fileType types.FileType) bool

IsImage checks if the given file type is considered an image.

func IsPhoto

func IsPhoto(fileType types.FileType) bool

IsPhoto checks if the given file type is considered a photo.

Types

type ExifDataParser

type ExifDataParser struct {
	// contains filtered or unexported fields
}

ExifDataParser is responsible for extracting and parsing EXIF metadata from images. It maintains a cache of parsed tags to improve performance when processing multiple images.

func NewExifDataParser

func NewExifDataParser() *ExifDataParser

NewExifDataParser creates and initializes a new instance of ExifDataParser. It initializes the tag cache used to store parsed EXIF tags for better performance.

Returns:

  • *ExifDataParser: A pointer to the newly created parser instance

func (*ExifDataParser) Parse

func (p *ExifDataParser) Parse(exifData []byte) (ImageData, error)

Parse extracts and processes EXIF metadata from raw image data. It performs a comprehensive extraction of all available EXIF information and organizes it into a structured ImageData object.

Parameters:

  • exifData: Raw EXIF data bytes from the image

Returns:

  • ImageData: Structured representation of the extracted metadata
  • error: Any error encountered during parsing

type ExifParser

type ExifParser struct{}

ExifParser is a struct that contains the EXIF parser.

func NewExifParser

func NewExifParser() *ExifParser

NewExifParser creates a new ExifParser struct.

func (*ExifParser) Parse

func (p *ExifParser) Parse(path string, fileType types.FileType) ([]byte, error)

Parse parses the EXIF data from the file.

type ImageData

type ImageData struct {
	// GPS information extracted from the EXIF data
	GPSLatitude          float64   `exif:"GPSLatitude"`
	GPSLongitude         float64   `exif:"GPSLongitude"`
	GPSAltitude          float64   `exif:"GPSAltitude"`
	GPSTimeZone          string    // Determined from coordinates
	GPSTimestamp         time.Time `exif:"GPSDateStamp,GPSTimeStamp"`
	GPSTimestampLocal    time.Time // Computed from GPSTimestamp and GPSTimeZone
	GPSProcessingMethod  string    `exif:"GPSProcessingMethod"`
	GPSStatus            string    `exif:"GPSStatus"`
	GPSSatellites        string    `exif:"GPSSatellites"`
	GPSHPositioningError float64   `exif:"GPSHPositioningError"`
	GPSSpeed             float64   `exif:"GPSSpeed"`
	GPSTrack             float64   `exif:"GPSTrack"`
	GPSImgDirection      float64   `exif:"GPSImgDirection"`
	GPSDestLatitude      float64   `exif:"GPSDestLatitude"`
	GPSDestLongitude     float64   `exif:"GPSDestLongitude"`
	GPSDestBearing       float64   `exif:"GPSDestBearing"`
	GPSDestDistance      float64   `exif:"GPSDestDistance"`

	// Camera information extracted from the EXIF data
	CameraMake        string    `exif:"Make,CameraMake"`
	CameraModel       string    `exif:"Model,CameraModel"`
	CameraExposure    string    `exif:"ExposureTime,Exposure"`
	ISOSpeed          int       `exif:"ISOSpeedRatings,ISO"`
	ShutterSpeed      string    `exif:"ShutterSpeedValue"`
	Software          string    `exif:"Software"`
	DateTime          time.Time `exif:"DateTime,CreateDate"`
	DateTimeOriginal  time.Time `exif:"DateTimeOriginal,OriginalDateTime"`
	DateTimeDigitized time.Time `exif:"DateTimeDigitized,DigitizedDateTime"`
	TimeOffset        string    `exif:"OffsetTime,OffsetTimeOriginal,OffsetTimeDigitized"` // Format: "+0200" or "-0700"
	SubSecOriginal    string    `exif:"SubSecTimeOriginal,SubSecTime"`                     // Subsecond precision
	HasTimeOffset     bool      // Indicates if time offset was found

	// Lens information extracted from the EXIF data
	LensMake            string `exif:"LensMake"`
	LensModel           string `exif:"LensModel,Lens"`
	LensFocalLength     string `exif:"FocalLength"`
	LensAperture        string `exif:"FNumber,ApertureValue"`
	LensFocalLength35mm string `exif:"FocalLengthIn35mmFilm"`
	LensMaxAperture     string `exif:"MaxApertureValue"`
	LensMinAperture     string `exif:"MinApertureValue"`
	LensMaxFocalLength  string `exif:"MaxFocalLength"`

	// Image information
	ImageWidth       int      `exif:"ImageWidth,PixelXDimension,ExifImageWidth,SourceImageWidth"`
	ImageHeight      int      `exif:"ImageHeight,PixelYDimension,ExifImageHeight,SourceImageHeight"`
	ImageOrientation int      `exif:"Orientation"`
	ColorSpace       string   `exif:"ColorSpace"`
	Compression      string   `exif:"Compression"`
	XResolution      Rational `exif:"XResolution"`
	YResolution      Rational `exif:"YResolution"`
	ResolutionUnit   string   `exif:"ResolutionUnit"`

	// Additional EXIF information
	Artist           string  `exif:"Artist,Creator"`
	Copyright        string  `exif:"Copyright,CopyrightNotice"`
	Description      string  `exif:"ImageDescription,Description"`
	WhiteBalance     string  `exif:"WhiteBalance"`
	Flash            string  `exif:"Flash,FlashFired"`
	MeteringMode     string  `exif:"MeteringMode"`
	ExposureProgram  string  `exif:"ExposureProgram"`
	SceneCaptureType string  `exif:"SceneCaptureType"`
	SubjectDistance  float64 `exif:"SubjectDistance"`
	DigitalZoomRatio float64 `exif:"DigitalZoomRatio"`
}

type ImageInfo

type ImageInfo struct {
	// File information
	FileInfo fs.FileInfo
	FileType types.FileType
	FileExt  types.FileExtension

	// Image information
	ImageData ImageData
}

ImageInfo is a structure that contains information about an image file. This information are extracted from the image file exif data.

func NewImageInfo

func NewImageInfo(path string) (*ImageInfo, error)

NewImageInfo creates a new ImageInfo struct.

func (*ImageInfo) Exif

func (i *ImageInfo) Exif() (*ImageInfo, error)

Exif extracts the image information from the exif data.

func (*ImageInfo) IsImage

func (i *ImageInfo) IsImage() bool

IsImage checks if the image is an image.

func (*ImageInfo) IsPhoto

func (i *ImageInfo) IsPhoto() bool

IsPhoto checks if the image is a photo.

type Rational

type Rational struct {
	Numerator   int
	Denominator int
}

Rational represents a rational number with a numerator and a denominator.

func NewRational

func NewRational(s string) (Rational, error)

func (Rational) String

func (r Rational) String() string

String converts a Rational to a string formatted as "numerator/denominator".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL