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
{{ message }}
Repository navigation
Enhancement: create blank/empty image of given dimensions/channels #470
Reacted by Anton Istomin, Lorenzo Ponticelli, Jamie Chapman, Param Aggarwal, ryan neptune, Owen Bodley, Florian, James, Grimitsu, prathap937 and 2 more
@lovell, sorry for the late reply. Yes your code seems to do what I was looking for, although I agree with @strarsis that a helper function would be nicer.
The forthcoming v0.16.0 release moves all image input logic to a common location, namely the _createInputDescriptor function in JavaScript then CreateInputDescriptor method in C++.
This is the best place to add such a "create image" helper, so any part of the API that can handle input images will be able to use it.
To combine multiple images, I did this instead of the empty canvas:
for(leti=1,left=singleWidth;i<imgCount;i++,left+=singleWidth){// only one overlay per pipelineif(i>1){combined=sharp(awaitcombined.toBuffer())}combined.overlayWith(imgBufs[i],{left,top: 0})}
so basically forcing sharp to process the pipeline once there is more than one overlay. Async/await makes this nice, with promises this code would be a bit harder.
(incidentally, I wonder if there would be a use for a .perform() call that runs the pipeline and starts a new one?)
Activity
lovell commentedon Jun 20, 2016
Are you able to provide more information about the problem you're trying to solve? What do you mean by "canvas" in this context?
pjarts commentedon Jun 21, 2016
The lwip node module has a method called "create" (https://github.com/EyalAr/lwip#create-a-new-image) that creates an empty image. I was wondering if it is possible to accomplish the same thing in sharp, or if I always have to start off from an existing image file.
lovell commentedon Jun 21, 2016
You could use a raw pixel input buffer for this, something like this (ES2015) example:
lovell commentedon Jul 11, 2016
@pjarts Were you able to make any progress with this?
strarsis commentedon Jul 13, 2016
Would a little helper function ("create(...)"?) in sharp make sense,
like one that uses the canvas code above?
pjarts commentedon Jul 15, 2016
@lovell, sorry for the late reply. Yes your code seems to do what I was looking for, although I agree with @strarsis that a helper function would be nicer.
lovell commentedon Jul 16, 2016
@pjarts Thanks for confirming.
Let's leave this issue open to track adding such a helper - I'll need to have a think about what the API might look like.
[-]Create empty canvas [/-][+]Enhancement: create blank/empty image of given dimensions/channels[/+]strarsis commentedon Jul 16, 2016
A kind of factory/'static' method:
With configuration object passed:
Like 2. but directly with 'constructor' method:
With no arguments passed at all - using resize to achieve the desired dimensions:
Like 3. but using an empty dummy image from constant (not very elegant imho
because of dummy image and even artifacts that may be caused):
lovell commentedon Aug 13, 2016
The forthcoming v0.16.0 release moves all image input logic to a common location, namely the _createInputDescriptor function in JavaScript then CreateInputDescriptor method in C++.
This is the best place to add such a "create image" helper, so any part of the API that can handle input images will be able to use it.
Here's how the API could work:
where
rgbandrgbaare parsed by thecolormodule, the same approach used by the existing background function.strarsis commentedon Sep 14, 2016
[email protected] doesn't seem to support it yet.
lovell commentedon Sep 14, 2016
@strarsis That's correct. My comment about v0.16.0 was that it provided the ground work for this feature request.
5im0n commentedon Jan 13, 2017
Is this feature gonna be available in a next release ?
lovell commentedon Jan 13, 2017
@5im0n I'm happy to help with a PR if you're able.
Create blank image (width, height, channels, background) #470
lovell commentedon Mar 11, 2017
Commit 1aa053c adds the ability to create a blank image using the API described by comment #470 (comment) above. This will be available in v0.17.3.
lovell commentedon Apr 1, 2017
v0.17.3 now available, thanks for all the suggestions.
wmertens commentedon Apr 23, 2017
To combine multiple images, I did this instead of the empty canvas:
so basically forcing sharp to process the pipeline once there is more than one overlay. Async/await makes this nice, with promises this code would be a bit harder.
(incidentally, I wonder if there would be a use for a
.perform()call that runs the pipeline and starts a new one?)