Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set unitCount=1 for ThumbnailOffset #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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