Skip to content

Commit d91f460

Browse files
authored
Merge pull request #106 from Dhaval2404/feature/v1.7.4
Fixed PNG image saved as JPG after compress issue
2 parents d4c5842 + 422a949 commit d91f460

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

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

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

7578
[Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v2.0...HEAD
79+
[1.7.4]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.3...v1.7.4
7680
[1.7.3]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.2...v1.7.3
7781
[1.7.2]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.1...v1.7.2
7882
[1.7.1]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7...v1.7.1

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
5454
```
5555

5656
```groovy
57-
implementation 'com.github.dhaval2404:imagepicker:1.7.3'
57+
implementation 'com.github.dhaval2404:imagepicker:1.7.4'
5858
```
5959

6060
**If you are yet to Migrate on AndroidX, Use support build artifact:**
@@ -116,10 +116,10 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
116116
imgProfile.setImageURI(fileUri)
117117
118118
//You can get File object from intent
119-
val file:File = ImagePicker.getFile(data)
119+
val file:File = ImagePicker.getFile(data)!!
120120
121121
//You can also get File Path from intent
122-
val filePath:String = ImagePicker.getFilePath(data)
122+
val filePath:String = ImagePicker.getFilePath(data)!!
123123
} else if (resultCode == ImagePicker.RESULT_ERROR) {
124124
Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show()
125125
} else {
@@ -276,6 +276,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w
276276
* Fixed NullPointerException in FileUriUtils.getPathFromRemoteUri() [#61](https://github.com/Dhaval2404/ImagePicker/issues/61) (Special Thanks to [himphen](https://github.com/himphen))
277277
* Fixed UCropActivity Crash Android 4.4 (KiKat) [#82](https://github.com/Dhaval2404/ImagePicker/issues/82)
278278
* Fixed PNG image saved as JPG after crop issue [#94](https://github.com/Dhaval2404/ImagePicker/issues/94)
279+
* Fixed PNG image saved as JPG after compress issue [#105](https://github.com/Dhaval2404/ImagePicker/issues/105)
279280
280281
### Version: 1.6
281282

imagepicker/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
defaultConfig {
1414
minSdkVersion 19
1515
targetSdkVersion 28
16-
versionCode 11
17-
versionName "1.7.3"
16+
versionCode 12
17+
versionName "1.7.4"
1818

1919
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2020
}
@@ -72,7 +72,7 @@ ext {
7272
siteUrl = 'https://github.com/Dhaval2404/ImagePicker/'
7373
gitUrl = 'https://github.com/Dhaval2404/ImagePicker.git'
7474

75-
libraryVersion = '1.7.3'
75+
libraryVersion = '1.7.4'
7676
//If you are uploading new library try : gradlew install
7777
//If you are updating existing library then execute: gradlew bintrayUpload
7878
//In both the case don't forgot to put bintray credentials in local.properties file.

imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/provider/CompressionProvider.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.graphics.BitmapFactory
66
import android.os.AsyncTask
77
import com.github.dhaval2404.imagepicker.ImagePicker
88
import com.github.dhaval2404.imagepicker.ImagePickerActivity
9+
import com.github.dhaval2404.imagepicker.util.FileUriUtils
910
import com.github.dhaval2404.imagepicker.util.FileUtil
1011
import com.github.dhaval2404.imagepicker.util.ImageUtil
1112
import java.io.File
@@ -169,13 +170,14 @@ class CompressionProvider(activity: ImagePickerActivity) : BaseProvider(activity
169170

170171
// Check file format
171172
var format = Bitmap.CompressFormat.JPEG
172-
var quality = 90
173+
var quality = 100
173174
if (file.absolutePath.endsWith(".png")) {
174175
format = Bitmap.CompressFormat.PNG
175176
quality = 100
176177
}
177178

178-
val compressFile: File? = FileUtil.getImageFile(dir = mFileDir)
179+
val extension = FileUriUtils.getImageExtension(file)
180+
val compressFile: File? = FileUtil.getImageFile(dir = mFileDir, extension = extension)
179181
return if (compressFile != null) {
180182
ImageUtil.compressImage(
181183
file, maxWidth.toFloat(), maxHeight.toFloat(),

imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUriUtils.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,10 @@ object FileUriUtils {
180180
return if (success) file!!.path else null
181181
}
182182

183-
/** @return extension of image with dot, or default .jpg if it none.
183+
/**
184+
* Get Image Extension i.e. .png, .jpg
185+
*
186+
* @return extension of image with dot, or default .jpg if it none.
184187
*/
185188
fun getImageExtension(uriImage: Uri): String {
186189
var extension: String? = null
@@ -202,6 +205,15 @@ object FileUriUtils {
202205
return ".$extension"
203206
}
204207

208+
/**
209+
* Get Image Extension i.e. .png, .jpg
210+
*
211+
* @return extension of image with dot, or default .jpg if it none.
212+
*/
213+
fun getImageExtension(file: File): String {
214+
return getImageExtension(Uri.fromFile(file))
215+
}
216+
205217
/**
206218
* @param uri The Uri to check.
207219
* @return Whether the Uri authority is ExternalStorageProvider.

sample/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId "com.github.dhaval2404.imagepicker.sample"
1313
minSdkVersion 19
1414
targetSdkVersion 28
15-
versionCode 11
16-
versionName "1.7.3"
15+
versionCode 12
16+
versionName "1.7.4"
1717
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1818
vectorDrawables.useSupportLibrary = true
1919
}

0 commit comments

Comments
 (0)