Skip to content

Commit

Permalink
Modify read local jpg image.
Browse files Browse the repository at this point in the history
  • Loading branch information
mittsu333 committed Jul 10, 2016
1 parent 04164f9 commit c85e6a0
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 23 deletions.
4 changes: 0 additions & 4 deletions Example/MarkedView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
78E0847CA3C2DD3D639695F6 /* Pods_MarkedView_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 323B000838FA6A78F40E8A40 /* Pods_MarkedView_Tests.framework */; };
893CB26B1CBA882700E10DEE /* UIMarkedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 893CB2691CBA882700E10DEE /* UIMarkedController.swift */; };
893CB26C1CBA882700E10DEE /* WKMarkedController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 893CB26A1CBA882700E10DEE /* WKMarkedController.swift */; };
8949F6501CC7A6800002E6A6 /* GitHub-Mark-120px-plus.png in Resources */ = {isa = PBXBuildFile; fileRef = 8949F64E1CC7A6800002E6A6 /* GitHub-Mark-120px-plus.png */; };
8949F6511CC7A6800002E6A6 /* sample.md in Sources */ = {isa = PBXBuildFile; fileRef = 8949F64F1CC7A6800002E6A6 /* sample.md */; };
8949F6521CC7AD970002E6A6 /* sample.md in Resources */ = {isa = PBXBuildFile; fileRef = 8949F64F1CC7A6800002E6A6 /* sample.md */; };
EEC1408B9FBE3FEF2F61CA89 /* Pods_MarkedView_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 48E3CE3BC7E3B409C0964FDF /* Pods_MarkedView_Example.framework */; };
Expand Down Expand Up @@ -51,7 +50,6 @@
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
893CB2691CBA882700E10DEE /* UIMarkedController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIMarkedController.swift; sourceTree = "<group>"; };
893CB26A1CBA882700E10DEE /* WKMarkedController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WKMarkedController.swift; sourceTree = "<group>"; };
8949F64E1CC7A6800002E6A6 /* GitHub-Mark-120px-plus.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "GitHub-Mark-120px-plus.png"; sourceTree = "<group>"; };
8949F64F1CC7A6800002E6A6 /* sample.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; path = sample.md; sourceTree = "<group>"; };
A61629B24CB9FF687C066251 /* Pods-MarkedView_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MarkedView_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-MarkedView_Example/Pods-MarkedView_Example.debug.xcconfig"; sourceTree = "<group>"; };
DCBC3074E186C6F1C33215A6 /* Pods-MarkedView_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MarkedView_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-MarkedView_Example/Pods-MarkedView_Example.release.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -171,7 +169,6 @@
8949F64D1CC7A6800002E6A6 /* sample_data */ = {
isa = PBXGroup;
children = (
8949F64E1CC7A6800002E6A6 /* GitHub-Mark-120px-plus.png */,
8949F64F1CC7A6800002E6A6 /* sample.md */,
);
path = sample_data;
Expand Down Expand Up @@ -277,7 +274,6 @@
files = (
8949F6521CC7AD970002E6A6 /* sample.md in Resources */,
607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */,
8949F6501CC7A6800002E6A6 /* GitHub-Mark-120px-plus.png in Resources */,
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */,
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */,
);
Expand Down
19 changes: 19 additions & 0 deletions Example/MarkedView/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string></string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
Expand All @@ -20,8 +22,25 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSApplicationCategoryType</key>
<string></string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>tk2-212-15794.vs.sakura.ne.jp</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionRequiresForwardSecrecy</key>
<false/>
</dict>
</dict>
</dict>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
Expand Down
24 changes: 19 additions & 5 deletions Example/MarkedView/sample_data/sample.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
## MarkedView Example
---

![sample_sc](./GitHub-Mark-120px-plus.png)
[![Version](https://img.shields.io/cocoapods/v/MarkedView.svg?style=flat)](http://cocoadocs.org/docsets/MarkedView)
[![License](https://img.shields.io/cocoapods/l/MarkedView.svg?style=flat)](http://cocoadocs.org/docsets/MarkedView)
[![Platform](https://img.shields.io/cocoapods/p/MarkedView.svg?style=flat)](http://cocoadocs.org/docsets/MarkedView)


![sample_sc](http://tk2-212-15794.vs.sakura.ne.jp/sample/oss-imgs/marked-sample-img.png)


## Introduction
---


The MarkedView is the markdown text viewer.

select the best one from UIWebview or WKWebview.
Expand All @@ -22,11 +28,12 @@ select the best one from UIWebview or WKWebview.
## Usage
---

The same process except the initialization.

Call is available from any text from any file .
It is a simple module, which enable you to convert any files into initialized view.

```

```swift
// Swift
import MarkedView

・・・
Expand Down Expand Up @@ -63,7 +70,14 @@ Then run the following command:
$ pod install
```

## License
## See Also
---

* MarkedView-for-Android
https://github.com/mittsuu/MarkedView-for-Android


## License


MarkedView is available under the MIT license. See the LICENSE file for more info.
36 changes: 29 additions & 7 deletions Pod/Classes/ConversionMDFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,39 @@ internal class ConversionMDFormat {
if !imgPath.pathExtensionCheck || imgPath.urlPatternCheck {
continue
}
let image = UIImage(named: imgPath.getFileName)!
let imageData = UIImagePNGRepresentation(image)
let base64String = imageData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
let dataScPath = "data:image/png;base64," + base64String
var pathOpti = dataScPath.stringByReplacingOccurrencesOfString("\n", withString: "")
pathOpti = pathOpti.stringByReplacingOccurrencesOfString("\r", withString: "")

newMdText = newMdText.stringByReplacingOccurrencesOfString(imgPath, withString: pathOpti)
guard let path = type2Path(imgPath.pathExtension, imgPath: imgPath) else {
continue
}
newMdText = newMdText.stringByReplacingOccurrencesOfString(imgPath, withString: path)
}

return newMdText
}

private func type2Path(imgExt: String!, imgPath: String!) -> String? {
var dataImgPath = ""

if imgExt == "jpg" || imgExt == "jpeg" {
let image = UIImage(named: imgPath)!
let imageData = UIImageJPEGRepresentation(image, 1)
let base64String = imageData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
dataImgPath = "data:image/jpg;base64," + base64String

} else if imgExt == "png" {
let image = UIImage(named: imgPath)!
let imageData = UIImagePNGRepresentation(image)
let base64String = imageData!.base64EncodedStringWithOptions(.Encoding64CharacterLineLength)
dataImgPath = "data:image/png;base64," + base64String
}

if dataImgPath == "" {
return nil

} else {
var pathOpti = dataImgPath.stringByReplacingOccurrencesOfString("\n", withString: "")
return pathOpti.stringByReplacingOccurrencesOfString("\r", withString: "")
}
}

}
9 changes: 2 additions & 7 deletions Pod/Classes/extentions/StringEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,8 @@ extension String {

var pathExtensionCheck: Bool {
return str2Ns().pathExtension == "png"
// || str2Ns().pathExtension == "jpg"
// || str2Ns().pathExtension == "jpeg"
}

var getFileName: String {
return self.lastPathComponent
.stringByReplacingOccurrencesOfString(".\(self.pathExtension)", withString: "")
|| str2Ns().pathExtension == "jpg"
|| str2Ns().pathExtension == "jpeg"
}

}

0 comments on commit c85e6a0

Please sign in to comment.