Class FastImageUtils


  • public class FastImageUtils
    extends java.lang.Object
    Fast Image Compression Utilities with Cross-Platform Support This utility class handles automatic loading of native libraries for different operating systems and architectures. Supports: - Windows x64 (.dll) - Linux x64 (.so) - macOS Intel x64 (.dylib) - macOS Apple Silicon ARM64 (.dylib) Usage:
     // Compress an image with 70% quality
     byte[] imageData = Files.readAllBytes(Paths.get("image.jpg"));
     byte[] compressed = FastImageUtils.compress(imageData, 70);
     
    • Constructor Summary

      Constructors 
      Constructor Description
      FastImageUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] compress​(byte[] imageBytes, int quality)
      Compress image data with automatic format detection and quality control This method automatically detects whether the input is PNG or JPEG format and applies the appropriate compression algorithm.
      static byte[] compressHigh​(byte[] imageBytes)
      Compress image with high quality (quality = 90) Output format will be the same as input format.
      static byte[] compressLow​(byte[] imageBytes)
      Compress image with low quality for maximum compression (quality = 30) Output format will be the same as input format.
      static byte[] compressMedium​(byte[] imageBytes)
      Compress image with medium quality (quality = 60) Output format will be the same as input format.
      static java.lang.String getPlatformInfo()
      Get information about the current platform and loaded library
      static boolean testLibrary()
      Test if the native library is working correctly
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FastImageUtils

        public FastImageUtils()
    • Method Detail

      • compress

        public static byte[] compress​(byte[] imageBytes,
                                      int quality)
        Compress image data with automatic format detection and quality control This method automatically detects whether the input is PNG or JPEG format and applies the appropriate compression algorithm. The output format will be the same as the input format (PNG input -> PNG output, JPEG input -> JPEG output).
        Parameters:
        imageBytes - Input image data as byte array (PNG or JPEG format)
        quality - Compression quality (0-100, where 0 is highest compression, 100 is best quality)
        Returns:
        Compressed image data as byte array in the same format as input
        Throws:
        java.lang.IllegalArgumentException - if quality is not in range 0-100 or data is empty
        java.lang.RuntimeException - if compression fails or image format is unsupported
      • compressHigh

        public static byte[] compressHigh​(byte[] imageBytes)
        Compress image with high quality (quality = 90) Output format will be the same as input format.
        Parameters:
        imageBytes - Input image data (PNG or JPEG format)
        Returns:
        Compressed image data in the same format as input
      • compressMedium

        public static byte[] compressMedium​(byte[] imageBytes)
        Compress image with medium quality (quality = 60) Output format will be the same as input format.
        Parameters:
        imageBytes - Input image data (PNG or JPEG format)
        Returns:
        Compressed image data in the same format as input
      • compressLow

        public static byte[] compressLow​(byte[] imageBytes)
        Compress image with low quality for maximum compression (quality = 30) Output format will be the same as input format.
        Parameters:
        imageBytes - Input image data (PNG or JPEG format)
        Returns:
        Compressed image data in the same format as input
      • getPlatformInfo

        public static java.lang.String getPlatformInfo()
        Get information about the current platform and loaded library
        Returns:
        Platform information string
      • testLibrary

        public static boolean testLibrary()
        Test if the native library is working correctly
        Returns:
        true if library is working, false otherwise