@oguzhnatly/react-native-image-manipulator 1.0.5 → 1.0.13

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.
Files changed (86) hide show
  1. package/.github/workflows/publish.yml +72 -0
  2. package/Example/.bundle/config +2 -0
  3. package/Example/.eslintrc.js +4 -0
  4. package/Example/.prettierrc.js +7 -0
  5. package/Example/.watchmanconfig +1 -1
  6. package/Example/App.tsx +58 -0
  7. package/Example/Gemfile +7 -0
  8. package/Example/Gemfile.lock +99 -0
  9. package/Example/__tests__/App.test.tsx +17 -0
  10. package/Example/android/app/build.gradle +83 -114
  11. package/Example/android/app/debug.keystore +0 -0
  12. package/Example/android/app/proguard-rules.pro +0 -7
  13. package/Example/android/app/src/debug/AndroidManifest.xml +9 -0
  14. package/Example/android/app/src/main/AndroidManifest.xml +6 -7
  15. package/Example/android/app/src/main/java/com/example/MainActivity.kt +22 -0
  16. package/Example/android/app/src/main/java/com/example/MainApplication.kt +45 -0
  17. package/Example/android/app/src/main/res/drawable/rn_edit_text_material.xml +36 -0
  18. package/Example/android/app/src/main/res/values/styles.xml +2 -1
  19. package/Example/android/build.gradle +11 -29
  20. package/Example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  21. package/Example/android/gradle/wrapper/gradle-wrapper.properties +3 -1
  22. package/Example/android/gradle.properties +25 -2
  23. package/Example/android/gradlew +189 -112
  24. package/Example/android/gradlew.bat +32 -24
  25. package/Example/android/settings.gradle +2 -1
  26. package/Example/app.json +1 -1
  27. package/Example/assets/tiktok.png +0 -0
  28. package/Example/babel.config.js +3 -0
  29. package/Example/index.js +3 -1
  30. package/Example/ios/.xcode.env +11 -0
  31. package/Example/ios/Example/AppDelegate.h +2 -10
  32. package/Example/ios/Example/AppDelegate.mm +31 -0
  33. package/Example/ios/Example/Images.xcassets/AppIcon.appiconset/Contents.json +30 -15
  34. package/Example/ios/Example/Info.plist +9 -18
  35. package/Example/ios/Example/LaunchScreen.storyboard +47 -0
  36. package/Example/ios/Example/main.m +2 -8
  37. package/Example/ios/Example.xcodeproj/project.pbxproj +238 -1024
  38. package/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme +2 -43
  39. package/Example/ios/Example.xcworkspace/contents.xcworkspacedata +10 -0
  40. package/Example/ios/Example.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +8 -0
  41. package/Example/ios/ExampleTests/ExampleTests.m +19 -21
  42. package/Example/ios/Podfile +56 -0
  43. package/Example/ios/Podfile.lock +1448 -0
  44. package/Example/jest.config.js +3 -0
  45. package/Example/metro.config.js +43 -0
  46. package/Example/package.json +26 -6
  47. package/Example/tsconfig.json +3 -0
  48. package/Example/yarn.lock +5580 -3025
  49. package/README.md +218 -104
  50. package/android/build.gradle +34 -3
  51. package/android/src/main/java/com/{reactnativeimagemanipulator → oguzhnatly/rnimagemanipulator}/RNImageManipulatorModule.java +7 -4
  52. package/android/src/main/java/com/oguzhnatly/rnimagemanipulator/RNImageManipulatorPackage.java +112 -0
  53. package/android/src/paper/java/com/oguzhnatly/rnimagemanipulator/NativeImageManipulatorModuleSpec.java +33 -0
  54. package/build/fabric/NativeImageManipulatorModule.d.ts +12 -0
  55. package/build/fabric/NativeImageManipulatorModule.js +3 -0
  56. package/build/fabric/NativeImageManipulatorModule.js.map +1 -0
  57. package/build/index.d.ts +18 -17
  58. package/build/index.js +6 -3
  59. package/build/index.js.map +1 -1
  60. package/fabric/NativeImageManipulatorModule.ts +14 -0
  61. package/index.ts +28 -8
  62. package/ios/ImageUtils.h +6 -1
  63. package/ios/ImageUtils.m +180 -0
  64. package/ios/RNImageManipulator.h +10 -6
  65. package/ios/RNImageManipulator.mm +31 -0
  66. package/package.json +17 -2
  67. package/react-native-image-manipulator.podspec +11 -3
  68. package/tsconfig.json +1 -5
  69. package/Example/.babelrc +0 -3
  70. package/Example/.buckconfig +0 -6
  71. package/Example/.flowconfig +0 -70
  72. package/Example/.gitattributes +0 -1
  73. package/Example/App.js +0 -49
  74. package/Example/android/app/BUCK +0 -65
  75. package/Example/android/app/src/main/java/com/example/MainActivity.java +0 -15
  76. package/Example/android/app/src/main/java/com/example/MainApplication.java +0 -45
  77. package/Example/android/keystores/BUCK +0 -8
  78. package/Example/android/keystores/debug.keystore.properties +0 -4
  79. package/Example/ios/Example/AppDelegate.m +0 -35
  80. package/Example/ios/Example/Base.lproj/LaunchScreen.xib +0 -42
  81. package/Example/ios/Example-tvOS/Info.plist +0 -54
  82. package/Example/ios/Example-tvOSTests/Info.plist +0 -24
  83. package/Example/ios/Example.xcodeproj/xcshareddata/xcschemes/Example-tvOS.xcscheme +0 -129
  84. package/android/src/main/java/com/reactnativeimagemanipulator/RNImageManipulatorPackage.java +0 -29
  85. package/index.d.ts +0 -26
  86. package/ios/RNImageManipulator.m +0 -200
