Skip to content

Commit

Permalink
✅ Test: png
Browse files Browse the repository at this point in the history
  • Loading branch information
soxft committed Nov 5, 2024
1 parent 231f52a commit 6710cb7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions fg/fg.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var Path string
var DateTime string
var DateTpl = "2006-01-02 15.04.05"
var Force bool
var SkipSafeQA bool

// Parse 解析命令行参数
func Parse() {
Expand All @@ -17,6 +18,7 @@ func Parse() {
flag.StringVar(&DateTime, "datetime", "", "日期时间")
flag.StringVar(&DateTpl, "tpl", "2006-01-02 15.04.05", "日期时间模板, 默认为 '2006-01-02 15.04.05' 请参照 Golang 时间 layout 设置, 不适用于 QuMagie 模式")
flag.BoolVar(&Force, "f", false, "强制执行, 不会检查是否已经有日期")
flag.BoolVar(&SkipSafeQA, "skipSafeQA", false, "跳过安全 QA, 直接执行")

flag.Parse()
}
23 changes: 14 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"log"
"photo_exif_do/fg"
"photo_exif_do/qumagie"
Expand All @@ -11,21 +12,25 @@ func main() {
fg.Parse()

// 安全 QA
//log.Println("请确保已经设置了快照,程序将会直接修改文件的 exif 元数据, 建议在使用前选择少量照片进行测试后再使用")
//log.Println("您确认要继续吗? (y/n)")
//var confirm string
//
//if _, err := fmt.Scanln(&confirm); err != nil {
// return
//} else if confirm != "y" {
// log.Fatal("已取消")
//}
if fg.SkipSafeQA {
log.Println("请确保已经设置了快照,程序将会直接修改文件的 exif 元数据, 建议在使用前选择少量照片进行测试后再使用")
log.Println("您确认要继续吗? (y/n)")
var confirm string

if _, err := fmt.Scanln(&confirm); err != nil {
return
} else if confirm != "y" {
log.Fatal("已取消")
}
}

// 读取目录
switch fg.Mode {
case "dir": // 指定文件夹批量修改
log.Println("Not implemented yet")
break
case "dirDate": //按照上级文件夹名称修改
log.Println("Not implemented yet")
break
case "test":
// log.Println(x_exif.SetDate("pics/qumagie/2006-01-02 15.04.05.jpg", time.Now(), true))
Expand Down
17 changes: 17 additions & 0 deletions x_exif/exif.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,23 @@ import (
"time"
)

// setExifTag 设置exif标签
func setExifTag(rootIB *exif.IfdBuilder, ifdPath, tagName, tagValue string) error {
// fmt.Printf("setTag(): ifdPath: %v, tagName: %v, tagValue: %v",
// ifdPath, tagName, tagValue)

ifdIb, err := exif.GetOrCreateIbFromRootIb(rootIB, ifdPath)
if err != nil {
return fmt.Errorf("failed to get or create IB: %v", err)
}

if err := ifdIb.SetStandardWithName(tagName, tagValue); err != nil {
return fmt.Errorf("failed to set DateTime tag: %v", err)
}

return nil
}

// ReadExif 获取exif 中的 DateTimeOriginal
func ReadExif(path string) (string, error) {
opt := exif.ScanOptions{}
Expand Down
17 changes: 0 additions & 17 deletions x_exif/jpg.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,6 @@ import (
"time"
)

// setExifTag 设置exif标签
func setExifTag(rootIB *exif.IfdBuilder, ifdPath, tagName, tagValue string) error {
// fmt.Printf("setTag(): ifdPath: %v, tagName: %v, tagValue: %v",
// ifdPath, tagName, tagValue)

ifdIb, err := exif.GetOrCreateIbFromRootIb(rootIB, ifdPath)
if err != nil {
return fmt.Errorf("failed to get or create IB: %v", err)
}

if err := ifdIb.SetStandardWithName(tagName, tagValue); err != nil {
return fmt.Errorf("failed to set DateTime tag: %v", err)
}

return nil
}

func setJpgExif(filePath string, t time.Time) error {

parser := jpeg.NewJpegMediaParser()
Expand Down

0 comments on commit 6710cb7

Please sign in to comment.