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
I want to crop an image defined as base64 data. The original uncropped image should later be used to create a File object to be sent via FormData to a third-party service. For this purpose I create two separate Buffer instances from the same base64 string via Buffer.from().
Calling .toBuffer(), .toArray(), or .toFile() on the Sharp instance used for cropping seems to affect the original Buffer in a way that causes an error when sent to the third-party service. The service's responds with a generic error which provides no further insights.
My main question is: How is it possible that two independent buffers are linked? Is it related to buffers created via Buffer.from() being pooled?
I am not even sure if this is a Node.js issue or a Sharp issue. Thanks for your help and for any hint or idea!
When you searched for similar issues, what did you find that might be related?
Searched this issue tracker and Google for "extract changes original buffer", "modified buffer", "Node.js buffer re-used" and all sorts of variations and combinations.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question
constcropImage=(imageBuffer: Buffer,region: ImageRegion)=>{sharp.cache(false)returnsharp(imageBuffer).extract({left: region.x,top: region.y,width: region.width,height: region.height,}).jpeg()// .toBuffer() // => fails; toArray() or toFile() also fails// .then((data) => `data:image/jpeg;base64,${data.toString('base64')}`)}constimageBase64DataString=imageBase64DataUri.replace(/^data:image\/jpeg;base64,/,'')constfirstBuffer=Buffer.from(imageBase64DataString,'base64')constsecondBuffer=Buffer.from(imageBase64DataString,'base64')constregionBase64Uri=awaitcropImage(secondBuffer,region)constfile=newFile([firstBuffer],'image.jpg',{type: 'image/jpeg'})constformData=newFormData()formData.append('file',file,'image.jpg')// third-party API call - fails whenever toBuffer() is used, see aboveconst{ error, fileMetadata }=awaitnhost.storage.upload({formData})
Please provide sample image(s) that help explain this question
Any image. Black 4x4 JPEG I am currently using for testing:
Please provide a complete code sample, without the 3rd party dependency, that allows someone else to reproduce. This will need to include things like a concrete definition of the imageBase64DataUri and region variables as well as some error handling.
Question about an existing feature
What are you trying to achieve?
I want to crop an image defined as base64 data. The original uncropped image should later be used to create a
File
object to be sent viaFormData
to a third-party service. For this purpose I create two separateBuffer
instances from the same base64 string viaBuffer.from()
.Calling
.toBuffer()
,.toArray()
, or.toFile()
on theSharp
instance used for cropping seems to affect the originalBuffer
in a way that causes an error when sent to the third-party service. The service's responds with a generic error which provides no further insights.My main question is: How is it possible that two independent buffers are linked? Is it related to buffers created via
Buffer.from()
being pooled?I am not even sure if this is a Node.js issue or a Sharp issue. Thanks for your help and for any hint or idea!
When you searched for similar issues, what did you find that might be related?
Searched this issue tracker and Google for "extract changes original buffer", "modified buffer", "Node.js buffer re-used" and all sorts of variations and combinations.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this question
Please provide sample image(s) that help explain this question
Any image. Black 4x4 JPEG I am currently using for testing:
The text was updated successfully, but these errors were encountered: