Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing #4

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b7fa2f6
Fixed warning "thrown type FileNotFoundException has already been cau…
l0stpenguin Sep 19, 2018
422e575
Merge pull request #1 from spoonconsulting/remove-file-exception
ombr Sep 25, 2018
b0215dd
force thumbnail generation
l0stpenguin Feb 8, 2019
7ad6611
Merge pull request #2 from spoonconsulting/ios_force_generation
ombr Feb 8, 2019
afb225d
Create spoonconsulting version
ombr Aug 6, 2020
0a5d58c
add correct plugin id
dinitri Feb 26, 2021
7537835
Merge pull request #3 from spoonconsulting/fix-cordova-plugin-id
ombr Mar 2, 2021
5eb74ca
create thumbnail with appropriate height and width
parveshneedhoo May 9, 2023
5afcb8f
use ios built-in function for thumbnail
dinitri May 10, 2023
b4c890d
use correct when using uiimage and uigraphic
dinitri May 10, 2023
37f30ab
fix landscape ratio
dinitri May 11, 2023
69cf4bd
move orientation declaration
parveshneedhoo May 12, 2023
6204d4f
fix orientation ratio ios
parveshneedhoo May 12, 2023
9a7fe03
remove unused code
parveshneedhoo May 12, 2023
0f74000
revert changes from android thumbnail plugin
parveshneedhoo May 16, 2023
72499c9
add eof line
parveshneedhoo May 22, 2023
ad0df4b
code refactoring
parveshneedhoo Jun 5, 2023
1d5c24d
refactoring
parveshneedhoo Jun 9, 2023
5679d7f
Create npm-publish.yml
dinitri Jun 9, 2023
baba057
create package-lock
dinitri Jun 9, 2023
7b7d023
Merge branch 'master' of github.com:spoonconsulting/cordova-plugin-th…
dinitri Jun 9, 2023
eda77b8
version bump 1.0.3
dinitri Jun 9, 2023
3dc41c9
Merge pull request #4 from spoonconsulting/fix-thumbnail-size-issue
dinitri Jun 9, 2023
91392e2
Add jackson
HashirRajah Sep 24, 2024
ab06815
Import jackson
HashirRajah Sep 24, 2024
6b2eedf
Add null check
HashirRajah Sep 24, 2024
5cb44dc
Latest jackson version
HashirRajah Sep 24, 2024
060c2c4
Remove jackson for test
HashirRajah Sep 24, 2024
2d458ee
Add jackson
HashirRajah Sep 24, 2024
2b8ebb0
testing
parveshneedhoo Sep 25, 2024
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
13 changes: 13 additions & 0 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Node.js Package
on: push
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: bahmutov/npm-install@v1
- id: publish
uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.npm_token }}

