zetbaitsu / Compressor

An android image compression library.
7.04k stars 961 forks source link

Requested resolution not set for the photo. #214

Open bipinvaylu opened 9 months ago

bipinvaylu commented 9 months ago

I am using this library to compress and update image resolution. But somehow, the Image doesn't convert to the requested resolution of 1500 x 1500.

Code:

private suspend fun compressImageMedia(image: Image): Either<Exception, Image> {
        return try {
            val sourceFile = File(image.url)
            val destinationFile = File(context.filesDir, sourceFile.name)

            val compressedImageFile = Compressor.compress(context, sourceFile) {
                resolution(1500, 1500)
                destination(destinationFile)
                quality(Constant.projectPhotosQuality)
                format(sourceFile.compressFormat())
            }

            Image(image.index, compressedImageFile.absolutePath).right()
        } catch (e: Exception) {
            Timber.e(e, "Image compression failed")
            e.left()
        }
    }

The actual image resolution is 3000 X 4000. The output image resolution is 1500 X 2000 instead of 1125 X 1500.

Library version: 3.0.1