question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable overwriting input file

See original GitHub issue
sharp('file.jpg').resize(100, 100).write('file.jpg', function(err) {
    console.log(err)l;
});

Gives:

VipsJpeg: Empty input file
vips__region_start: start function failed for image temp-1
VipsRegion: valid clipped to nothing
VipsRegion: valid clipped to nothing
VipsRegion: valid clipped to nothing

Any chance to implement file overwriting?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

32reactions
gzurbachcommented, Aug 24, 2020

In case it helps anyone, I ended up using the following approach to resize my files before uploading them to S3. I didn’t want to end up with a new filename. It seems to be working 👍

const sharp = require("sharp");
sharp.cache(false);

async function resizeFile(path) {
  let buffer = await sharp(path)
    .resize(2000, 2000, {
      fit: sharp.fit.inside,
      withoutEnlargement: true,
    })
    .toBuffer();
  return sharp(buffer).toFile(path);
}
9reactions
matyllacommented, May 22, 2014

Sorry, writing buffer to the same file works:

sharp('file.jpg').resize(100, 100).toBuffer(function(err, buffer) {
    fs.writeFile('file.jpg', buffer, function(e) {

    });
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Solved: overwrite input file - Designer
Solved: I am reading three files to combine and the output of today's will be used as the input next day. so when...
Read more >
Typescript error "Cannot write file ... because it would ...
Cannot write file 'C:/{{my-project}}/node_modules/buffer-shims/index.js' because it would overwrite input file. It looks like this all the time.
Read more >
read write - Overwriting an input file
Another common option is >>file , "append" mode, which skips the step where the file is emptied, but puts all output at the...
Read more >
How to Overwrite Input File in Awk
Sometimes you may need to save awk modifications in place. Here is how to overwrite input file in awk command.
Read more >
Overwrite file when creating a file in SharePoint
Turning "Allow chunking" OFF in the Create File settings worked for me. EnriqueC_0-1602018799274.png. Message 9 of 35. 51,675 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found