A tool for archiving & converting scans of postcards, and information about them.

Parse EXIF from TIFF

Grabs physical dimensions from TIFF files.

+31 -3
+3 -1
formats/web/encode.go
··· 30 30 if pc.Back != nil { 31 31 combinedSize.Max.Y *= 2 32 32 outputImageSize.PxHeight *= 2 33 - outputImageSize.CmHeight = (&big.Rat{}).Mul(outputImageSize.CmHeight, big.NewRat(2, 1)) 33 + if outputImageSize.HasPhysical() { 34 + outputImageSize.CmHeight = (&big.Rat{}).Mul(outputImageSize.CmHeight, big.NewRat(2, 1)) 35 + } 34 36 } 35 37 36 38 combinedImg := image.NewRGBA(combinedSize)
+1
go.mod
··· 7 7 github.com/dsoprea/go-exif/v3 v3.0.0-20210512043655-120bcdb2a55e 8 8 github.com/dsoprea/go-jpeg-image-structure v0.0.0-20221012074422-4f3f7e934102 9 9 github.com/dsoprea/go-png-image-structure v0.0.0-20210512210324-29b889a6093d 10 + github.com/dsoprea/go-tiff-image-structure v0.0.0-20221003165014-8ecc4f52edca 10 11 github.com/spf13/cobra v1.8.1 11 12 github.com/stretchr/testify v1.9.0 12 13 golang.org/x/image v0.0.0-20220902085622-e7cb96979f69
+2 -1
go.sum
··· 20 20 github.com/dsoprea/go-photoshop-info-format v0.0.0-20200609050348-3db9b63b202c/go.mod h1:pqKB+ijp27cEcrHxhXVgUUMlSDRuGJJp1E+20Lj5H0E= 21 21 github.com/dsoprea/go-png-image-structure v0.0.0-20210512210324-29b889a6093d h1:8+qI8ant/vZkNSsbwSjIR6XJfWcDVTg/qx/3pRUUZNA= 22 22 github.com/dsoprea/go-png-image-structure v0.0.0-20210512210324-29b889a6093d/go.mod h1:yTR3tKgyk20phAFg6IE9ulMA5NjEDD2wyx+okRFLVtw= 23 + github.com/dsoprea/go-tiff-image-structure v0.0.0-20221003165014-8ecc4f52edca h1:C0gA/12rFBjBZU+NipamTpthuJaAReN4Ydx63WRqphM= 24 + github.com/dsoprea/go-tiff-image-structure v0.0.0-20221003165014-8ecc4f52edca/go.mod h1:Lro6zqt9pr9yVPwBaM5ijpieYLc4Fy+ObmL5SKP7LrU= 23 25 github.com/dsoprea/go-utility v0.0.0-20200711062821-fab8125e9bdf h1:/w4QxepU4AHh3AuO6/g8y/YIIHH5+aKP3Bj8sg5cqhU= 24 26 github.com/dsoprea/go-utility v0.0.0-20200711062821-fab8125e9bdf/go.mod h1:95+K3z2L0mqsVYd6yveIv1lmtT3tcQQ3dVakPySffW8= 25 27 github.com/dsoprea/go-utility/v2 v2.0.0-20200717064901-2fccff4aa15e h1:IxIbA7VbCNrwumIYjDoMOdf4KOSkMC6NJE4s8oRbE7E= ··· 43 45 github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= 44 46 github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 45 47 github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 46 - github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= 47 48 github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= 48 49 github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 49 50 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+2 -1
internal/resolution/resolution.go
··· 12 12 {[]byte(pngHeader), decodePNG}, 13 13 {[]byte("\xff\xd8"), decodeJPEG}, 14 14 {[]byte("RIFF????WEBPVP8"), decodeWebP}, 15 - // TODO: tiff 15 + {[]byte{0x4D, 0x4D, 0x00, 0x2A}, decodeTIFF}, 16 + {[]byte{0x49, 0x49, 0x2A, 0x00}, decodeTIFF}, 16 17 } 17 18 18 19 // Decode returns the resolution (number of pixels per centimetre) an image declares it is stored with
+23
internal/resolution/tif.go
··· 1 + package resolution 2 + 3 + import ( 4 + "math/big" 5 + 6 + tiffstructure "github.com/dsoprea/go-tiff-image-structure" 7 + ) 8 + 9 + func decodeTIFF(data []byte) (*big.Rat, *big.Rat, error) { 10 + jmp := tiffstructure.NewTiffMediaParser() 11 + 12 + mc, err := jmp.ParseBytes(data) 13 + if err != nil { 14 + return nil, nil, err 15 + } 16 + 17 + _, exifData, err := mc.Exif() 18 + if err != nil { 19 + return nil, nil, err 20 + } 21 + 22 + return decodeExif(exifData) 23 + }