Created
June 11, 2019 16:24
-
-
Save romanoffs/bc481bc9aa4c7b3e9a395b956e80aa01 to your computer and use it in GitHub Desktop.
Resizing images and change image quality in Java with imagemagic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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