hkk595 / Resizer

An image resizing library for Android
MIT License
432 stars 69 forks source link

Simply doesn't work #10

Open jifferon opened 5 years ago

jifferon commented 5 years ago

Here's a module for compressor

@Module
class CompressorModule {
    @Provides
    @Singleton
    fun provideCompressor(context: Context) = Resizer(context)
            .setTargetLength(1000)
            .setQuality(75)
            .setOutputFormat("JPEG")
            .setOutputFilename(UUID.randomUUID().toString())
            .setOutputDirPath(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!.absolutePath)
}

And here's how we use it:

 override fun uploadImage(file: File): Single<Image> =
            file.run {
                System.out.println("Pre compressor size: ${file.totalSpace}")
                resizer
                        .setSourceImage(file)
                        .resizedFileAsFlowable
                        .subscribeOn(Schedulers.io())
                        .singleOrError()
                        .flatMap { compressedFile ->
                            System.out.println("Post compressor size: ${compressedFile.totalSpace}")
                            Single.fromCallable {
                                defaultApi.v2ImagesPost(compressedFile)
                            }
                        }
            }

And here's result of compression:

I/System.out: Pre compressor size: 57986539520
I/System.out: Post compressor size: 57986539520

Thus, nothing has changed: not size, not file resolution (which is twice the size specified). What are we doing wrong?

jifferon commented 5 years ago

My bad, my way of determination of file size was totally wrong. Still, image dimensions won't change