I am using python to compress an image to varying degrees ( or quality ) . I have implemented it based on OpenCV:
def compressAndwrite(save_path, img, quality):
'''
save_path: string
img: np.ndarray
quality: int, 0-100
'''
cv2.imwrite(save_path, img, [int(cv2.IMWRITE_JPEG_QUALITY), quality])
Is there any way that I can use libjpeg
in python to achieve the same effect instead of PIL
or OpenCV
?
If not, how can I compress and write an jpeg image using JPEG algorithm when given a parameter quality
?