I am testing sharp (so far installing was a breeze!).
I am trying the simplest code. I simply execute it from node interactive CLI (pretty much copy paste from the docs):
function resizeFileSharp(path) {
sharp(path).resize(600).toFile(path + "_copy.png", function(err) {
if (err) throw err;
// output.jpg is a 300 pixels wide and 200 pixels high image
// containing a scaled and cropped version of input.jpg
console.log("image resized");
});
}
var filePath = "path/to/some/file";
resizeFileSharp(filePath);
node version is v0.10.26
npm version is 1.4.3
sharp installed version is 0.14.1
Following that, I see the re-sized image etc but I cannot delete the original one - when I do so I get a windows warning:
The action can't be completed because the file is open in Evented I/O for V8 JavaScript
If I terminate the node process (Ctrl+C twice) the file is released.
Am I doing something wrong? Why would the file stay opened?
Thanks,
Tomer
Hello, input files can be kept open by libvips' file cache. You can use sharp.cache(false) to prevent this - see http://sharp.pixelplumbing.com/en/stable/api-utility/#cache
@lovell
First, thanks for quick answer!
Next, again, this library seems really great (or is, from what I used so far). I really loved having the dependencies packed with it so installation is straight forward and simple.
Lastly, in case I leave cache on, it's possible that the image will stay locked "indefinitely"? Can you elaborate what are the consequences of disabling cache?
Thanks!
Tomer
Another small question. Would re-sizing keep the orientation tag (exif:orientation) of the image? It seems not to :-(
Can you elaborate what are the consequences of disabling cache?
Possibly lower performance some of the time, but it depends. Profile your code to find out :)
Would re-sizing keep the orientation tag (exif:orientation) of the image?
If you've not already seen it, withMetadata is your friend here.
I should read more carefully... thanks again!
Most helpful comment
Hello, input files can be kept open by libvips' file cache. You can use
sharp.cache(false)to prevent this - see http://sharp.pixelplumbing.com/en/stable/api-utility/#cache