FMPhotoPicker
A modern, simple and zero-dependency photo picker with an elegant and customizable image editor


TAG: FMPhotoPicker , PhotoPicker , Gallery Picker , Image Picker , Crop ,Custom Picker , Swift , Edit , Filter , PhotoEditing
Licence: MIT
Classification: FMPhotoPicker
Platform: IOS
Language: Swift
Language: Swift
Device:
iPhone / iPad
Download
Installation
SwiftPM
dependencies: [
.package(url: "https://github.com/congnd/FMPhotoPicker.git", .exact("0.9.1")),
]
dependencies: [
.package(url: "https://github.com/congnd/FMPhotoPicker.git", .exact("0.9.1")),
]
Carthage
Insert the following line in your Carthfile:
git "git@github.com:congnd/FMPhotoPicker.git"
and run carthage update FMPhotoPicker
git "git@github.com:congnd/FMPhotoPicker.git"
carthage update FMPhotoPickerCocoaPods
FMPhotoPicker is now available in CocoaPods
You want to add pod 'FMPhotoPicker', '~> 0.8' similar to the following to your Podfile:
target 'MyApp' do
pod 'FMPhotoPicker', '~> 0.8'
end
Then run a pod install inside your terminal.
You want to add pod 'FMPhotoPicker', '~> 0.8' similar to the following to your Podfile:
target 'MyApp' do
pod 'FMPhotoPicker', '~> 0.8'
end
pod install inside your terminal.Usage
Create a configuration object
var config = FMPhotoPickerConfig()
For details, see Configuration
var config = FMPhotoPickerConfig()
Picker
let picker = FMPhotoPickerViewController(config: config)
picker.delegate = self
self.present(picker, animated: true)
From iOS 10, you have to add the Privacy - Photo Library Usage Description into your Info.plist file.
let picker = FMPhotoPickerViewController(config: config)
picker.delegate = self
self.present(picker, animated: true)
Privacy - Photo Library Usage Description into your Info.plist file.Editor
let editor = FMImageEditorViewController(config: config, sourceImage: image)
editor.delegate = self
self.present(editor, animated: true)
let editor = FMImageEditorViewController(config: config, sourceImage: image)
editor.delegate = self
self.present(editor, animated: true)
Delegation methods
- Implement FMPhotoPickerViewControllerDelegate protocol to handle selected images
func fmPhotoPickerController(_ picker: FMPhotoPickerViewController, didFinishPickingPhotoWith photos: [UIImage])
- Implement FMImageEditorViewControllerDelegate protocol to handle ouput image
func fmImageEditorViewController(_ editor: FMImageEditorViewController, didFinishEdittingPhotoWith photo: UIImage)
func fmPhotoPickerController(_ picker: FMPhotoPickerViewController, didFinishPickingPhotoWith photos: [UIImage])
func fmImageEditorViewController(_ editor: FMImageEditorViewController, didFinishEdittingPhotoWith photo: UIImage)
Configuration
The configuration supports the following parameters:
Reference
Customization
Custom filter
You can freely create your own filter by implementing the FMFilterable protocol.
public protocol FMFilterable {
func filter(image: UIImage) -> UIImage
func filterName() -> String
}
Be careful that the filterName is used to determine whether the two filters are the same.
Make sure that your filter's names are not duplicated, especially with the default filters that you want to use.
FMFilterable protocol.public protocol FMFilterable {
func filter(image: UIImage) -> UIImage
func filterName() -> String
}
Make sure that your filter's names are not duplicated, especially with the default filters that you want to use.
Custom cropping
Similar as filter function, FMPhotoPicker provides the capability to use your own cropping by implementing the FMCroppable protocol.
public protocol FMCroppable {
func crop(image: UIImage, toRect rect: CGRect) -> UIImage
func name(string: [String: String]) -> String
func icon() -> UIImage
func ratio() -> FMCropRatio?
}
The func name(strings: [String: String]) -> String will receive the strings configuration from configuration object. It allows you customize the cropping while keeping all your language setting in only one place.
The name() method is also used as identifier for the cropping.
Thus, make sure you do not have any duplicate of the cropping name.
FMCroppable protocol.public protocol FMCroppable {
func crop(image: UIImage, toRect rect: CGRect) -> UIImage
func name(string: [String: String]) -> String
func icon() -> UIImage
func ratio() -> FMCropRatio?
}
func name(strings: [String: String]) -> String will receive the strings configuration from configuration object. It allows you customize the cropping while keeping all your language setting in only one place.name() method is also used as identifier for the cropping.Thus, make sure you do not have any duplicate of the cropping name.
Custom alert view controller
You can use your own view style for the confirmation view by implementing the FMAlertable protocol.
public protocol FMAlertable {
func show(in viewController: UIViewController, ok: @escaping () -> Void, cancel: @escaping () -> Void)
}
FMAlertable protocol.public protocol FMAlertable {
func show(in viewController: UIViewController, ok: @escaping () -> Void, cancel: @escaping () -> Void)
}
