You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I could be missing something in docs, but i did not found how best to do such task.
I am trying at the end of pipeline to convert my image to rgba, if it is not (to use with ImageData and show in canvas).
So i literally copy pixel values depending number of channels (i do not make any color space conversion) in .toBuffer to produce new raw pixel values. Maybe there is a better way to do this?
Also could you please correct me if i wrong, i assume 1 channel it is grayscale image, 2 channels it is grayscale + alpha, 3 channels it is rgb and 4 it what i need rgba.
Hello, forcing the addition of an alpha channel is not directly available via the existing API, but you could do something like the following (untested) which by extending 0 pixels using a fully transparent background should force your image to RGBA:
I also would like to know also if it is possible to add own interpolator and reduction kernel. I have pretty specific usecase (pixel art) and generally good resampling methods not always suite there.
Activity
lovell commentedon Jan 12, 2017
Hello, forcing the addition of an alpha channel is not directly available via the existing API, but you could do something like the following (untested) which by extending 0 pixels using a fully transparent background should force your image to RGBA:
btd commentedon Jan 13, 2017
Thanks for answering.
Nope, this does not work. I tried with usual jpg file with 3 channels, and it still remains with 3 channels.
lovell commentedon Jan 13, 2017
Ah, sorry, there's a
> 0check that prevents this approach. https://github.com/lovell/sharp/blob/master/src/pipeline.cc#L520 (I will update the parameter validation in the JavaScript to match the C++ logic).If you know the dimensions you could use an embedding resize:
btd commentedon Jan 13, 2017
Nope this still does not work. With the same jpg file i have tried:
btd commentedon Jan 13, 2017
I also would like to know also if it is possible to add own interpolator and reduction kernel. I have pretty specific usecase (pixel art) and generally good resampling methods not always suite there.
lovell commentedon Jan 15, 2017
Sorry, I'm not doing very well here. Third time lucky...
For RGB input of known dimensions, the joinChannel operation with a zero-filled Buffer will add a fully-transparent alpha channel.
Modify the value of
alphaBuffer to change the transparency, e.g.Buffer.alloc(width * height, 255)for fully-opaque.btd commentedon Jan 16, 2017
Thanks, will try to use it for most common case.