@@ -1,8 +0,0 @@
1
- keystore(
2
- name = "debug",
3
- properties = "debug.keystore.properties",
4
- store = "debug.keystore",
5
- visibility = [
6
- "PUBLIC",
7
- ],
8
- )
@@ -1,4 +0,0 @@
1
- key.store=debug.keystore
2
- key.alias=androiddebugkey
3
- key.store.password=android
4
- key.alias.password=android
@@ -1,35 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- #import "AppDelegate.h"
9
-
10
- #import <React/RCTBundleURLProvider.h>
11
- #import <React/RCTRootView.h>
12
-
13
- @implementation AppDelegate
14
-
15
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
16
- {
17
- NSURL *jsCodeLocation;
18
-
19
- jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
20
-
21
- RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
22
- moduleName:@"Example"
23
- initialProperties:nil
24
- launchOptions:launchOptions];
25
- rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
26
-
27
- self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
28
- UIViewController *rootViewController = [UIViewController new];
29
- rootViewController.view = rootView;
30
- self.window.rootViewController = rootViewController;
31
- [self.window makeKeyAndVisible];
32
- return YES;
33
- }
34
-
35
- @end
@@ -1,42 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
- <document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7702" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
3
- <dependencies>
4
- <deployment identifier="iOS"/>
5
- <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7701"/>
6
- <capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
7
- </dependencies>
8
- <objects>
9
- <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
10
- <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
11
- <view contentMode="scaleToFill" id="iN0-l3-epB">
12
- <rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
13
- <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
14
- <subviews>
15
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Powered by React Native" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
16
- <rect key="frame" x="20" y="439" width="441" height="21"/>
17
- <fontDescription key="fontDescription" type="system" pointSize="17"/>
18
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
19
- <nil key="highlightedColor"/>
20
- </label>
21
- <label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Example" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
22
- <rect key="frame" x="20" y="140" width="441" height="43"/>
23
- <fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
24
- <color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
25
- <nil key="highlightedColor"/>
26
- </label>
27
- </subviews>
28
- <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
29
- <constraints>
30
- <constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
31
- <constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
32
- <constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
33
- <constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
34
- <constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
35
- <constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
36
- </constraints>
37
- <nil key="simulatedStatusBarMetrics"/>
38
- <freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
39
- <point key="canvasLocation" x="548" y="455"/>
40
- </view>
41
- </objects>
42
- </document>
@@ -1,54 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>CFBundleDevelopmentRegion</key>
6
- <string>en</string>
7
- <key>CFBundleExecutable</key>
8
- <string>$(EXECUTABLE_NAME)</string>
9
- <key>CFBundleIdentifier</key>
10
- <string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
11
- <key>CFBundleInfoDictionaryVersion</key>
12
- <string>6.0</string>
13
- <key>CFBundleName</key>
14
- <string>$(PRODUCT_NAME)</string>
15
- <key>CFBundlePackageType</key>
16
- <string>APPL</string>
17
- <key>CFBundleShortVersionString</key>
18
- <string>1.0</string>
19
- <key>CFBundleSignature</key>
20
- <string>????</string>
21
- <key>CFBundleVersion</key>
22
- <string>1</string>
23
- <key>LSRequiresIPhoneOS</key>
24
- <true/>
25
- <key>UILaunchStoryboardName</key>
26
- <string>LaunchScreen</string>
27
- <key>UIRequiredDeviceCapabilities</key>
28
- <array>
29
- <string>armv7</string>
30
- </array>
31
- <key>UISupportedInterfaceOrientations</key>
32
- <array>
33
- <string>UIInterfaceOrientationPortrait</string>
34
- <string>UIInterfaceOrientationLandscapeLeft</string>
35
- <string>UIInterfaceOrientationLandscapeRight</string>
36
- </array>
37
- <key>UIViewControllerBasedStatusBarAppearance</key>
38
- <false/>
39
- <key>NSLocationWhenInUseUsageDescription</key>
40
- <string></string>
41
- <key>NSAppTransportSecurity</key>
42
- <!--See http://ste.vn/2015/06/10/configuring-app-transport-security-ios-9-osx-10-11/ -->
43
- <dict>
44
- <key>NSExceptionDomains</key>
45
- <dict>
46
- <key>localhost</key>
47
- <dict>
48
- <key>NSExceptionAllowsInsecureHTTPLoads</key>
49
- <true/>
50
- </dict>
51
- </dict>
52
- </dict>
53
- </dict>
54
- </plist>
@@ -1,24 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>CFBundleDevelopmentRegion</key>
6
- <string>en</string>
7
- <key>CFBundleExecutable</key>
8
- <string>$(EXECUTABLE_NAME)</string>
9
- <key>CFBundleIdentifier</key>
10
- <string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)</string>
11
- <key>CFBundleInfoDictionaryVersion</key>
12
- <string>6.0</string>
13
- <key>CFBundleName</key>
14
- <string>$(PRODUCT_NAME)</string>
15
- <key>CFBundlePackageType</key>
16
- <string>BNDL</string>
17
- <key>CFBundleShortVersionString</key>
18
- <string>1.0</string>
19
- <key>CFBundleSignature</key>
20
- <string>????</string>
21
- <key>CFBundleVersion</key>
22
- <string>1</string>
23
- </dict>
24
- </plist>
@@ -1,129 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Scheme
3
- LastUpgradeVersion = "0940"
4
- version = "1.3">
5
- <BuildAction
6
- parallelizeBuildables = "NO"
7
- buildImplicitDependencies = "YES">
8
- <BuildActionEntries>
9
- <BuildActionEntry
10
- buildForTesting = "YES"
11
- buildForRunning = "YES"
12
- buildForProfiling = "YES"
13
- buildForArchiving = "YES"
14
- buildForAnalyzing = "YES">
15
- <BuildableReference
16
- BuildableIdentifier = "primary"
17
- BlueprintIdentifier = "2D2A28121D9B038B00D4039D"
18
- BuildableName = "libReact.a"
19
- BlueprintName = "React-tvOS"
20
- ReferencedContainer = "container:../node_modules/react-native/React/React.xcodeproj">
21
- </BuildableReference>
22
- </BuildActionEntry>
23
- <BuildActionEntry
24
- buildForTesting = "YES"
25
- buildForRunning = "YES"
26
- buildForProfiling = "YES"
27
- buildForArchiving = "YES"
28
- buildForAnalyzing = "YES">
29
- <BuildableReference
30
- BuildableIdentifier = "primary"
31
- BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
32
- BuildableName = "Example-tvOS.app"
33
- BlueprintName = "Example-tvOS"
34
- ReferencedContainer = "container:Example.xcodeproj">
35
- </BuildableReference>
36
- </BuildActionEntry>
37
- <BuildActionEntry
38
- buildForTesting = "YES"
39
- buildForRunning = "YES"
40
- buildForProfiling = "NO"
41
- buildForArchiving = "NO"
42
- buildForAnalyzing = "YES">
43
- <BuildableReference
44
- BuildableIdentifier = "primary"
45
- BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
46
- BuildableName = "Example-tvOSTests.xctest"
47
- BlueprintName = "Example-tvOSTests"
48
- ReferencedContainer = "container:Example.xcodeproj">
49
- </BuildableReference>
50
- </BuildActionEntry>
51
- </BuildActionEntries>
52
- </BuildAction>
53
- <TestAction
54
- buildConfiguration = "Debug"
55
- selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
56
- selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
57
- shouldUseLaunchSchemeArgsEnv = "YES">
58
- <Testables>
59
- <TestableReference
60
- skipped = "NO">
61
- <BuildableReference
62
- BuildableIdentifier = "primary"
63
- BlueprintIdentifier = "2D02E48F1E0B4A5D006451C7"
64
- BuildableName = "Example-tvOSTests.xctest"
65
- BlueprintName = "Example-tvOSTests"
66
- ReferencedContainer = "container:Example.xcodeproj">
67
- </BuildableReference>
68
- </TestableReference>
69
- </Testables>
70
- <MacroExpansion>
71
- <BuildableReference
72
- BuildableIdentifier = "primary"
73
- BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
74
- BuildableName = "Example-tvOS.app"
75
- BlueprintName = "Example-tvOS"
76
- ReferencedContainer = "container:Example.xcodeproj">
77
- </BuildableReference>
78
- </MacroExpansion>
79
- <AdditionalOptions>
80
- </AdditionalOptions>
81
- </TestAction>
82
- <LaunchAction
83
- buildConfiguration = "Debug"
84
- selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
85
- selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
86
- launchStyle = "0"
87
- useCustomWorkingDirectory = "NO"
88
- ignoresPersistentStateOnLaunch = "NO"
89
- debugDocumentVersioning = "YES"
90
- debugServiceExtension = "internal"
91
- allowLocationSimulation = "YES">
92
- <BuildableProductRunnable
93
- runnableDebuggingMode = "0">
94
- <BuildableReference
95
- BuildableIdentifier = "primary"
96
- BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
97
- BuildableName = "Example-tvOS.app"
98
- BlueprintName = "Example-tvOS"
99
- ReferencedContainer = "container:Example.xcodeproj">
100
- </BuildableReference>
101
- </BuildableProductRunnable>
102
- <AdditionalOptions>
103
- </AdditionalOptions>
104
- </LaunchAction>
105
- <ProfileAction
106
- buildConfiguration = "Release"
107
- shouldUseLaunchSchemeArgsEnv = "YES"
108
- savedToolIdentifier = ""
109
- useCustomWorkingDirectory = "NO"
110
- debugDocumentVersioning = "YES">
111
- <BuildableProductRunnable
112
- runnableDebuggingMode = "0">
113
- <BuildableReference
114
- BuildableIdentifier = "primary"
115
- BlueprintIdentifier = "2D02E47A1E0B4A5D006451C7"
116
- BuildableName = "Example-tvOS.app"
117
- BlueprintName = "Example-tvOS"
118
- ReferencedContainer = "container:Example.xcodeproj">
119
- </BuildableReference>
120
- </BuildableProductRunnable>
121
- </ProfileAction>
122
- <AnalyzeAction
123
- buildConfiguration = "Debug">
124
- </AnalyzeAction>
125
- <ArchiveAction
126
- buildConfiguration = "Release"
127
- revealArchiveInOrganizer = "YES">
128
- </ArchiveAction>
129
- </Scheme>
@@ -1,29 +0,0 @@
1
-
2
- package com.oguzhnatly.rnimagemanipulator;
3
-
4
- import java.util.Arrays;
5
- import java.util.Collections;
6
- import java.util.List;
7
-
8
- import com.facebook.react.ReactPackage;
9
- import com.facebook.react.bridge.NativeModule;
10
- import com.facebook.react.bridge.ReactApplicationContext;
11
- import com.facebook.react.uimanager.ViewManager;
12
- import com.facebook.react.bridge.JavaScriptModule;
13
-
14
- public class RNImageManipulatorPackage implements ReactPackage {
15
- @Override
16
- public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
17
- return Arrays.<NativeModule>asList(new RNImageManipulatorModule(reactContext));
18
- }
19
-
20
- // Deprecated from RN 0.47
21
- public List<Class<? extends JavaScriptModule>> createJSModules() {
22
- return Collections.emptyList();
23
- }
24
-
25
- @Override
26
- public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
27
- return Collections.emptyList();
28
- }
29
- }
package/index.d.ts DELETED
@@ -1,26 +0,0 @@
1
- import {RNImageManipulatorResult as ImageResult} from './index';
2
-
3
- export declare type RNImageManipulatorResult = ImageResult;
4
-
5
- declare const RNImageManipulator: {
6
- manipulate: (
7
- uri: string,
8
- actions: Array<{
9
- resize?: {width?: number; height?: number};
10
- rotate?: number;
11
- flip?: {vertical?: boolean; horizontal?: boolean};
12
- crop?: {
13
- originX?: number;
14
- originY?: number;
15
- width?: number;
16
- height?: number;
17
- };
18
- }>,
19
- saveOptions: {
20
- compress?: number;
21
- format?: 'jpeg' | 'png';
22
- base64?: boolean;
23
- },
24
- ) => Promise<RNImageManipulatorResult>;
25
- };
26
- export default RNImageManipulator;
@@ -1,200 +0,0 @@
1
- #import "RNImageManipulator.h"
2
- #import "ImageUtils.h"
3
- #import <React/RCTLog.h>
4
- #import <Photos/Photos.h>
5
-
6
- @implementation RNImageManipulator
7
-
8
- RCT_EXPORT_MODULE(RNImageManipulator);
9
-
10
- @synthesize bridge = _bridge;
11
-
12
- - (void)setBridge:(RCTBridge *)bridge
13
- {
14
- _bridge = bridge;
15
- }
16
-
17
- - (dispatch_queue_t)methodQueue
18
- {
19
- return dispatch_get_main_queue();
20
- }
21
-
22
- RCT_EXPORT_METHOD(manipulate:(NSString *)uri
23
- actions:(NSArray *)actions
24
- saveOptions:(NSDictionary *)saveOptions
25
- resolver:(RCTPromiseResolveBlock)resolve
26
- rejecter:(RCTPromiseRejectBlock)reject)
27
- {
28
- NSURL *url = [NSURL URLWithString:uri];
29
- NSString *path = [url.path stringByStandardizingPath];
30
-
31
- if ([[url scheme] isEqualToString:@"assets-library"]) {
32
- PHFetchResult<PHAsset *> *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
33
- if (fetchResult.count > 0) {
34
- PHAsset *asset = fetchResult[0];
35
- CGSize size = CGSizeMake([asset pixelWidth], [asset pixelHeight]);
36
- PHImageRequestOptions *options = [PHImageRequestOptions new];
37
- [options setResizeMode:PHImageRequestOptionsResizeModeExact];
38
- [options setNetworkAccessAllowed:YES];
39
- [options setSynchronous:NO];
40
- [options setDeliveryMode:PHImageRequestOptionsDeliveryModeHighQualityFormat];
41
-
42
- [[PHImageManager defaultManager] requestImageForAsset:asset targetSize:size contentMode:PHImageContentModeAspectFit options:options resultHandler:^(UIImage * _Nullable image, NSDictionary * _Nullable info) {
43
- if (!image) {
44
- reject(@"E_IMAGE_MANIPULATION_FAILED", [NSString stringWithFormat:@"The file isn't convertable to image. Given path: `%@`.", path], nil);
45
- return;
46
- }
47
- [self manipulateImage:image actions:actions saveOptions:saveOptions resolver:resolve rejecter:reject];
48
- }];
49
- return;
50
- } else {
51
- reject(@"E_IMAGE_MANIPULATION_FAILED", [NSString stringWithFormat:@"The file does not exist. Given path: `%@`.", path], nil);
52
- return;
53
- }
54
- } else {
55
- if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
56
- reject(@"E_IMAGE_MANIPULATION_FAILED", [NSString stringWithFormat:@"The file does not exist. Given path: `%@`.", path], nil);
57
- return;
58
- }
59
-
60
- UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
61
- if (image == nil) {
62
- reject(@"E_CANNOT_OPEN", @"Could not open provided image", nil);
63
- return;
64
- }
65
-
66
- [self manipulateImage:image actions:actions saveOptions:saveOptions resolver:resolve rejecter:reject];
67
- return;
68
- }
69
- }
70
-
71
- -(void)manipulateImage:(UIImage *)image
72
- actions:(NSArray *)actions
73
- saveOptions:(NSDictionary *)saveOptions
74
- resolver:(RCTPromiseResolveBlock)resolve
75
- rejecter:(RCTPromiseRejectBlock)reject
76
- {
77
- for (NSDictionary *options in actions) {
78
- if (options[@"resize"]) {
79
- float imageWidth = image.size.width;
80
- float imageHeight = image.size.height;
81
- float imageRatio = imageWidth / imageHeight;
82
-
83
- NSInteger requestedWidth = 0;
84
- NSInteger requestedHeight = 0;
85
- NSDictionary *resize = options[@"resize"];
86
- if (resize[@"width"]) {
87
- requestedWidth = [(NSNumber *)resize[@"width"] integerValue];
88
- requestedHeight = requestedWidth/imageRatio;
89
- }
90
- if (resize[@"height"]) {
91
- requestedHeight = [(NSNumber *)resize[@"height"] integerValue];
92
- requestedWidth = requestedWidth == 0 ? imageRatio * requestedHeight : requestedWidth;
93
- }
94
-
95
- CGSize requestedSize = CGSizeMake(requestedWidth, requestedHeight);
96
- UIGraphicsBeginImageContextWithOptions(requestedSize, NO, 1.0);
97
- [image drawInRect:CGRectMake(0, 0, requestedWidth, requestedHeight)];
98
- image = UIGraphicsGetImageFromCurrentImageContext();
99
- UIGraphicsEndImageContext();
100
- } else if (options[@"rotate"]) {
101
- float rads = [(NSNumber *)options[@"rotate"] integerValue] * M_PI/180;
102
- CGSize size = image.size;
103
- UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,size.width, size.height)];
104
- CGAffineTransform t = CGAffineTransformMakeRotation(rads);
105
- rotatedViewBox.transform = t;
106
- CGSize rotatedSize = rotatedViewBox.frame.size;
107
-
108
- UIGraphicsBeginImageContext(rotatedSize);
109
- CGContextRef bitmap = UIGraphicsGetCurrentContext();
110
- CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
111
- CGContextRotateCTM(bitmap, rads);
112
- CGContextScaleCTM(bitmap, 1.0, -1.0);
113
- CGContextDrawImage(bitmap, CGRectMake(-size.width / 2, -size.height / 2, size.width, size.height), image.CGImage);
114
-
115
- image = UIGraphicsGetImageFromCurrentImageContext();
116
- UIGraphicsEndImageContext();
117
- } else if (options[@"flip"]) {
118
- NSDictionary *flip = options[@"flip"];
119
- UIImageView *tempImageView = [[UIImageView alloc] initWithImage:image];
120
-
121
- UIGraphicsBeginImageContext(tempImageView.frame.size);
122
- CGContextRef context = UIGraphicsGetCurrentContext();
123
- CGAffineTransform transform;
124
- if (flip[@"vertical"]) {
125
- transform = CGAffineTransformMake(1, 0, 0, -1, 0, tempImageView.frame.size.height);
126
- CGContextConcatCTM(context, transform);
127
- } else if (flip[@"horizontal"]) {
128
- transform = CGAffineTransformMake(-1, 0, 0, 1, tempImageView.frame.size.width, 0);
129
- CGContextConcatCTM(context, transform);
130
- }
131
-
132
- [tempImageView.layer renderInContext:context];
133
- image = UIGraphicsGetImageFromCurrentImageContext();
134
- UIGraphicsEndImageContext();
135
- } else if (options[@"crop"]) {
136
- NSDictionary *cropData = options[@"crop"];
137
- if (cropData[@"originX"] == nil || cropData[@"originY"] == nil || cropData[@"width"] == nil || cropData[@"height"]== nil) {
138
- reject(@"E_INVALID_CROP_DATA", @"Invalid crop options has been passed. Please make sure the object contains originX, originY, width and height.", nil);
139
- return;
140
- }
141
-
142
- float originX = [(NSNumber *)cropData[@"originX"] floatValue];
143
- float originY = [(NSNumber *)cropData[@"originY"] floatValue];
144
- float requestedWidth = [(NSNumber *)cropData[@"width"] floatValue];
145
- float requestedHeight = [(NSNumber *)cropData[@"height"] floatValue];
146
-
147
- if (originX > image.size.width || originY > image.size.height || requestedWidth > image.size.width || requestedHeight > image.size.height) {
148
- reject(@"E_INVALID_CROP_DATA", @"Invalid crop options has been passed. Please make sure the requested crop rectangle is inside source image.", nil);
149
- return;
150
- }
151
- CGRect cropDimensions = CGRectMake(originX, originY, requestedWidth, requestedHeight);
152
- image = [ImageUtils cropImage:image toRect:cropDimensions];
153
- }
154
- }
155
-
156
- float compressionValue = 1.0;
157
- if (saveOptions[@"compress"] != nil) {
158
- compressionValue = [(NSNumber *)saveOptions[@"compress"] floatValue];
159
- }
160
-
161
- NSData *imageData = nil;
162
- NSString *format = saveOptions[@"format"];
163
- NSString *extension;
164
- if (format == nil) {
165
- format = @"jpeg";
166
- }
167
- if ([format isEqualToString:@"jpeg"]) {
168
- imageData = UIImageJPEGRepresentation(image, compressionValue);
169
- extension = @".jpg";
170
- } else if ([format isEqualToString:@"png"]) {
171
- imageData = UIImagePNGRepresentation(image);
172
- extension = @".png";
173
- } else {
174
- RCTLogWarn(@"Unsupported format: %@, using JPEG instead.", format);
175
- imageData = UIImageJPEGRepresentation(image, compressionValue);
176
- extension = @".jpg";
177
- }
178
-
179
-
180
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
181
- NSString *directory = directory = [paths firstObject];
182
- NSString *fileName = [[[NSUUID UUID] UUIDString] stringByAppendingString:extension];
183
- NSString *newPath = [directory stringByAppendingPathComponent:fileName];
184
-
185
- [imageData writeToFile:newPath atomically:YES];
186
- NSURL *fileURL = [NSURL fileURLWithPath:newPath];
187
- NSString *filePath = [fileURL absoluteString];
188
- NSMutableDictionary *response = [[NSMutableDictionary alloc] init];
189
- response[@"uri"] = filePath;
190
- response[@"filename"] = fileName;
191
- response[@"width"] = @(CGImageGetWidth(image.CGImage));
192
- response[@"height"] = @(CGImageGetHeight(image.CGImage));
193
- if (saveOptions[@"base64"] && [saveOptions[@"base64"] boolValue]) {
194
- response[@"base64"] = [imageData base64EncodedStringWithOptions:0];
195
- }
196
-
197
- resolve(response);
198
- }
199
-
200
- @end