Skip to content

Commit 52dfcf3

Browse files
committed
Merge branch 'develop'
2 parents ff9ea5f + 7cddf74 commit 52dfcf3

File tree

6 files changed

+161
-4
lines changed

6 files changed

+161
-4
lines changed

FilestackSDK.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@
159159
4586F19E2524F1CF008F282E /* FilestackSDK.h in Headers */ = {isa = PBXBuildFile; fileRef = 4586F1652524EEB8008F282E /* FilestackSDK.h */; settings = {ATTRIBUTES = (Public, ); }; };
160160
4586F1C42524FD7E008F282E /* Fixtures in Resources */ = {isa = PBXBuildFile; fileRef = 4586F1C32524FD7E008F282E /* Fixtures */; };
161161
4591004A25C1A3DF008187F5 /* URLSession+filestackDefault.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4591004925C1A3DF008187F5 /* URLSession+filestackDefault.swift */; };
162+
45F3187026CAB6B300A60607 /* SmartCropTransform.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45F3186F26CAB6B300A60607 /* SmartCropTransform.swift */; };
163+
45F3187226CAB6BF00A60607 /* TransformSmartCropMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 45F3187126CAB6BF00A60607 /* TransformSmartCropMode.swift */; };
162164
/* End PBXBuildFile section */
163165

164166
/* Begin PBXContainerItemProxy section */
@@ -310,6 +312,8 @@
310312
4586F1652524EEB8008F282E /* FilestackSDK.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FilestackSDK.h; sourceTree = "<group>"; };
311313
4586F1C32524FD7E008F282E /* Fixtures */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Fixtures; sourceTree = "<group>"; };
312314
4591004925C1A3DF008187F5 /* URLSession+filestackDefault.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "URLSession+filestackDefault.swift"; sourceTree = "<group>"; };
315+
45F3186F26CAB6B300A60607 /* SmartCropTransform.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SmartCropTransform.swift; sourceTree = "<group>"; };
316+
45F3187126CAB6BF00A60607 /* TransformSmartCropMode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransformSmartCropMode.swift; sourceTree = "<group>"; };
313317
"FilestackSDK::FilestackSDK::Product" /* FilestackSDK.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = FilestackSDK.framework; sourceTree = BUILT_PRODUCTS_DIR; };
314318
OBJ_164 /* BaseOperationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseOperationTests.swift; sourceTree = "<group>"; };
315319
OBJ_165 /* ClientTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientTests.swift; sourceTree = "<group>"; };
@@ -496,6 +500,7 @@
496500
45825BB02524E389002F3310 /* TransformPageOrientation.swift */,
497501
45825BBE2524E389002F3310 /* TransformPosition.swift */,
498502
45825BB12524E389002F3310 /* TransformShapeType.swift */,
503+
45F3187126CAB6BF00A60607 /* TransformSmartCropMode.swift */,
499504
45825BB32524E389002F3310 /* TransformStyleMode.swift */,
500505
45825BB62524E389002F3310 /* UploadStatus.swift */,
501506
);
@@ -592,6 +597,7 @@
592597
45825C072524E389002F3310 /* SepiaTransform.swift */,
593598
45825BD82524E389002F3310 /* ShadowTransform.swift */,
594599
45825BFC2524E389002F3310 /* SharpenTransform.swift */,
600+
45F3186F26CAB6B300A60607 /* SmartCropTransform.swift */,
595601
45825BF12524E389002F3310 /* TagsTransform.swift */,
596602
45825BDF2524E389002F3310 /* TornEdgesTransform.swift */,
597603
45825BEB2524E389002F3310 /* Transform.swift */,
@@ -734,7 +740,7 @@
734740
attributes = {
735741
LastSwiftMigration = 9999;
736742
LastSwiftUpdateCheck = 1200;
737-
LastUpgradeCheck = 1240;
743+
LastUpgradeCheck = 1300;
738744
TargetAttributes = {
739745
45825B252524DE46002F3310 = {
740746
CreatedOnToolsVersion = 12.0;
@@ -861,6 +867,7 @@
861867
45825C522524E38B002F3310 /* TransformPageFormat.swift in Sources */,
862868
45825C2A2524E38A002F3310 /* CommitPartUploadOperation.swift in Sources */,
863869
45825C582524E38B002F3310 /* UploadOptions.swift in Sources */,
870+
45F3187226CAB6BF00A60607 /* TransformSmartCropMode.swift in Sources */,
864871
45825C342524E38A002F3310 /* String+Hmac.swift in Sources */,
865872
45825C5F2524E38B002F3310 /* Transformable+Deprecated.swift in Sources */,
866873
45825C392524E38A002F3310 /* UploadDescriptor.swift in Sources */,
@@ -932,6 +939,7 @@
932939
45825C712524E38B002F3310 /* NoMetadataTransform.swift in Sources */,
933940
45825C3C2524E38A002F3310 /* CDNService.swift in Sources */,
934941
45825C852524E38C002F3310 /* PDFConvertTransform.swift in Sources */,
942+
45F3187026CAB6B300A60607 /* SmartCropTransform.swift in Sources */,
935943
45825C742524E38B002F3310 /* ModulateTransform.swift in Sources */,
936944
45825C2F2524E38A002F3310 /* NetworkingServiceWithBaseURL+buildURL.swift in Sources */,
937945
45825C7A2524E38B002F3310 /* MinifyCSSTransform.swift in Sources */,

FilestackSDK.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"repositoryURL": "https://github.com/AliSoftware/OHHTTPStubs.git",
77
"state": {
88
"branch": null,
9-
"revision": "e92b5a5746ef16add2a1424f1fc19529d9a75cde",
10-
"version": "9.0.0"
9+
"revision": "12f19662426d0434d6c330c6974d53e2eb10ecd9",
10+
"version": "9.1.0"
1111
}
1212
}
1313
]

FilestackSDK.xcodeproj/xcshareddata/xcschemes/FilestackSDK.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1240"
3+
LastUpgradeVersion = "1300"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// TransformSmartCropMode.swift
3+
// FilestackSDK
4+
//
5+
// Created by Ruben Nine on 16/8/21.
6+
// Copyright © 2021 Filestack. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
/// Represents an image transform smart crop type.
12+
public enum TransformSmartCropMode: CustomStringConvertible {
13+
/// Face
14+
case face
15+
/// Object
16+
case object(name: String)
17+
/// Auto
18+
case auto
19+
}
20+
21+
// MARK: - CustomStringConvertible Conformance
22+
23+
extension TransformSmartCropMode {
24+
/// Returns a `String` representation of self.
25+
public var description: String {
26+
switch self {
27+
case .face: return "face"
28+
case .object(let name): return "object,object:\(name)"
29+
case .auto: return "auto"
30+
}
31+
}
32+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// SmartCropTransform.swift
3+
// FilestackSDK
4+
//
5+
// Created by Ruben Nine on 16/8/21.
6+
// Copyright © 2021 Filestack. All rights reserved.
7+
//
8+
9+
import UIKit
10+
11+
/// Allows you to programmatically manipulate your images in a way that provides a version of the image that is
12+
/// exactly of the shape you want, while keeping it’s aspect ratio and cutting out least interesting fragments of
13+
/// the input picture.
14+
///
15+
/// For more information, please check our [docs](https://www.filestack.com/docs/api/processing/#smart-crop).
16+
public class SmartCropTransform: Transform {
17+
// MARK: - Lifecycle
18+
19+
/// Initializes a `SmartCropTransform` object.
20+
public init() {
21+
super.init(name: "smart_crop")
22+
}
23+
}
24+
25+
// MARK: - Public Functions
26+
27+
public extension SmartCropTransform {
28+
/// Adds the `mode` option.
29+
///
30+
/// - Parameter value: When `face` value is used, we will run face detection on the input image in order to provide
31+
/// best results if faces are present. You can specify `object` to crop the image against a particular object,
32+
/// for example `dog`.
33+
@discardableResult
34+
func mode(_ value: TransformSmartCropMode) -> Self {
35+
return appending(key: "mode", value: value)
36+
}
37+
38+
/// Adds the `width` option.
39+
///
40+
/// - Parameter value: Width of the output image.
41+
@discardableResult
42+
func width(_ value: Int) -> Self {
43+
return appending(key: "width", value: value)
44+
}
45+
46+
/// Adds the `height` option.
47+
///
48+
/// - Parameter value: Height of the output image.
49+
@discardableResult
50+
func height(_ value: Int) -> Self {
51+
return appending(key: "height", value: value)
52+
}
53+
54+
/// Adds the `fillColor` option.
55+
///
56+
/// - Parameter value: Sets the color used for filling the bars that appear when the image is cropped.
57+
@discardableResult
58+
func fillColor(_ value: UIColor) -> Self {
59+
return appending(key: "fill_color", value: value.hexString)
60+
}
61+
62+
/// Adds the `coords` option.
63+
///
64+
/// - Parameter value: If true, it returns the coordinates of the cropped area in the image.
65+
@discardableResult
66+
func coords(_ value: Bool) -> Self {
67+
return appending(key: "coords", value: value)
68+
}
69+
}

Tests/FilestackSDKTests/TransformableTests.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,54 @@ class TransformableTests: XCTestCase {
466466
XCTAssertEqual(transformable.url, expectedURL)
467467
}
468468

469+
func testSmartCropTransformationWithModeAutoURL() {
470+
transformable.add(transform: SmartCropTransform()
471+
.mode(.auto)
472+
.fillColor(.white)
473+
.width(512)
474+
.height(512)
475+
.coords(false)
476+
)
477+
478+
let expectedURL = Constants.cdnURL
479+
.appendingPathComponent("smart_crop=mode:auto,fill_color:FFFFFFFF,width:512,height:512,coords:false")
480+
.appendingPathComponent("MY-HANDLE")
481+
482+
XCTAssertEqual(transformable.url, expectedURL)
483+
}
484+
485+
func testSmartCropTransformationWithModeObjectURL() {
486+
transformable.add(transform: SmartCropTransform()
487+
.mode(.object(name: "dog"))
488+
.fillColor(.white)
489+
.width(512)
490+
.height(512)
491+
.coords(false)
492+
)
493+
494+
let expectedURL = Constants.cdnURL
495+
.appendingPathComponent("smart_crop=mode:object,object:dog,fill_color:FFFFFFFF,width:512,height:512,coords:false")
496+
.appendingPathComponent("MY-HANDLE")
497+
498+
XCTAssertEqual(transformable.url, expectedURL)
499+
}
500+
501+
func testSmartCropTransformationWithModeFaceURL() {
502+
transformable.add(transform: SmartCropTransform()
503+
.mode(.face)
504+
.fillColor(.white)
505+
.width(512)
506+
.height(512)
507+
.coords(false)
508+
)
509+
510+
let expectedURL = Constants.cdnURL
511+
.appendingPathComponent("smart_crop=mode:face,fill_color:FFFFFFFF,width:512,height:512,coords:false")
512+
.appendingPathComponent("MY-HANDLE")
513+
514+
XCTAssertEqual(transformable.url, expectedURL)
515+
}
516+
469517
func testPixelateFacesTransformationURL() {
470518
transformable.add(transform: PixelateFacesTransform()
471519
.faces([3])

0 commit comments

Comments
 (0)