20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"name": "cordova-plugin-thumbnail",
"version": "1.0.0",
"name": "@spoonconsulting/cordova-plugin-thumbnail",
"version": "1.0.3",
"description": "Image thumbnail generator for Cordova project",
"cordova": {
"id": "cordova-plugin-thumbnail",
"id": "@spoonconsulting/cordova-plugin-thumbnail",
"platforms": [
"ios",
"android"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/almas/cordova-plugin-thumbnail.git"
"url": "git+https://github.com/spoonconsulting/cordova-plugin-thumbnail.git"
},
"keywords": [
"thumbnail",
"ecosystem:cordova",
"cordova-android",
"cordova-ios"
],
"author": "Almas",
"author": "Almas & Spoonconsulting",
"license": "Apache 2.0",
"bugs": {
"url": "https://github.com/almas/cordova-plugin-thumbnail/issues"
"url": "https://github.com/spoonconsulting/cordova-plugin-thumbnail/issues"
},
"homepage": "https://github.com/almas/cordova-plugin-thumbnail#readme",
"homepage": "https://github.com/spoonconsulting/cordova-plugin-thumbnail#readme",
"engines": {
"cordovaDependencies": {
"0.1.0": {
Expand Down
3 changes: 2 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-thumbnail" version="1.0.0">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="@spoonconsulting/cordova-plugin-thumbnail" version="1.0.3">
<name>Thumbnail</name>
<description>Cordova Thumbnail Plugin</description>
<license>Apache 2.0</license>
Expand All @@ -12,6 +12,7 @@
<dependency id="cordova-plugin-file"/>

<platform name="android">

<config-file target="res/xml/config.xml" parent="/*">
<feature name="Thumbnails">
<param name="android-package" value="com.cordova.plugin.thumbnail.ThumbnailsCordovaPlugin"/>
Expand Down
11 changes: 6 additions & 5 deletions src/android/Thumbnails.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

public class Thumbnails {

public static void thumbnail(Options thumbnailOptions) throws IOException {
public static void thumbnail(Options thumbnailOptions) throws Exception {
long begin = System.currentTimeMillis();

Bitmap bitmap = thumbnailSmallImage(thumbnailOptions);
Expand All @@ -37,12 +37,16 @@ public static void thumbnail(Options thumbnailOptions) throws IOException {
bitmap = null;
}

private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws IOException {
private static Bitmap thumbnailSmallImage(Options thumbnailOptions) throws Exception {

BitmapFactory.Options options = calculateImageSize(thumbnailOptions.sourcePath);
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(thumbnailOptions.sourcePath, options);

if (bitmap == null) {
throw new Exception("Could not decode file into bitmap object { sourcePath: " + thumbnailOptions.sourcePath + " options: }");
}

long begin = System.currentTimeMillis();
int oWidth = bitmap.getWidth();
int oHeight = bitmap.getHeight();
Expand Down Expand Up @@ -123,9 +127,6 @@ public static Boolean saveBitmapToFile(Bitmap bitmap, String targetPath, Options
bitmap.compress(guessImageType(targetPath), 90, os);
} catch (FileNotFoundException ex) {
throw new TargetPathNotFoundException(ex);
} catch (IOException ex) {
Log.e("Thumbnails.saveBitmapToFile()", "Error opening file stream:" + targetPath);
ex.printStackTrace();
} finally {
if (os != null) {
try {
Expand Down
45 changes: 28 additions & 17 deletions src/ios/Thumbnail.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,35 @@ + (void) thumbnail:(NSString *)imageURL size:(CGFloat)maxSize toURL:(NSString *)

+ (UIImage *)thumbnailWithContentsOfURL:(NSURL *)URL maxPixelSize:(CGFloat)maxPixelSize
{
CGImageSourceRef imageSource = CGImageSourceCreateWithURL((__bridge CFURLRef)URL, NULL);
if(imageSource == NULL) {
NSLog(@"Can not read from source: %@", URL);
return NULL;
NSData *data = [NSData dataWithContentsOfURL:URL];
UIImage* image = [[UIImage alloc] initWithData:data];
double thumbnailHeight;
double thumbnailWidth;
CGSize thumbnailSize;
double maxPointSize = maxPixelSize / (double) (image.scale);

double ratio;
if ((image.size.width / image.size.height) > 1) {
ratio = MAX(image.size.width / maxPointSize, image.size.height / maxPointSize);
} else {
ratio = MIN(image.size.width / maxPointSize, image.size.height / maxPointSize);
}

if (@available(iOS 15.0, *)) {
thumbnailHeight = (image.size.height / ratio) / image.scale;
thumbnailWidth = (image.size.width / ratio) / image.scale;
thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight);
return [image imageByPreparingThumbnailOfSize: thumbnailSize];
} else {
thumbnailHeight = (image.size.height / ratio) / UIScreen.mainScreen.scale;
thumbnailWidth = (image.size.width / ratio) / UIScreen.mainScreen.scale;
thumbnailSize = CGSizeMake(thumbnailWidth, thumbnailHeight);
UIGraphicsBeginImageContextWithOptions(thumbnailSize, false, 0.0);
[image drawInRect:CGRectMake(0, 0, thumbnailSize.width, thumbnailSize.height)];
UIImage *thumbnailImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return thumbnailImage;
}

NSDictionary *imageOptions = @{
(NSString const *)kCGImageSourceCreateThumbnailFromImageIfAbsent : (NSNumber const *)kCFBooleanTrue,
(NSString const *)kCGImageSourceThumbnailMaxPixelSize : @(maxPixelSize),
(NSString const *)kCGImageSourceCreateThumbnailWithTransform : (NSNumber const *)kCFBooleanTrue
};
CGImageRef thumbnail = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (__bridge CFDictionaryRef)imageOptions);
CFRelease(imageSource);

UIImage *result = [[UIImage alloc] initWithCGImage:thumbnail];
CGImageRelease(thumbnail);

return result;
}

@end
Expand Down