novitai / skycompress

Compress the image with binary search algorithm to find best fit dimension and quality
1 stars 0 forks source link

Skycompress

This module provides a function to compress images to a desired byte size using OpenCV.

Sky is the limit.

Dependencies

Usage

The primary function in this module is compress_image(), which compresses an image to the desired byte size.

Parameters:

Returns:

Example:


import cv2
import numpy as np

from skycompress import compress_image

# Load the image
img = cv2.imread("path_to_your_image.jpg")

# Compress the image
compressed_img_data = compress_image(img, 15000)  # Compress to 15000 bytes in RGB format

# Save the compressed image
with open("compressed_image.jpg", "wb") as f:
    f.write(compressed_img_data)