Skip to content

Commit

Permalink
Merge pull request #106 from Dhaval2404/feature/v1.7.4
Browse files Browse the repository at this point in the history
Fixed PNG image saved as JPG after compress issue
  • Loading branch information
Dhaval2404 authored Aug 2, 2020
2 parents d4c5842 + 422a949 commit d91f460
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [1.7.4] - 2020-08-02
### Changed
* Fixed PNG image saved as JPG after compress issue [#105](https://github.com/Dhaval2404/ImagePicker/issues/105)

## [1.7.3] - 2020-07-18
### Changed
Expand Down Expand Up @@ -73,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Retrieve Image Result as File, File Path as String or Uri object

[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v2.0...HEAD
[1.7.4]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.3...v1.7.4
[1.7.3]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.2...v1.7.3
[1.7.2]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.1...v1.7.2
[1.7.1]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7...v1.7.1
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
```

```groovy
implementation 'com.github.dhaval2404:imagepicker:1.7.3'
implementation 'com.github.dhaval2404:imagepicker:1.7.4'
```

**If you are yet to Migrate on AndroidX, Use support build artifact:**
Expand Down Expand Up @@ -116,10 +116,10 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
imgProfile.setImageURI(fileUri)
//You can get File object from intent
val file:File = ImagePicker.getFile(data)
val file:File = ImagePicker.getFile(data)!!
//You can also get File Path from intent
val filePath:String = ImagePicker.getFilePath(data)
val filePath:String = ImagePicker.getFilePath(data)!!
} else if (resultCode == ImagePicker.RESULT_ERROR) {
Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
} else {
Expand Down Expand Up @@ -276,6 +276,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
* Fixed NullPointerException in FileUriUtils.getPathFromRemoteUri() [#61](https://github.com/Dhaval2404/ImagePicker/issues/61) (Special Thanks to [himphen](https://github.com/himphen))
* Fixed UCropActivity Crash Android 4.4 (KiKat) [#82](https://github.com/Dhaval2404/ImagePicker/issues/82)
* Fixed PNG image saved as JPG after crop issue [#94](https://github.com/Dhaval2404/ImagePicker/issues/94)
* Fixed PNG image saved as JPG after compress issue [#105](https://github.com/Dhaval2404/ImagePicker/issues/105)
### Version: 1.6
Expand Down
6 changes: 3 additions & 3 deletions imagepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 11
versionName "1.7.3"
versionCode 12
versionName "1.7.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -72,7 +72,7 @@ ext {
siteUrl = 'https://github.com/Dhaval2404/ImagePicker/'
gitUrl = 'https://github.com/Dhaval2404/ImagePicker.git'

libraryVersion = '1.7.3'
libraryVersion = '1.7.4'
//If you are uploading new library try : gradlew install
//If you are updating existing library then execute: gradlew bintrayUpload
//In both the case don't forgot to put bintray credentials in local.properties file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.graphics.BitmapFactory
import android.os.AsyncTask
import com.github.dhaval2404.imagepicker.ImagePicker
import com.github.dhaval2404.imagepicker.ImagePickerActivity
import com.github.dhaval2404.imagepicker.util.FileUriUtils
import com.github.dhaval2404.imagepicker.util.FileUtil
import com.github.dhaval2404.imagepicker.util.ImageUtil
import java.io.File
Expand Down Expand Up @@ -169,13 +170,14 @@ class CompressionProvider(activity: ImagePickerActivity) : BaseProvider(activity

// Check file format
var format = Bitmap.CompressFormat.JPEG
var quality = 90
var quality = 100
if (file.absolutePath.endsWith(".png")) {
format = Bitmap.CompressFormat.PNG
quality = 100
}

val compressFile: File? = FileUtil.getImageFile(dir = mFileDir)
val extension = FileUriUtils.getImageExtension(file)
val compressFile: File? = FileUtil.getImageFile(dir = mFileDir, extension = extension)
return if (compressFile != null) {
ImageUtil.compressImage(
file, maxWidth.toFloat(), maxHeight.toFloat(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ object FileUriUtils {
return if (success) file!!.path else null
}

/** @return extension of image with dot, or default .jpg if it none.
/**
* Get Image Extension i.e. .png, .jpg
*
* @return extension of image with dot, or default .jpg if it none.
*/
fun getImageExtension(uriImage: Uri): String {
var extension: String? = null
Expand All @@ -202,6 +205,15 @@ object FileUriUtils {
return ".$extension"
}

/**
* Get Image Extension i.e. .png, .jpg
*
* @return extension of image with dot, or default .jpg if it none.
*/
fun getImageExtension(file: File): String {
return getImageExtension(Uri.fromFile(file))
}

/**
* @param uri The Uri to check.
* @return Whether the Uri authority is ExternalStorageProvider.
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "com.github.dhaval2404.imagepicker.sample"
minSdkVersion 19
targetSdkVersion 28
versionCode 11
versionName "1.7.3"
versionCode 12
versionName "1.7.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down

0 comments on commit d91f460

Please sign in to comment.