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

Strange "bad extract area" error #136

Closed
LeoAdamek opened this issue Mar 10, 2017 · 3 comments
Closed

Strange "bad extract area" error #136

LeoAdamek opened this issue Mar 10, 2017 · 3 comments
Assignees

Comments

@LeoAdamek
Copy link

I'm using bimg to extract areas from images and then resize them, however I get a bad extract area from libvips when trying to perform this operation, which according to the source is thrown when the extra area extends outside the bounds of the image, which after checking the values, is not the case.

Size of the image reported by bimg: {Width:4608 Height:3456}
Options passed to (*bimg.image).Process:

{Height:0 Width:0 AreaHeight:3454 AreaWidth:2592 Top:0 Left:1008 Quality:0 Compression:0 Zoom:0 Crop:false Enlarge:false Embed:false Flip:false Flop:false Force:false NoAutoRotate:false NoProfile:false Interlace:false Extend:0 Rotate:0 Background:{R:0 G:0 B:0} Gravity:0 Watermark:{Width:0 DPI:0 Margin:0 Opacity:0 NoReplicate:false Text: Font: Background:{R:0 G:0 B:0}} Type:0 Interpolator:bicubic Interpretation:0 GaussianBlur:{Sigma:0 MinAmpl:0} Sharpen:{Radius:0 X1:0 Y2:0 Y3:0 M1:0 M2:0}}

Code sample:

if (crop.Y + scaleHeight) > size.Height {
		// Clamp crop so that bottom edge aligns with
		// original image bottom edge.
		crop.Y = size.Height - scaleHeight
	}

	// Top-left boundary checks.
	if crop.X < 0 {
		crop.X = 0
	}

	if crop.Y < 0 {
		crop.Y = 0
	}

	cropOptions := bimg.Options{
		Top:        crop.Y,
		Left:       crop.X,
		AreaWidth:  scaleWidth,
		AreaHeight: scaleHeight,
	}

	// C R O P
	croppedData, err := im.Process(cropOptions)

	if err != nil {
		logrus.WithError(err).WithFields(logrus.Fields{
			"options": cropOptions,
			"size":    size,
		}).Errorln("Unable to crop image")
		return []byte{}, err
	}

Any ideas why I'm getting this error when my values show I'm not asking for any area outside the image?

@LeoAdamek LeoAdamek changed the title Strage "bad extract area" error Strange "bad extract area" error Mar 10, 2017
@LeoAdamek
Copy link
Author

So I've realised now what is actually causing the issue.

Because the (*bimg.Image).Size() function (or rather the associated libvips function) is getting the dimensions from the format-specific file header, it doesn't take into account the possibility of an EXIF orientation flag. However this flag is taken into account when determining if the area specified for an extract operation is valid, and where that area is.

Will look into this further but may submit a PR to add another func which gets the dimensions with the EXIF orientation applied if this resolves the issue.

@h2non
Copy link
Owner

h2non commented Mar 13, 2017

Apologies for the delay, I'm quite busy lately. If you can provide a PR, that would be great. I will take a look asap.

@LeoAdamek
Copy link
Author

See PR #140 which adds this enhancement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants