public static byte[] compress(final byte[] bytes) throws ImagingException {
        final ByteArrayOutputStream out = new ByteArrayOutputStream(Allocator.checkByteArray(bytes.length / 2));
        try (DeflaterOutputStream compressOut = new DeflaterOutputStream(out)) {
            compressOut.write(bytes);
        } catch (final IOException e) {
            throw new ImagingException("Unable to compress image", e);
        }
        return out.toByteArray();
    }
Compress the byte[] using ZLIB deflate compression.

@param bytes The bytes to compress
@return The compressed bytes.
@throws ImagingException if the bytes could not be compressed.
@see DeflaterOutputStream
src/main/java/org/apache/commons/imaging/common/ZlibDeflate.java