react-native-compressor 1.8.21 → 1.8.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ <img src="https://numan.dev/images/child-lives-matter.png" />
2
+
1
3
  <div align="center">
2
4
  <img height="150" src="/media/logo.png" />
3
5
  </div>
@@ -26,8 +26,8 @@ object AutoVideoCompression {
26
26
  val actualWidth = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)!!.toInt()
27
27
  val bitrate = metaRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE)!!.toInt()
28
28
  val scale = if (actualWidth > actualHeight) maxSize / actualWidth else maxSize / actualHeight
29
- val resultWidth = Math.round(actualWidth * scale / 2) * 2
30
- val resultHeight = Math.round(actualHeight * scale / 2) * 2
29
+ val resultWidth = Math.round(actualWidth * Math.min(scale, 1f) / 2) * 2
30
+ val resultHeight = Math.round(actualHeight * Math.min(scale, 1f) / 2) * 2
31
31
  val videoBitRate = makeVideoBitrate(
32
32
  actualHeight, actualWidth,
33
33
  bitrate,
@@ -125,16 +125,25 @@ class ImageCompressor {
125
125
 
126
126
  let url = URL(fileURLWithPath: filePath)
127
127
  let source = CGImageSourceCreateWithURL(url as CFURL, nil)!
128
- var metadata = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any]
128
+ let metadata = CGImageSourceCopyPropertiesAtIndex(source, 0, nil) as? [CFString: Any]
129
129
 
130
130
  let dataProvider = CGDataProvider(data: data as CFData)
131
131
  let dataImageSource = CGImageSourceCreateWithDataProvider(dataProvider!, nil)!
132
- let dataMetadata = CGImageSourceCopyPropertiesAtIndex(dataImageSource, 0, nil) as? [CFString: Any]
132
+ var dataMetadata = CGImageSourceCopyPropertiesAtIndex(dataImageSource, 0, nil) as? [CFString: Any]
133
133
 
134
134
  // Copy all keys from source metadata to destination metadata if they don't exist
135
- for (key, value) in dataMetadata ?? [:] {
136
- if metadata?[key] == nil {
137
- metadata?[key] = value
135
+ for (key, value) in metadata ?? [:] {
136
+ if dataMetadata?[key] == nil {
137
+ dataMetadata?[key] = value
138
+ } else {
139
+ if let metadataObj = dataMetadata?[key] as? NSMutableDictionary,
140
+ let valueObj = value as? NSDictionary {
141
+ for (key, value) in valueObj {
142
+ if metadataObj[key] == nil {
143
+ metadataObj[key] = value
144
+ }
145
+ }
146
+ }
138
147
  }
139
148
  }
140
149
 
@@ -142,7 +151,7 @@ class ImageCompressor {
142
151
 
143
152
  let destinationData = NSMutableData()
144
153
  let destination = CGImageDestinationCreateWithData(destinationData, outputFormat, 1, nil)!
145
- CGImageDestinationAddImage(destination, image.cgImage!, metadata as CFDictionary?)
154
+ CGImageDestinationAddImage(destination, image.cgImage!, dataMetadata as CFDictionary?)
146
155
  CGImageDestinationFinalize(destination)
147
156
  return destinationData as Data
148
157
  }
@@ -154,7 +154,7 @@ class VideoCompressor {
154
154
  let minValue:Float=min(Float(originalHeight)/Float(height),Float(originalWidth)/Float(width))
155
155
  var remeasuredBitrate:Int = Int(Float(originalBitrate) / minValue)
156
156
  remeasuredBitrate = Int(Float(remeasuredBitrate)*compressFactor)
157
- let minBitrate:Int = self.getVideoBitrateWithFactor(f: minCompressFactor) / (1280 * 720 / (width * height))
157
+ let minBitrate:Int = Int(Float(self.getVideoBitrateWithFactor(f: minCompressFactor)) / (1280 * 720 / Float(width * height)))
158
158
  if (originalBitrate < minBitrate) {
159
159
  return remeasuredBitrate;
160
160
  }
@@ -186,8 +186,8 @@ class VideoCompressor {
186
186
 
187
187
  let bitrate=Float(abs(track.estimatedDataRate));
188
188
  let scale:Float = actualWidth > actualHeight ? (Float(maxSize) / actualWidth) : (Float(maxSize) / actualHeight);
189
- let resultWidth:Float = round(actualWidth * scale / 2) * 2;
190
- let resultHeight:Float = round(actualHeight * scale / 2) * 2;
189
+ let resultWidth:Float = round(actualWidth * min(scale, 1) / 2) * 2;
190
+ let resultHeight:Float = round(actualHeight * min(scale, 1) / 2) * 2;
191
191
 
192
192
  let videoBitRate:Int = self.makeVideoBitrate(
193
193
  originalHeight: Int(actualHeight), originalWidth: Int(actualWidth),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-compressor",
3
- "version": "1.8.21",
4
- "description": "This library compress image, video and audio",
3
+ "version": "1.8.23",
4
+ "description": "Compress Image, Video, and Audio same like Whatsapp & Auto/Manual Compression | Background Upload | Download File | Create Video Thumbnail",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
7
7
  "types": "lib/typescript/index.d.ts",