Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ createThumbnail({
| format | `String` (default `jpeg`) | Thumbnail format, can be one of: `jpeg`, or `png` |
| maxWidth | `Number` (default `512`) | Max thumbnail width in px |
| maxHeight | `Number` (default `512`) | Max thumbnail height in px |
| quality | `Number` (default `90`) | Thumbnail quality |
| dirSize | `Number` (default `100`) | Maximum size of the cache directory (in megabytes). When this directory is full, the previously generated thumbnails will be deleted to clear about half of it's size. |
| headers | `Object` | Headers to load the video with. e.g. `{ Authorization: 'someAuthToken' }` |
| cacheName | `String` (optional) | Cache name for this thumbnail to avoid duplicate generation. If specified, and a thumbnail already exists with the same cache name, it will be returned instead of generating a new one. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private ReadableMap processData(ReadableMap options) throws IOException {
int timeStamp = options.hasKey("timeStamp") ? options.getInt("timeStamp") : 0;
int maxWidth = options.hasKey("maxWidth") ? options.getInt("maxWidth") : 512;
int maxHeight = options.hasKey("maxHeight") ? options.getInt("maxHeight") : 512;
int quality = options.hasKey("quality") ? options.getInt("quality") : 90;
boolean onlySyncedFrames = options.hasKey("onlySyncedFrames") ? options.getBoolean("onlySyncedFrames") : true;
HashMap headers = options.hasKey("headers") ? options.getMap("headers").toHashMap() : new HashMap<String, String>();
String fileName = TextUtils.isEmpty(cacheName) ? ("thumb-" + UUID.randomUUID().toString()) : cacheName + "." + format;
Expand All @@ -101,11 +102,10 @@ private ReadableMap processData(ReadableMap options) throws IOException {
file.createNewFile();
fOut = new FileOutputStream(file);

// 100 means no compression, the lower you go, the stronger the compression
if (format.equals("png")) {
image.compress(Bitmap.CompressFormat.PNG, 100, fOut);
image.compress(Bitmap.CompressFormat.PNG, quality, fOut);
} else {
image.compress(Bitmap.CompressFormat.JPEG, 90, fOut);
image.compress(Bitmap.CompressFormat.JPEG, quality, fOut);
}

fOut.flush();
Expand Down
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare module "react-native-create-thumbnail" {
cacheName?: string;
maxWidth?: number;
maxHeight?: number;
quality?: number;
/**
* iOS Only
*/
Expand Down
3 changes: 2 additions & 1 deletion ios/CreateThumbnail.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @implementation CreateThumbnail
NSDictionary *headers = config[@"headers"] ?: @{};
CGFloat maxWidth = [config[@"maxWidth"] floatValue] ?: 512;
CGFloat maxHeight = [config[@"maxHeight"] floatValue] ?: 512;
CGFloat quality = [config[@"quality"] floatValue] ?: 90;
int timeToleranceMs = [config[@"timeToleranceMs"] intValue] ?: 2000;

unsigned long long cacheDirSize = dirSize * 1024 * 1024;
Expand Down Expand Up @@ -61,7 +62,7 @@ @implementation CreateThumbnail
if ([format isEqual: @"png"]) {
data = UIImagePNGRepresentation(thumbnail);
} else {
data = UIImageJPEGRepresentation(thumbnail, 1.0);
data = UIImageJPEGRepresentation(thumbnail, quality / 100);
}

NSFileManager *fileManager = [NSFileManager defaultManager];
Expand Down