A drop in single image picker.

Overview

PHSingleImagePicker

A low memory, single image picker wrapper that provide a significant smaller file size while also preserve high image quality.

Introduction

Image file size โ‰  memory size after rendering. Eg: We have a png image with file size 3.4MB and resolution 3000x4000 File size: 3.4MB Memory size to render that image: 3000x4000x4 ~= 46MB For more info, please see WWDC2018's Video We attempt to solve both file size and memory size without sacrifice much quality.

Inspired by: โ€ข Using PHPickerViewController Images in a Memory-Efficient Way โ€ข try! Swift NYC 2019 - The Life of an Image on iOS

Requirement

If you need camera usage, please include NSCameraUsageDescription key in plist. Below iOS 14, please include NSPhotoLibraryUsageDescription key in plist.

Usage


let imagePicker = PHSingleImagePickerManager.shared
// Optional: Default is 2_000 which mean image width and height cannot reach more than 2_000
imagePicker.preferredMaxSize = 2_000
imagePicker.show(.photoLibrary, on: self) { result in
  switch result {
  case .failure(let error):
    // Show message bar here

  case .success(let value):
    let data = value.data
    let filename = value.name
    let image = UIImage(data: data)
  }
}
    

Note: Please use data in success block to upload to server instead of image?.pngData() or image?.jpegData(compressionQuality: ??) . If need to display image, we can convert that image data to image using UIImage(data: data).

Localize error message

extension PHSingleImagePickerManagerError {
  var message: String {
     switch self {
     case .downsamplingFailure:
       return "imagepicker_downsamplingFailure"
     case .noCamera:
       return "imagepicker_noCamera"
     case .noCameraPermission:
       return "imagepicker_noCameraPermission"
     case .noPhotoLibraryPermission:
       return "imagepicker_noPhotoLibraryPermission"
     case .unknown:
       return "imagepicker_unknown"
     }
   }
}

Swift Package Manager

From Xcode menu bar:

  1. File
  2. Swift Packages
  3. Add Package Dependency...
  4. Paste the repo url https://github.com/PhanithNY/PHSingleImagePicker.git

Or just drop files in Sources folder into your project.

You might also like...
MICountryPicker is a country picker controller for iOS8+ with an option to search.
MICountryPicker is a country picker controller for iOS8+ with an option to search.

MICountryPicker MICountryPicker is a country picker controller for iOS8+ with an option to search. The list of countries is based on the ISO 3166 coun

A simple, customizable Country picker for picking country or dialing code. ๐Ÿ‡ฎ๐Ÿ‡ณ ๐Ÿ‡ฏ๐Ÿ‡ต ๐Ÿ‡ฐ๐Ÿ‡ท ๐Ÿ‡ฉ๐Ÿ‡ช ๐Ÿ‡จ๐Ÿ‡ณ ๐Ÿ‡บ๐Ÿ‡ธ ๐Ÿ‡ซ๐Ÿ‡ท ๐Ÿ‡ช๐Ÿ‡ธ ๐Ÿ‡ฎ๐Ÿ‡น ๐Ÿ‡ท๐Ÿ‡บ ๐Ÿ‡ฌ๐Ÿ‡ง Multi-picker for iOS and Mac available in SwiftUI
Multi-picker for iOS and Mac available in SwiftUI

Multi-picker for iOS and Mac available in Swift UI

iOS/macOS media picker for importing images and videos in SwiftUI

iOS/macOS media picker for importing images and videos in SwiftUI.

A simple yet customizable horizontal and vertical picker view
A simple yet customizable horizontal and vertical picker view

WheelPicker A simple yet customizable horizontal and vertical picker view Features Vertical or Horizontal picker Image or Text data Configure UILabel

A SwiftUI implementation of a picker that also allows direct input.
A SwiftUI implementation of a picker that also allows direct input.

ComboPicker ComboPicker is a SwiftUI view that allows users to input a value by selecting from a predefined set or by typing a custom one. Installatio

LocationPicker - A ready for use and fully customizable location picker for your app
LocationPicker - A ready for use and fully customizable location picker for your app

LocationPicker A ready for use and fully customizable location picker for your app. Features Installation Cocoapods Carthage Swift Package Manager Qui

McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.
McPicker is a customizable, closure driven UIPickerView drop-in solution with animations that is rotation ready.

McPicker About McPicker is a UIPickerView drop-in solution with animations that is rotation ready. The more string arrays you pass, the more picker co

A ฮผlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and emoji.

CountryKit CountryKit A ฮผlibrary in Swift containing all the countries with their localized name, ISO code, phone code, country code, flag image and e

Owner
Phanith NY
Solo iOS Developer.
Phanith NY
A SwiftUI List Picker to replace system Picker in List

BetterListPicker An alternative customizable list picker in order to replace built-in non customizable Picker when we write settings view codes. Demo

Jinya 1 Apr 11, 2022
A better SwiftUI Picker Use _Picker instead of Picker

BetterPicker A better SwiftUI Picker. Use _Picker instead of Picker. Create styles with _PickerStyle. The is a WIP This library is currently a work-in

Eric Lewis 17 Dec 14, 2022
FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

FYPhoto is a photo/video picker and image browser library for iOS written in pure Swift. It is feature-rich and highly customizable to match your App's requirements.

null 10 Dec 11, 2022
Convert Countries, Country Codes, Continents,... with a single line of code.

iOS ยท macOS ยท watchOS ยท tvOS A pure Swift library that allows you to easily convert Countries to Country Codes and Country Codes to Countries. There i

Novem 1 Feb 22, 2022
Date picker dialog for iOS

DatePickerDialog 4.0 - iOS - Swift DatePickerDialog is an iOS drop-in classe that displays an UIDatePicker within an UIAlertView. Requirements DatePic

Squimer 535 Dec 17, 2022
a picker view shown as a popup for iOS in Objective-C

CZPicker Demo Change Log 3 most recent changes are listed here. Full change logs v0.4.3 - 2016-08-12 Added - (void)czpickerViewWillDisplay:(CZPickerVi

Chen Zeyu 527 Oct 2, 2022
๐ŸŽฏ Swift country and phone code Picker

CountryPicker Picker code Swift 3 / 4 / 5. Example To run the example project, clone the repo, and run pod install from the Example directory first. U

null 207 Dec 22, 2022
An iOS picker view to serve all your "picking" needs

Mandoline The PickerView is a UICollectionView that provides a smooth "picking" interface. In order to get the most out of it, a consuming view contro

Blue Apron 883 Nov 28, 2022
Elegant and Easy-to-Use iOS Swift Date Picker

D2PDatePicker Example To run the example project, clone the repo, and run pod install from the Example directory first. Example Code: Programmatical I

Pradheep Rajendirane 292 Nov 6, 2022
A country picker view controller for iOS

Planet A country picker view controller for iOS. Installation CocoaPods You can use CocoaPods to install Planet by adding it to your Podfile: platform

kWallet 71 Jul 11, 2022