Skip to content

Instantly share code, notes, and snippets.

@romanoffs
Created June 11, 2019 16:24
Show Gist options
  • Save romanoffs/bc481bc9aa4c7b3e9a395b956e80aa01 to your computer and use it in GitHub Desktop.
Save romanoffs/bc481bc9aa4c7b3e9a395b956e80aa01 to your computer and use it in GitHub Desktop.
Resizing images and change image quality in Java with imagemagic
private static boolean resizeImage(final String image_path, final String quality, final String size, final String output_image) {
// absolute path to ImageMagick: Command-line Tools: Convert
String convert_path = "magick";
// Build process to execute convert
ProcessBuilder pb = new ProcessBuilder(
convert_path,
image_path,
"-quality",
quality,
"-resize",
size,
output_image);
pb.redirectErrorStream(true);
try {
Process p = pb.start();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
while ((line = br.readLine()) != null) {
log.info(line);
}
}
catch (Exception e) {
Sentry.capture(e);
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment