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

"Error: linear: vector must have 1 or 2 elements" raised when resizing a b&w png image #411

Closed
janaz opened this issue Apr 14, 2016 · 3 comments
Labels
Milestone

Comments

@janaz
Copy link
Contributor

janaz commented Apr 14, 2016

Hi Lovell,

Sharp is failing to resize a png file with the following metadata:

{ format: 'png',
  width: 1653,
  height: 2339,
  space: 'b-w',
  channels: 1,
  density: 200,
  hasProfile: false,
  hasAlpha: false }

To reproduce, please run the following:

var sharp = require('sharp');
var i = sharp('image.png');

i.embed() // works without embed
  .resize(100, 100)
  .background({r:0,g:0,b:0,a:0}) // works with a:1
  .toBuffer(function(err, output, info) {
    if (err) {
      throw err;
    } else {
      console.log("All good")
    }
  });

The error thrown is Error: linear: vector must have 1 or 2 elements

It works when 'embed()' is not used or the alpha channel in the background color is set to 1

I created a repo that showcases the issue and includes the b&w png file: https://github.com/janaz/sharp-png-issue

@lovell
Copy link
Owner

lovell commented Apr 14, 2016

That looks like a bug - the background colour embedding logic has probably never been tested with 1 channel images - I'll take a look.

@lovell lovell added the bug label Apr 14, 2016
@lovell lovell added this to the v0.14.1 milestone Apr 14, 2016
@lovell
Copy link
Owner

lovell commented Apr 14, 2016

Commit e0d5826 adds support for embed with 1 and 2 channel images. Thanks for reporting this!

@lovell
Copy link
Owner

lovell commented Apr 16, 2016

v0.14.1 now available via npm. Please re-open this if it doesn't solve the problem Tomasz.

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

No branches or pull requests

2 participants