Reputation: 9063
I'm resizing an image using Graphics Magick and then using a loop to do multiple crops on that image. The second time the crop command runs, it fails with: Command failed: gm convert: geometry does not contain image (unable to crop image).
Here's my loop code:
var resizedImage = gm(pathToTemporaryImage).resize(maxSize, maxSize);
resizedImage.size(function(error, size) {
for (var x = 0; x < size.width; x += kGridSize) {
for (var y = 0; y < size.height; y += kGridSize) {
// Calculate the grid element width and height
var width = Math.min(kGridSize, size.width - x);
var height = Math.min(kGridSize, size.height - y);
resizedImage.page(0, 0, '+0+0')
.crop(width, height, x, y)
.quality(Math.min(frameTick.quality, 100))
.write(pathToImage + '-' + x + '-' + y + '.jpg', callback(x, y));
}
}
}
Upvotes: 1
Views: 3160
Reputation: 9063
Instead of caching resizedImage
, I wrote the image to disk after resizing and loaded it back up before cropping and re-writing.
Removed the reference to .page(0, 0, '+0+0')
, that being the case.
Upvotes: 1