Coder Social home page Coder Social logo

sdwebimage / sdwebimagephotosplugin Goto Github PK

View Code? Open in Web Editor NEW
57.0 57.0 7.0 437 KB

A SDWebImage plugin to support Photos framework image loading

License: MIT License

Ruby 3.13% Objective-C 94.82% Swift 2.05%
cocoapods ios macos objective-c photoslibrary sdwebimage tvos

sdwebimagephotosplugin's Introduction

Build Status Pod Version Pod Platform Pod License Carthage compatible SwiftPM compatible Mac Catalyst compatible codecov

This library provides an async image downloader with cache support. For convenience, we added categories for UI elements like UIImageView, UIButton, MKAnnotationView.

Note: SD is the prefix for Simple Design (which is the team name in Daily Motion company from the author Olivier Poitrey)

Features

For Apple visionOS

From 5.19+, SDWebImage supports visionOS on all Package Managers (include CocoaPods/Carthage/SPM). Upgrade the related tools if you're facing issues.

For 5.18+, SDWebImage can be compiled for visionOS platform. However, it's still in beta and may contains issues unlike the stable iOS UIKit support. Welcome to have a try and report issue.

To build on visionOS, currently we only support the standard Xcode integration.

See Installation with Swift Package Manager and Manual Installation Guide below.

Supported Image Formats

  • Image formats supported by Apple system (JPEG, PNG, TIFF, BMP, ...), including GIF/APNG animated image
  • HEIC format from iOS 11/macOS 10.13, including animated HEIC from iOS 13/macOS 10.15 via SDWebImageHEICCoder. For lower firmware, use coder plugin SDWebImageHEIFCoder
  • WebP format from iOS 14/macOS 11.0 via SDWebImageAWebPCoder. For lower firmware, use coder plugin SDWebImageWebPCoder
  • JPEG-XL format from iOS 17/macOS 14.0 built-in. For lower firmware, use coder plugin SDWebImageJPEGXLCoder
  • Support extendable coder plugins for new image formats like BPG, AVIF. And vector format like PDF, SVG. See all the list in Image coder plugin List

Additional modules and Ecosystem

In order to keep SDWebImage focused and limited to the core features, but also allow extensibility and custom behaviors, during the 5.0 refactoring we focused on modularizing the library. As such, we have moved/built new modules to SDWebImage org.

SwiftUI

SwiftUI is an innovative UI framework written in Swift to build user interfaces across all Apple platforms.

We support SwiftUI by building a brand new framework called SDWebImageSwiftUI, which is built on top of SDWebImage core functions (caching, loading and animation).

The new framework introduce two View structs WebImage and AnimatedImage for SwiftUI world, ImageIndicator modifier for any View, ImageManager observable object for data source. Supports iOS 13+/macOS 10.15+/tvOS 13+/watchOS 6+ and Swift 5.1. Have a nice try and provide feedback!

Coders for additional image formats

Custom Caches

Custom Loaders

  • SDWebImagePhotosPlugin - plugin to support loading images from Photos (using Photos.framework)
  • SDWebImageLinkPlugin - plugin to support loading images from rich link url, as well as LPLinkView (using LinkPresentation.framework)

Integration with 3rd party libraries

Community driven popular libraries

  • FirebaseUI - Firebase Storage binding for query images, based on SDWebImage loader system
  • react-native-fast-image - React Native fast image component, based on SDWebImage Animated Image solution
  • flutter_image_compress - Flutter compresses image plugin, based on SDWebImage WebP coder plugin

Make our lives easier

You can use those directly, or create similar components of your own, by using the customizable architecture of SDWebImage.

Requirements

  • iOS 9.0 or later
  • tvOS 9.0 or later
  • watchOS 2.0 or later
  • macOS 10.11 or later (10.15 for Catalyst)
  • visionOS 1.0 or later
  • Xcode 14.0 or later (visionOS requires Xcode 15.0)

Backwards compatibility

Getting Started

Who Uses It

Communication

  • If you need help, use Stack Overflow. (Tag 'sdwebimage')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you need IRC channel, use Gitter.

Contribution

How To Use

  • Objective-C
