evanoberholster / imagemeta

Image Metadata (Exif and XMP) extraction for JPEG, HEIC, AVIF, TIFF and Camera Raw in golang. Focus is on providing features and improved performance.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

convert cr2 -> jpg

kmulvey opened this issue · comments

I know that this might not be exactly what this library is intended to do, but i just wanted to know if i've wandered too far off the path or should this work?

package main

import (
	"fmt"
	"image/jpeg"
	"os"

	"github.com/evanoberholster/imagemeta"
)

const imageFilename = "~/Alpaca/IMG_6179.CR2"

func main() {
	var err error

	f, err := os.Open(imageFilename)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	m, err := imagemeta.Parse(f)
	if err != nil {
		panic(err)
	}
	fmt.Println(m.Exif())
	fmt.Println(m.Xmp())
	fmt.Println(m.ImageType())
	fmt.Println(m.Dimensions())
	img, err := jpeg.Decode(m.PreviewImage())  // panic happens here
	if err != nil {
		panic(err)
	}

	out, err := os.Create("./out.jpg")
	if err != nil {
		panic(err)
	}
	defer out.Close()

	err = jpeg.Encode(out, img, &jpeg.Options{Quality: 90})
	if err != nil {
		panic(err)
	}
}
&{0xc000134000 map[16777472:{5472 1 256 3 1} 16777473:{3648 1 257 3 1} 16777474:{238 3 258 3 1} 16777475:{6 1 259 3 1} 16777487:{244 6 271 2 1} 16777488:{250 13 272 2 1} 16777489:{96900 1 273 4 1} 16777490:{1 1 274 3 1} 16777495:{1667194 1 279 4 1} 16777498:{282 1 282 5 1} 16777499:{290 1 283 5 1} 16777512:{2 1 296 3 1} 16777522:{298 20 306 2 1} 16777531:{318 13 315 2 1} 16777916:{71876 8192 700 1 1} 16810648:{382 13 33432 2 1} 16843265:{80068 1 513 4 1} 16843266:{16832 1 514 4 1} 16908544:{464 1 256 3 1} 16908545:{309 1 257 3 1} 16908546:{71734 3 258 3 1} 16908547:{1 1 259 3 1} 16908550:{2 1 262 3 1} 16908561:{1764096 1 273 4 1} 16908565:{3 1 277 3 1} 16908566:{309 1 278 3 1} 16908567:{860256 1 279 4 1} 16908572:{1 1 284 3 1} 16958937:{2 1 50649 4 1} 16959173:{3 1 50885 4 1} 16959196:{71740 4 50908 4 1} 16974080:{5568 1 256 3 1} 16974081:{3708 1 257 3 1} 16974083:{6 1 259 3 1} 16974097:{2624352 1 273 4 1} 16974103:{21736030 1 279 4 1} 17024472:{1 1 50648 4 1} 17024480:{1 1 50656 4 1} 17024576:{71870 3 50752 3 1} 17024709:{1 1 50885 4 1} 50365082:{908 1 33434 5 3} 50365085:{916 1 33437 5 3} 50366498:{2 1 34850 3 3} 50366503:{800 1 34855 3 3} 50366512:{2 1 34864 3 3} 50366514:{800 1 34866 4 3} 50368512:{808661552 4 36864 7 3} 50368515:{924 20 36867 2 3} 50368516:{944 20 36868 2 3} 50368769:{197121 4 37121 7 3} 50369025:{964 1 37377 10 3} 50369026:{972 1 37378 5 3} 50369028:{980 1 37380 10 3} 50369031:{2 1 37383 3 3} 50369033:{16 1 37385 3 3} 50369034:{988 1 37386 5 3} 50369158:{69256 264 37510 7 3} 50369168:{12336 3 37520 2 3} 50369169:{12336 3 37521 2 3} 50369170:{12336 3 37522 2 3} 50372608:{808464688 4 40960 7 3} 50372609:{1 1 40961 3 3} 50372610:{5472 1 40962 3 3} 50372611:{3648 1 40963 3 3} 50372613:{69520 1 40965 4 3} 50373134:{69550 1 41486 5 3} 50373135:{69558 1 41487 5 3} 50373136:{2 1 41488 3 3} 50373633:{0 1 41985 3 3} 50373634:{0 1 41986 3 3} 50373635:{0 1 41987 3 3} 50373638:{0 1 41990 3 3} 50373680:{69566 13 42032 2 3} 50373681:{69598 13 42033 2 3} 50373682:{69630 4 42034 5 3} 50373684:{69662 29 42036 2 3} 50373685:{69736 11 42037 2 3} 67108864:{770 4 0 1 4} 67108865:{78 2 1 2 4} 67108866:{70126 3 2 5 4} 67108867:{87 2 3 2 4} 67108868:{70150 3 4 5 4} 67108869:{0 1 5 1 4} 67108870:{70174 1 6 5 4} 67108871:{70182 3 7 5 4} 67108872:{12849 3 8 2 4} 67108873:{65 2 9 2 4} 67108874:{51 2 10 2 4} 67108875:{70666 1 11 5 4} 67108882:{70698 7 18 2 4} 67108893:{71530 11 29 2 4} 100663297:{1506 49 1 3 6} 100663298:{1604 4 2 3 6} 100663299:{1612 4 3 3 6} 100663300:{1620 34 4 3 6} 100663302:{1688 13 6 2 6} 100663303:{1720 24 7 2 6} 100663305:{1744 32 9 2 6} 100663309:{1776 1536 13 7 6} 100663312:{2147484418 1 16 4 6} 100663315:{3312 4 19 3 6} 100663321:{1 1 25 3 6} 100663334:{3320 56 38 3 6} 100663349:{3432 4 53 4 6} 100663443:{3448 44 147 3 6} 100663445:{3536 74 149 2 6} 100663446:{3610 16 150 2 6} 100663447:{3626 1024 151 7 6} 100663448:{4650 4 152 3 6} 100663449:{4658 106 153 4 6} 100663450:{5082 5 154 4 6} 100663456:{5102 14 160 3 6} 100663466:{5130 6 170 3 6} 100663476:{1 1 180 3 6} 100663504:{0 1 208 4 6} 100663520:{5142 17 224 3 6} 100679681:{5176 1313 16385 3 6} 100679682:{7802 43636 16386 7 6} 100679685:{51438 16792 16389 7 6} 100679688:{68230 3 16392 3 6} 100679689:{68236 3 16393 3 6} 100679696:{68242 32 16400 2 6} 100679697:{68274 252 16401 7 6} 100679698:{68526 32 16402 2 6} 100679699:{68558 11 16403 4 6} 100679701:{68602 456 16405 7 6} 100679702:{69058 7 16406 4 6} 100679704:{69086 7 16408 4 6} 100679705:{69114 30 16409 7 6} 100679712:{69144 7 16416 4 6} 100679713:{69172 5 16417 4 6} 100679717:{69192 9 16421 4 6} 100679719:{69228 5 16423 4 6}] Canon Canon EOS 6D 5472 3648 230 16} <nil>
{{   0  0  0/0 } { 0 0 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0 Not Defined Auto 0/0 0 {false 0 false false 0} Unknown 0 0.00mm 0 0 0 0 0001-01-01 00:00:00 +0000 UTC} {   [] [] 0 0 Unknown} {0001-01-01 00:00:00 +0000 UTC   0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC 0} {[]  [] 0001-01-01 00:00:00 +0000 UTC [] application/octet-stream  [] []  [] [] []} {} {00000000-0000-0000-0000-000000000000 00000000-0000-0000-0000-000000000000 00000000-0000-0000-0000-000000000000 [] }} xmp: error no XMP Tag found
image/x-canon-cr2
width: 5472, height: 3648
panic: invalid JPEG format: missing SOI marker

goroutine 1 [running]:
main.main()
	main.go:32 +0x509
exit status 2

img.zip

Did you get it working?