int croppedHeight = (int) (scaledHeight - Math.max(cropY, 0.0f));
// Do the cropping
IMOperation cropOperation = new IMOperation();
cropOperation.addImage(scaledFile.getAbsolutePath());
cropOperation.crop(croppedWidth, croppedHeight, croppedLeft, croppedTop);
cropOperation.p_repage(); // Reset the page canvas and position to match
// the actual cropped image
cropOperation.addImage(croppedFile.getAbsolutePath());
imageMagick.run(cropOperation);
finalFile = croppedFile;