damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

Readme.md (2068B)


      1 # BlurHash for iOS, in Swift
      2 
      3 ## Standalone decoder and encoder
      4 
      5 [BlurHashDecode.swift](BlurHashDecode.swift) and [BlurHashEncode.swift](BlurHashEncode.swift) contain a decoder
      6 and encoder for BlurHash to and from `UIImage`. Both files are completeiy standalone, and can simply be copied into your
      7 project directly.
      8 
      9 ### Decoding
     10 
     11 [BlurHashDecode.swift](BlurHashDecode.swift) implements the following extension on `UIImage`:
     12 
     13 	public convenience init?(blurHash: String, size: CGSize, punch: Float = 1)
     14 
     15 This creates a UIImage containing the placeholder image decoded from the BlurHash string, or returns nil if decoding failed.
     16 The parameters are:
     17 
     18 * `blurHash` - A string containing the BlurHash.
     19 * `size` - The requested output size. You should keep this small, and let UIKit scale it up for you. 32 pixels wide is plenty.
     20 * `punch` - Adjusts the contrast of the output image. Tweak it if you want a different look for your placeholders.
     21 
     22 ### Encoding
     23 
     24  [BlurHashEncode.swift](BlurHashEncode.swift) implements the following extension on `UIImage`:
     25 
     26 	public func blurHash(numberOfComponents components: (Int, Int)) -> String?
     27 
     28 This returns a string containing the BlurHash for the image, or nil if the image was in a weird format that is not supported.
     29 The parameters are:
     30 
     31 * `numberOfComponents` - a Tuple of integers specifying the number of components in the X and Y directions. Both must be
     32 between 1 and 9 inclusive, or the function will return nil.  3 to 5 is usually a good range.
     33 
     34 ## BlurHashKit
     35 
     36 This is a more advanced library, currently in development. It will let you do more advanced operations using BlurHashes,
     37 such testing whether various parts of an image are dark and light, or generating BlurHashes as gradients from corner colours.
     38 
     39 It is currently not documented or finalised, but feel free to look into the different files and what they implement, or look at
     40 how it is used by the test app.
     41 
     42 ## BlurHashTest.app
     43 
     44 This is a simple test app that shows how to use the various pieces of BlurHash functionality, and lets you play with the
     45 algorithm.