php-vips
php-vips copied to clipboard
Some PNG images donesn't work with embed.
require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;
use Jcupitt\Vips\Extend;
$target_width = 200;
$target_height = 200;
$bufferData = file_get_contents('./4942896.png');
$image = Vips\Image::thumbnail_buffer($bufferData, $target_width, [
'height' => $target_height
]);
$x = ($target_width - $image->width) / 2;
$y = ($target_height - $image->height) / 2;
$image = $image->embed($x, $y, $target_width, $target_height, [
'extend' => Extend::BACKGROUND,
'background' => [255, 255, 255, 0.0]
]);
$buffer = $image->writeToBuffer('.png', []);
header("Content-Type: image/png");
echo $buffer;
linear: vector must have 1 or 3 elements.

Hi @Sud4,
Your PNG doesn't have an alpha channel, so you only need a three-element array for the background.
Try:
'background' => [255, 255, 255]
You can also just use a single number, ie.
'background' => 255
Now it'll work for any PNG image.
it's works, Can i do 'background' => 0 to make extended background transparent.
Sure, should work. Though your PNG doesn't have an alpha channel, of course, you'd need to add one.
it's works just perfect, Thank You!.