Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@eslam-mahmoud
Copy link
Contributor

@eslam-mahmoud eslam-mahmoud commented Nov 15, 2019

Orignal issue is
Having an extra border on the right and bottom side of images

Root cause comes from
https://libvips.github.io/libvips/API/current/libvips-resample.html#vips-resize

When upsizing (scale > 1), the operation uses vips_affine() with a VipsInterpolate selected depending on kernel . It will use VipsInterpolateBicubic for VIPS_KERNEL_CUBIC and above. It adds a 0.5 pixel displacement to the input pixels to get center convention scaling.

The fix
Enable vipsAffine to use Extend option value and send it to lipvips
This will change the default from the one that libvips use which is background to the ones that bimg use which is C.VIPS_EXTEND_BLACK
But because the lip add extra 1 or .5 pixel the background is considered black anyway so this will not affect anyone but will fix the bug of having a border on the right and bottom of some images

Creating 100x100 white jpg reproduced the issue if it is scaled even to 101x101 with these options

bimg.Options{
		Width:         width,
		Height:        height,
		Embed:         false,
		NoProfile:     true,
		StripMetadata: true,
		Quality:       100,
	}

now adding this make it works

		Extend:        bimg.ExtendCopy

100x100
white

500x500
whie-with-border

Note the more you scale the image up the darker and thicker the boarder gets

this will change the default from the one that lipvips use which is `background` to the ones that bimg use which is  `C.VIPS_EXTEND_BLACK`
but because the lip add extra 1 or .5 pix the background is considered black anyway so this will not affect anyone
but will fix the bug of having border on the right and bottom of some images

[ch15924]
@MDrollette MDrollette force-pushed the eslam/ch15924/some-product-images-have-a-border branch from a7a23c8 to cd2783e Compare April 16, 2020 17:43
@h2non h2non merged commit 7884549 into h2non:master Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants