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
77 changes: 22 additions & 55 deletions Example/Mozi.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

/* Begin PBXFileReference section */
4EF9C40AF24048DE7DE7B981 /* Pods-Mozi_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mozi_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Mozi_Example/Pods-Mozi_Example.release.xcconfig"; sourceTree = "<group>"; };
54C7058831FE3851E974074F /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
54C7058831FE3851E974074F /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
607FACD01AFB9204008FA782 /* Mozi_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mozi_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
Expand All @@ -40,10 +40,10 @@
607FACE51AFB9204008FA782 /* Mozi_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Mozi_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
64B24FE5921F66910A0AD438 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; name = README.md; path = ../README.md; sourceTree = "<group>"; };
64B24FE5921F66910A0AD438 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
8B869EAE1B76161E3E727EFB /* Pods-Mozi_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mozi_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Mozi_Example/Pods-Mozi_Example.debug.xcconfig"; sourceTree = "<group>"; };
9E0961D381AA9ADDE7D8DA92 /* Pods-Mozi_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mozi_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Mozi_Tests/Pods-Mozi_Tests.debug.xcconfig"; sourceTree = "<group>"; };
BA1EDB9AADD36237EAE7BF06 /* Mozi.podspec */ = {isa = PBXFileReference; includeInIndex = 1; name = Mozi.podspec; path = ../Mozi.podspec; sourceTree = "<group>"; };
BA1EDB9AADD36237EAE7BF06 /* Mozi.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = Mozi.podspec; path = ../Mozi.podspec; sourceTree = "<group>"; };
BF942826D2D1AC022CDD118E /* Pods-Mozi_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Mozi_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Mozi_Tests/Pods-Mozi_Tests.release.xcconfig"; sourceTree = "<group>"; };
D1C9F2952F47055715178369 /* Pods_Mozi_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Mozi_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
F6FB59DF4DDCD1D39EFC2717 /* Pods_Mozi_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Mozi_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -171,7 +171,6 @@
607FACCD1AFB9204008FA782 /* Frameworks */,
607FACCE1AFB9204008FA782 /* Resources */,
C92F3A3CC12957D6D6DDD37F /* [CP] Embed Pods Frameworks */,
A990A5F84B66F16A5770A010 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -190,8 +189,6 @@
607FACE11AFB9204008FA782 /* Sources */,
607FACE21AFB9204008FA782 /* Frameworks */,
607FACE31AFB9204008FA782 /* Resources */,
D3B6576E3E9762CB402AD066 /* [CP] Embed Pods Frameworks */,
33ACA833D0B2CD65305A6C19 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -215,10 +212,12 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = H4PQW37M3H;
LastSwiftMigration = 0820;
};
607FACE41AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = H4PQW37M3H;
LastSwiftMigration = 0820;
TestTargetID = 607FACCF1AFB9204008FA782;
};
Expand Down Expand Up @@ -264,49 +263,22 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
33ACA833D0B2CD65305A6C19 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Mozi_Tests/Pods-Mozi_Tests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
59CFB2B015CBA84AFE80F1A7 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Mozi_Example-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
A990A5F84B66F16A5770A010 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Mozi_Example/Pods-Mozi_Example-resources.sh\"\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
C92F3A3CC12957D6D6DDD37F /* [CP] Embed Pods Frameworks */ = {
Expand All @@ -315,43 +287,34 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-Mozi_Example/Pods-Mozi_Example-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Mozi/Mozi.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Mozi.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Mozi_Example/Pods-Mozi_Example-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
D3B6576E3E9762CB402AD066 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Mozi_Tests/Pods-Mozi_Tests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
DCB842BEEDCB5672742A17D5 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Mozi_Tests-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
Expand Down Expand Up @@ -496,10 +459,11 @@
baseConfigurationReference = 8B869EAE1B76161E3E727EFB /* Pods-Mozi_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = H4PQW37M3H;
INFOPLIST_FILE = Mozi/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = bieshixuan.test;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
Expand All @@ -510,10 +474,11 @@
baseConfigurationReference = 4EF9C40AF24048DE7DE7B981 /* Pods-Mozi_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = H4PQW37M3H;
INFOPLIST_FILE = Mozi/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_BUNDLE_IDENTIFIER = bieshixuan.test;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
Expand All @@ -523,6 +488,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = 9E0961D381AA9ADDE7D8DA92 /* Pods-Mozi_Tests.debug.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = H4PQW37M3H;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand All @@ -543,6 +509,7 @@
isa = XCBuildConfiguration;
baseConfigurationReference = BF942826D2D1AC022CDD118E /* Pods-Mozi_Tests.release.xcconfig */;
buildSettings = {
DEVELOPMENT_TEAM = H4PQW37M3H;
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Mozi: a512b400fa783de4298a9b8ba38be78c6c22a0b8
Mozi: bba2da98cfd0702e3033cbd96a8f915347c0552b

PODFILE CHECKSUM: 26db4f5ccc1e18146a433dcac762769a00843555

COCOAPODS: 1.2.1
COCOAPODS: 1.5.2
55 changes: 19 additions & 36 deletions Mozi/Classes/Mozi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by iCell on 01/06/2017.
//
//
import UIKit

enum WidthType {
case small(minValue: CGFloat, maxValue: CGFloat)
Expand Down Expand Up @@ -34,7 +35,7 @@ enum WidthType {
case .large(let minV, let maxV):
return (minV: minV / 4, maxV: maxV / 4, size: max(100, ((minV / 4) * (maxV / 4)) / pow(10240 / 4, 2) * 300))
case .giant(let minV, let maxV):
let multiple = ((maxV / 1280) == 0) ? 1 : (maxV / 1280)
let multiple = (Int(maxV / 1280) == 0) ? 1 : (maxV / 1280)
return (minV: minV / multiple, maxV: maxV / multiple, size: max(100, ((minV / multiple) * (maxV / multiple)) / pow(2560, 2) * 300))
}
}
Expand All @@ -52,14 +53,14 @@ enum SizeType {
let ratio = minV / maxV

if ratio > 0 && ratio <= 0.5 {
// [1:1 ~ 9:16)
self = .square(minValue: minV, maxValue: maxV)
// [1:2 ~ 1:∞)
self = .rectangle(minValue: minV, maxValue: maxV)
} else if ratio > 0.5 && ratio < 0.5625 {
// [9:16 ~ 1:2)
self = .other(minValue: minV, maxValue: maxV)
} else if ratio >= 0.5625 && ratio <= 1 {
// [1:2 ~ 1:∞)
self = .rectangle(minValue: minV, maxValue: maxV)
// [1:1 ~ 9:16)
self = .square(minValue: minV, maxValue: maxV)
} else {
return nil
}
Expand All @@ -71,7 +72,7 @@ enum SizeType {
let widthType = WidthType.init(minV: minV, maxV: maxV)
return widthType.size
case .rectangle(let minV, let maxV):
let multiple = ((maxV / 1280) == 0) ? 1 : (maxV / 1280)
let multiple = (Int(minV / 1280) == 0) ? 1 : (minV / 1280)
let size = max(100, ((minV / multiple) * (maxV / multiple)) / (1440 * 2560) * 400)
return (minV: minV / multiple, maxV: maxV / multiple, size: size)
case .other(let minV, let maxV):
Expand All @@ -85,48 +86,30 @@ enum SizeType {

extension UIImage {
public func compressedImage() -> UIImage {
if let imgData = UIImageJPEGRepresentation(self, 1) {
let imgFileSize = imgData.count
print("origin file size: \(imgFileSize)")

if let type = SizeType.init(size: self.size) {
let compressSize = type.size.size
let resizedImage = resizeTo(size: CGSize(width: type.size.minV, height: type.size.maxV))
if let data = resizedImage.compressTo(size: compressSize) {
print("compressed file size: \(data.count)")
return UIImage(data: data) ?? self
}
if let type = SizeType.init(size: self.size) {
let compressSize = type.size.size
let resizedImage = resizeTo(size: CGSize(width: type.size.minV, height: type.size.maxV))
if let data = resizedImage.compressTo(size: compressSize) {
return UIImage(data: data) ?? self
}
}
return self
}

public func compressedData() -> Data? {
if let imgData = UIImageJPEGRepresentation(self, 1) {
let imgFileSize = imgData.count
print("origin file size: \(imgFileSize)")

if let type = SizeType.init(size: self.size) {
let compressSize = type.size.size
let resizedImage = resizeTo(size: CGSize(width: type.size.minV, height: type.size.maxV))
if let data = resizedImage.compressTo(size: compressSize) {
print("compressed file size: \(data.count)")
return data
}
if let type = SizeType.init(size: self.size) {
let compressSize = type.size.size
let resizedImage = resizeTo(size: CGSize(width: type.size.minV, height: type.size.maxV))
if let data = resizedImage.compressTo(size: compressSize) {
return data
}
}
return nil
}

public func resizeTo(size: CGSize) -> UIImage {
let ratio = self.size.height / self.size.width
var factor: CGFloat = 1.0
if ratio > 1 {
factor = size.height / size.width
} else {
factor = size.width / size.height
}
let toSize = CGSize(width: self.size.width * factor, height: self.size.height * factor)
let isV = self.size.height > self.size.width
let toSize = isV ? size : CGSize.init(width: size.height, height: size.width)

UIGraphicsBeginImageContext(toSize)
draw(in: CGRect.init(origin: CGPoint(x: 0, y: 0), size: toSize))
Expand Down