Skip to content

Conversation

@sdkawata
Copy link

fix #70

This pull request fixes a bug where certain tools (such as exiftool) raised warnings and failed to extract thumbnails properly when updating EXIF tags using this library. Upon investigation, setting unitCount for ThumbnailOffset to 1 resolves the issue.

Here's the code snippet I use to update EXIF tags:

package main

import (
	"io"
	"os"

	jpegstructure "github.com/dsoprea/go-jpeg-image-structure/v2"
)

func main() {
	f, err := os.Open("./input.jpg")
	if err != nil {
		panic(err)
	}
	imageBytes, err := io.ReadAll(f)
	if err != nil {
		panic(err)
	}
	jmp := jpegstructure.NewJpegMediaParser()
	intfc, err := jmp.ParseBytes(imageBytes)
	if err != nil {
		panic(err)
	}
	sl := (intfc).(*jpegstructure.SegmentList)
	rootIb, err := sl.ConstructExifBuilder()
	if err != nil {
		panic(err)
	}
	err = sl.SetExif(rootIb)
	if err != nil {
		panic(err)
	}
	wf, err := os.Create("./result.jpg")
	if err != nil {
		panic(err)
	}
	err = sl.Write(wf)
	if err != nil {
		panic(err)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Thumbnail offset gets corrupted when updating a tag

1 participant