#import <SDWebImage/SDWebImage.h>
...
[imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
             placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
  • Swift
import SDWebImage

imageView.sd_setImage(with: URL(string: "http://www.domain.com/path/to/image.jpg"), placeholderImage: UIImage(named: "placeholder.png"))

Animated Images (GIF) support

In 5.0, we introduced a brand new mechanism for supporting animated images. This includes animated image loading, rendering, decoding, and also supports customizations (for advanced users).

This animated image solution is available for iOS/tvOS/macOS. The SDAnimatedImage is subclass of UIImage/NSImage, and SDAnimatedImageView is subclass of UIImageView/NSImageView, to make them compatible with the common frameworks APIs.

The SDAnimatedImageView supports the familiar image loading category methods, works like drop-in replacement for UIImageView/NSImageView.

Don't have UIView (like WatchKit or CALayer)? you can still use SDAnimatedPlayer the player engine for advanced playback and rendering.

See Animated Image for more detailed information.

  • Objective-C
SDAnimatedImageView *imageView = [SDAnimatedImageView new];
SDAnimatedImage *animatedImage = [SDAnimatedImage imageNamed:@"image.gif"];
imageView.image = animatedImage;
  • Swift
let imageView = SDAnimatedImageView()
let animatedImage = SDAnimatedImage(named: "image.gif")
imageView.image = animatedImage

FLAnimatedImage integration has its own dedicated repo

In order to clean up things and make our core project do less things, we decided that the FLAnimatedImage integration does not belong here. From 5.0, this will still be available, but under a dedicated repo SDWebImageFLPlugin.

Installation

There are 5 ways to use SDWebImage in your project:

  • using CocoaPods
  • using Carthage
  • using Swift Package Manager
  • download binary XCFramework
  • manual install (build frameworks or embed Xcode Project)

Installation with CocoaPods

CocoaPods is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the Get Started section for more details.

Podfile

platform :ios, '8.0'
pod 'SDWebImage', '~> 5.0'
Swift and static framework

Swift project previously had to use use_frameworks! to make all Pods into dynamic framework to let CocoaPods work.

However, starting with CocoaPods 1.5.0+ (with Xcode 9+), which supports to build both Objective-C && Swift code into static framework. You can use modular headers to use SDWebImage as static framework, without the need of use_frameworks!:

platform :ios, '8.0'
# Uncomment the next line when you want all Pods as static framework
# use_modular_headers!
pod 'SDWebImage', :modular_headers => true

See more on CocoaPods 1.5.0 — Swift Static Libraries

If not, you still need to add use_frameworks! to use SDWebImage as dynamic framework:

platform :ios, '8.0'
use_frameworks!
pod 'SDWebImage'

Subspecs

There are 2 subspecs available now: Core and MapKit (this means you can install only some of the SDWebImage modules. By default, you get just Core, so if you need MapKit, you need to specify it).

Podfile example:

pod 'SDWebImage/MapKit'

Installation with Carthage

Carthage is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods.

To install with carthage, follow the instruction on Carthage

Carthage users can point to this repository and use whichever generated framework they'd like: SDWebImage, SDWebImageMapKit or both.

Make the following entry in your Cartfile: github "SDWebImage/SDWebImage" Then run carthage update If this is your first time using Carthage in the project, you'll need to go through some additional steps as explained over at Carthage.

NOTE: At this time, Carthage does not provide a way to build only specific repository subcomponents (or equivalent of CocoaPods's subspecs). All components and their dependencies will be built with the above command. However, you don't need to copy frameworks you aren't using into your project. For instance, if you aren't using SDWebImageMapKit, feel free to delete that framework from the Carthage Build directory after carthage update completes.

NOTE: Apple requires SDWebImage contains signatures. So, by default the carthage build binary framework does not do codesign, this will cause validation error. You can sign yourself with the Apple Developer Program identity, or using the binary framework:

binary "https://github.com/SDWebImage/SDWebImage/raw/master/SDWebImage.json"

Installation with Swift Package Manager (Xcode 11+)

Swift Package Manager (SwiftPM) is a tool for managing the distribution of Swift code as well as C-family dependency. From Xcode 11, SwiftPM got natively integrated with Xcode.

SDWebImage support SwiftPM from version 5.1.0. To use SwiftPM, you should use Xcode 11 to open your project. Click File -> Swift Packages -> Add Package Dependency, enter SDWebImage repo's URL. Or you can login Xcode with your GitHub account and just type SDWebImage to search.

After select the package, you can choose the dependency type (tagged version, branch or commit). Then Xcode will setup all the stuff for you.

If you're a framework author and use SDWebImage as a dependency, update your Package.swift file:

let package = Package(
    // 5.1.0 ..< 6.0.0
    dependencies: [
        .package(url: "https://github.com/SDWebImage/SDWebImage.git", from: "5.1.0")
    ],
    // ...
)

Download binary XCFramework

From 5.19.2, SDWebImage provide the canonical official binary XCFramework on GitHub release pages.

  • Download XCFramework

You can choose to download SDWebImage-dynamic.xcframework.zip for dynamic linked one, or SDWebImage-static.xcframework.zip for static-linked one.

  • Integrate to Xcode Project

Drag the unzipped .xcframework into your Xcode Project's Framework tab.

  • Verify signature of binary XCFramework

From Xcode 15 Apple will verify the signature of binary XCFramework, to avoid supply chain attack.

The fingerprint currently should be FC 3B 10 13 86 34 4C 50 DB 70 2A 9A D1 01 6F B5 1A 3E CC 8B 9D A9 B7 AE 47 A0 48 D4 D0 63 39 83

The certificate is stored in the repo here

The public key is stored in the repo here

See more: Verifying the origin of your XCFrameworks

Manual Installation Guide

  • Check your command line Xcode version
sudo xcode-select -s /path/to/Xcode.app

or

export DEVELOPER_DIR=/path/to/Xcode.app/Contents/Developer
  • Run the script to build frameworks
./Scripts/build-frameworks.sh
  • Run the script to merge XCFramework
./Scripts/create-xcframework.sh
  • Use your own certificate to sign XCFramework
// https://developer.apple.com/support/third-party-SDK-requirements/
codesign --timestamp -v --sign "your own certificate" SDWebImage.xcframework

See more on wiki: Manual install Guide

Import headers in your source files

In the source files where you need to use the library, import the umbrella header file:

#import <SDWebImage/SDWebImage.h>

It's also recommend to use the module import syntax, available for CocoaPods(enable modular_headers)/Carthage/SwiftPM.

@import SDWebImage;

Build Project

At this point your workspace should build without error. If you are having problem, post to the Issue and the community can help you solve it.

Data Collection Practices

From Xcode 15, we provide the new PrivacyInfo.xcprivacy file for privacy details, see Describing data use in privacy manifests

You can exports the privacy report after archive your App by integrate SDWebImage via SwiftPM/XCFramework or CocoaPods (use_frameworks set to true).

For old version or if you're using static ar archive, as required by the App privacy details on the App Store, here's SDWebImage's list of Data Collection Practices.

Author

Collaborators

Credits

Thank you to all the people who have already contributed to SDWebImage.

Contributors

Licenses

All source code is licensed under the MIT License.

Architecture

To learn about SDWebImage's architecture design for contribution, read The Core of SDWebImage v5.6 Architecture. Thanks @looseyi for the post and translation.

High Level Diagram

Overall Class Diagram

Top Level API Diagram

Main Sequence Diagram

More detailed diagrams

sdwebimagephotosplugin's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sdwebimagephotosplugin's Issues

Only support image

Only support PHAssetMediaTypeImage
pls support PHAssetMediaTypeVideo too

Support for URL instead of NSURL

New Feature Request Checklist

  • I have checked the current documentations or APIs and did not find a solution
  • I have searched for a similar issue in the project and found none

Feature Request Description

Currently, you make a NSURL from PHAsset like this:

// Create with `PHAsset`
let asset: PHAsset
let photosURL = NSURL.sd_URL(with: asset)

// Load image (assume using custom manager)
imageView.sd_setImage(with: photosURL, placeholderImage: nil, context: [.customManager: manager])

However, sd_setImage(with: takes a URL, not NSURL.

Screen Shot 2020-12-30 at 8 20 47 PM

I would like to be able to get a URL from PHAsset, something like this:

// Create with `PHAsset`
let asset: PHAsset
let photosURL = URL.sd_URL(with: asset) /// URL not NSURL

// Load image (assume using custom manager)
imageView.sd_setImage(with: photosURL, placeholderImage: nil, context: [.customManager: manager])

This would avoid the error, and I think URLs are safer than NSURLs.

Request completion block

Hi! I wonder if it is possible to get completion block after photo loading was completed for following method:
imageView.sd_setImage(with: photoURL, placeholderImage: nil, context [.photosImageRequestOptions: requestOptions])
Thanks in advance!

Does not load image in the SDAnimatedImageView (intermittent issue)

Since Photos Library image is already stored on the device disk. And query speed is fast enough for small resolution image. You can use SDWebImageContextStoreCacheType with SDImageCacheTypeNone to disable cache storage. And use SDWebImageFromLoaderOnly to disable cache query.

This does not load image sometimes in the SDAnimatedImageView.

Is it possible to have SDWebImagePhotosPlugin work with SDWebImage v.5.10.X using SPM?

New Feature Request Checklist

  • I have checked the current documentations or APIs and does not find a solution
  • I have searched for a similar issue in the project and found none
    I seem to be able to only make it work with 5.9.X. You run into the dreaded
    "The package product 'iOSAnyPackage' requires minimum platform version 9.0 for the iOS platform, but this target supports 8.0" error outlined here https://forums.swift.org/t/xcode12-minimum-deployment-target-and-spm/40467 when you update your package.
    There seem to be ways to do this using CocoaPods, but I am having trouble finding anything useful when working with SPM.

Feature Request Description

Please fill in the detailed description about feature request, including the feature use case (what you need) and the solution you want (like usage, demo code, ...)

Crashed with beta4 and beta6

Crashed with beta4 and beta6.
Example of request:

let requestOptions = PHImageRequestOptions()
requestOptions.sd_targetSize = targetSize
requestOptions.sd_contentMode = .aspectFill
requestOptions.isNetworkAccessAllowed = true

if let url = NSURL.sd_URL(with: asset) as URL? {
sd_setImage(with: url,
         placeholderImage: nil,
         context: [.photosImageRequestOptions: requestOptions,
                        .customManager: SDWebImagePhotosLoader.shared])
} else {
    sd_cancelCurrentImageLoad()
    image = nil
}

Get this crash:
crash

Extremely high memory usage and slow scrolling

New Issue Checklist

  • I have read the tutorial usage
  • I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name iOS
Platform Version 14.2
Framework Version SDWebImage (5.8.3), SDWebImagePhotosPlugin (1.1.0)
Integration Method cocoapods
Xcode Version Xcode 12
Repro rate 100%
Repro with our demo prj No
Demo project link https://github.com/aheze/PhotoLoading

Issue Description and Steps

The collection view scrolls choppily, and the memory goes over 1 gb, depending on how many photos you have. It sometimes also crashes due to Terminated due to memory error.

Screen Shot 2020-12-30 at 8 07 04 PM

I followed the example project (it's in Objective-C so I probably misread some things), first doing this inside viewDidLoad():

//Supports HTTP URL as well as Photos URL globally
SDImageLoadersManager.shared.loaders = [SDWebImageDownloader.shared, SDImagePhotosLoader.shared]

// Replace default manager's loader implementation
SDWebImageManager.defaultImageLoader = SDImageLoadersManager.shared

let options = PHImageRequestOptions()
options.sd_targetSize = CGSize(width: 500, height: 500) /// make sure don't load too big
SDImagePhotosLoader.shared.imageRequestOptions = options

Instead of an array of NSURL I used an array of PHAsset:

var allPhotos: PHFetchResult<PHAsset>? = nil
...
PHPhotoLibrary.requestAuthorization { (status) in /// request access inside ViewDidLoad
    if status == .authorized {
        let fetchOptions = PHFetchOptions()
        self.allPhotos = PHAsset.fetchAssets(with: .image, options: fetchOptions)
        DispatchQueue.main.async {
            self.collectionView.reloadData() /// reload collectionview once done
        }
    }
}

And this is my cellForRowAt. I make the NSURL here.

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseID, for: indexPath) as! CollectionViewCell
  
  let asset = allPhotos![indexPath.item]
  let photosURL = NSURL.sd_URL(with: asset)
  cell.imageView.sd_setImage(with: photosURL as URL?, placeholderImage: nil, options: SDWebImageOptions.fromLoaderOnly)
  return cell
}

My full code is all in ViewController.swift (63 lines). What am I doing wrong? Thanks for any help!

reloaddata causes image flickering

In the demo project, as in mine, when you reload the collectionview, the pictures flicker, when I reload only visible cells, this does not happen, but some cells remain not updated when scrolling. Are there any ways to solve this?

Carthage build failed

New Issue Checklist

  • I have read the tutorial usage
  • I have searched for a similar issue in the project and found none

Issue Info

Info Value
Platform Name ios
Platform Version 14.4
Framework Version 1.2.0
Integration Method carthage
Xcode Version Xcode 12.4
Repro rate all the time (100%)
Repro with our demo prj
Demo project link

Issue Description and Steps

Cartfile

github "SDWebImage/SDWebImage"
github "SDWebImage/SDWebImagePhotosPlugin"

log

carthage update --platform iOS --use-xcframeworks --cache-builds
*** Fetching SDWebImage
*** Fetching SDWebImagePhotosPlugin
*** Checking out SDWebImage at "5.11.1"
*** Checking out SDWebImagePhotosPlugin at "1.2.0"
*** xcodebuild output can be found in /var/folders/zr/4r0p2kpd4gg0thfj05jldkgc0000gn/T/carthage-xcodebuild.a4iK05.log
*** Valid cache found for SDWebImage, skipping build
*** No cache found for SDWebImagePhotosPlugin, building with all downstream dependencies
*** Building scheme "SDWebImagePhotosPlugin" in SDWebImagePhotosPlugin.xcodeproj
Build Failed
 Task failed with exit code 65:
 /usr/bin/xcrun xcodebuild -project /Users/venice/projects/CarthageTest/Carthage/Checkouts/SDWebImagePhotosPlugin/SDWebImagePhotosPlugin.xcodeproj -scheme SDWebImagePhotosPlugin -configuration Release -derivedDataPath /Users/venice/Library/Caches/org.carthage.CarthageKit/DerivedData/12.4_12D4e/SDWebImagePhotosPlugin/1.2.0 -sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive VALIDATE_WORKSPACE=NO -archivePath /var/folders/zr/4r0p2kpd4gg0thfj05jldkgc0000gn/T/SDWebImagePhotosPlugin SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO STRIP_INSTALLED_PRODUCT=NO (launched in /Users/venice/projects/CarthageTest/Carthage/Checkouts/SDWebImagePhotosPlugin)

This usually indicates that project itself failed to compile. Please check the xcodebuild log for more details: /var/folders/zr/4r0p2kpd4gg0thfj05jldkgc0000gn/T/carthage-xcodebuild.a4iK05.log
✘ venice  ~/projects/CarthageTest 

unsupported URL

2018-09-04 18:31:24.318357+0530 [1690:202387] Task <65A83068-4467-4DBA-B035-720EBB27A59A>.<7> finished with error - code: -1002
2018-09-04 18:31:24.337494+0530 [1690:202405] Task <65A83068-4467-4DBA-B035-720EBB27A59A>.<7> load failed with error Error Domain=NSURLErrorDomain Code=-1002 "unsupported URL" UserInfo={NSLocalizedDescription=unsupported URL, NSErrorFailingURLStringKey=photos://asset/82CCD013-F7E9-461F-8F36-5E3A4FCAD6BB/L0/001, NSErrorFailingURLKey=photos://asset/82CCD013-F7E9-461F-8F36-5E3A4FCAD6BB/L0/001, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <65A83068-4467-4DBA-B035-720EBB27A59A>.<7>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <65A83068-4467-4DBA-B035-720EBB27A59A>.<7>, NSUnderlyingError=0x281b02ac0 {Error Domain=kCFErrorDomainCFNetwork Code=-1002 "(null)"}} [-1002]

Support for SDWebImage 4.X

Feature Request Description

This pod should really attempt to use the stable version of SDWebImage if possible. I cannot use this even though it would be useful because I will not update my SDWebImage dependency to a beta version.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.