bimg icon indicating copy to clipboard operation
bimg copied to clipboard

Basic cropping fails when image has EXIF orientation

Open felixveysseyre opened this issue 3 years ago • 1 comments

Hello,

Trying to crop into an oriented image, I got the following error: extract_area: bad extract area

See the complete reproduction repository here.

package main

import (
	"fmt"
	"github.com/h2non/bimg"
	"io/ioutil"
	"os"
	"path"
)

func main()  {
	cD, _ := os.Getwd()
	fP := path.Join(cD, "data/Landscape_6.jpg")
	fB, _ := ioutil.ReadFile(fP)
	bI := bimg.NewImage(fB)
	iS, _ := bI.Size()
	iM, _ := bI.Metadata()

	fmt.Printf("Image size: %+v\n", iS) // 1200 x 1800
	fmt.Printf("Image orientation: %+v\n", iM.EXIF.Orientation) // 6

	options := bimg.Options{
		Top: 0,
		Left: 0,
		AreaWidth: 1000,
		AreaHeight: 1800,
	}

	_, err := bI.Process(options)

	fmt.Printf("Error: %+v\n", err) // extract_area: bad extract area
}

Despite that bimg returns (width, height) = (1200, 1800) as image size, it seems to consider the orientation when trying to crop it.

When inverting AreaWidth and AreaHeight values, no error is thrown.

felixveysseyre avatar Dec 17 '20 12:12 felixveysseyre

Were you able to find a solution to this?

Destaq avatar Oct 09 '23 02:10 Destaq