UIImage

class UIImage : NSObject, NSSecureCoding

This extesion adds some useful functions to UIImage.

  • Create a dummy image.

    Declaration

    Swift

    public convenience init?(dummyImage dummy: String)

    Parameters

    dummy

    This parameter must contain: 100x100, 100x100.#FFFFFF or 100x100.blue (if it is a color defined in UIColor class) if you want to define a color. Default color is lightGray.

  • Create a dummy image.

    Declaration

    Swift

    public convenience init?(width: CGFloat, height: CGFloat, color: String = "lightGray")

    Parameters

    width

    Width of dummy image.

    height

    Height of dummy image.

    color

    Color of dummy image. Can be HEX or color like blue. Default color is lightGray.

  • Create a dummy image.

    Declaration

    Swift

    public convenience init?(size: CGSize, color: String = "lightGray")
  • Create an image from a given text.

    Declaration

    Swift

    public convenience init?(text: String, font: FontName, fontSize: CGFloat, imageSize: CGSize)

    Parameters

    text

    Text.

    font

    Text font name.

    fontSize

    Text font size.

    imageSize

    Image size.

  • Create an image with a background color and with a text with a mask.

    Declaration

    Swift

    public convenience init?(maskedText: String, font: FontName, fontSize: CGFloat, imageSize: CGSize, backgroundColor: UIColor)

    Parameters

    maskedText

    Text to mask.

    font

    Text font name.

    fontSize

    Text font size.

    imageSize

    Image size.

    backgroundColor

    Image background color.

  • Create an image from a given color.

    Declaration

    Swift

    public convenience init?(color: UIColor)

    Parameters

    color

    Color value.

  • Create an image from a base64 String.

    Declaration

    Swift

    public convenience init?(base64: String)

    Parameters

    base64

    Base64 String.

  • Returns the screen scale, based on the device.

    Declaration

    Swift

    public static func screenScale() -> CGFloat

    Return Value

    Returns the screen scale, based on the device.

  • Apply the given Blend Mode.

    Declaration

    Swift

    public func blend(image: UIImage, blendMode: CGBlendMode) -> UIImage

    Parameters

    image

    Image to be added to blend.

    blendMode

    Blend Mode.

    Return Value

    Returns the image.

  • Create an image from a given rect of

    Declaration

    Swift

    public func crop(in rect: CGRect) -> UIImage

    Parameters

    rect

    Rect to take the image.

    Return Value

    Returns the image from a given rect.

  • Scale the image to the minimum given size.

    Declaration

    Swift

    public func scaleProportionally(toMinimumSize targetSize: CGSize) -> UIImage

    Parameters

    targetSize

    The size to scale to.

    Return Value

    Returns the scaled image.

  • Scale the image to the maxinum given size.

    Declaration

    Swift

    public func scaleProportionally(toMaximumSize targetSize: CGSize) -> UIImage

    Parameters

    targetSize

    The site to scale to.

    Return Value

    Returns the scaled image.

  • Scale the image proportionally to the given size.

    Declaration

    Swift

    public func scaleProportionally(toSize targetSize: CGSize) -> UIImage

    Parameters

    targetSize

    The site to scale to.

    Return Value

    Returns the scaled image.

  • Scele the image to the given size.

    Declaration

    Swift

    public func scale(toSize targetSize: CGSize) -> UIImage

    Parameters

    targetSize

    The site to scale to.

    Return Value

    Returns the scaled image.

  • Flip the image horizontally, like a mirror.

    Example: Image -> egamI.

    Declaration

    Swift

    public func flipHorizontally() -> UIImage

    Return Value

    Returns the flipped image.

  • Flip the image vertically.

    Example: Image -> Iɯɐƃǝ.

    Declaration

    Swift

    public func flipVertically() -> UIImage

    Return Value

    Returns the flipped image.

  • Check if the image has alpha.

    Declaration

    Swift

    public func hasAlpha() -> Bool

    Return Value

    Returns true if has alpha, otherwise false.

  • Remove the alpha of the image.

    Declaration

    Swift

    public func removeAlpha() -> UIImage

    Return Value

    Returns the image without alpha.

  • Fill the alpha with the given color.

    Default is white.

    Declaration

    Swift

    public func fillAlpha(color: UIColor = UIColor.white) -> UIImage

    Parameters

    color

    Color to fill.

    Return Value

    Returns the filled image.

  • Check if the image is in grayscale.

    Declaration

    Swift

    public func isGrayscale() -> Bool

    Return Value

    Returns true if is in grayscale, otherwise false.

  • Transform the image to grayscale.

    Declaration

    Swift

    public func toGrayscale() -> UIImage

    Return Value

    Returns the transformed image.

  • Transform the image to black and white.

    Declaration

    Swift

    public func toBlackAndWhite() -> UIImage

    Return Value

    Returns the transformed image.

  • Invert the color of the image.

    Declaration

    Swift

    public func invertColors() -> UIImage

    Return Value

    Returns the transformed image.

  • Creates an image from an UIView.

    Declaration

    Swift

    public convenience init?(view: UIView)

    Parameters

    view

    UIView.

  • Rotate the image to the given radians.

    Declaration

    Swift

    public func rotate(radians: Float) -> UIImage

    Parameters

    radians

    Radians to rotate to

    Return Value

    Returns the rotated image.

  • Rotate the image to the given degrees.

    Declaration

    Swift

    public func rotate(degrees: Float) -> UIImage

    Parameters

    degrees

    Degrees to rotate to.

    Return Value

    Returns the rotated image.

  • Apply a filter to the image. Full list of CIFilters here.

    Declaration

    Swift

    public func filter(name: String, parameters: [String: Any] = [:]) -> UIImage

    Parameters

    name

    Filter name.

    parameters

    Keys and values of the filter. A key example is kCIInputCenterKey.

    Return Value

    Returns the transformed image.

  • Apply the bloom effect to the image.

    Declaration

    Swift

    public func bloom(radius: Float, intensity: Float) -> UIImage

    Parameters

    radius

    Radius of the bloom.

    intensity

    Intensity of the bloom.

    Return Value

    Returns the transformed image.

  • Apply the bump distortion effect to the image.

    Declaration

    Swift

    public func bumpDistortion(center: CIVector, radius: Float, scale: Float) -> UIImage

    Parameters

    center

    Vector of the distortion. Use CIVector(x: X, y: Y).

    radius

    Radius of the effect.

    scale

    Scale of the effect.

    Return Value

    Returns the transformed image.

  • Apply the bump distortion linear effect to the image.

    Declaration

    Swift

    public func bumpDistortionLinear(center: CIVector, radius: Float, scale: Float, angle: Float) -> UIImage

    Parameters

    center

    Vector of the distortion. Use CIVector(x: X, y: Y).

    radius

    Radius of the effect.

    scale

    Scale of the effect.

    angle

    Angle of the effect in radians.

    Return Value

    Returns the transformed image.

  • Apply the circular splash distortion effect to the image

    Declaration

    Swift

    public func circleSplashDistortion(center: CIVector, radius: Float) -> UIImage

    Parameters

    center

    Vector of the distortion. Use CIVector(x: X, y: Y).

    radius

    Radius of the effect.

    Return Value

    Returns the transformed image.

  • Apply the circular wrap effect to the image.

    Declaration

    Swift

    public func circularWrap(center: CIVector, radius: Float, angle: Float) -> UIImage

    Parameters

    center

    Vector of the distortion. Use CIVector(x: X, y: Y).

    radius

    Radius of the effect.

    angle

    Angle of the effect in radians.

    Return Value

    Returns the transformed image.

  • Apply the CMY halftone effect to the image.

    Declaration

    Swift

    public func cmykHalftone(center: CIVector, width: Float, angle: Float, sharpness: Float, gcr: Float, ucr: Float) -> UIImage

    Parameters

    center

    Vector of the distortion. Use CIVector(x: X, y: Y).

    width

    Width value.

    angle

    Angle of the effect in radians.

    sharpness

    Sharpness Value.

    gcr

    GCR value.

    ucr

    UCR value

    Return Value

    Returns the transformed image.

  • Apply the sepia filter to the image.

    Declaration

    Swift

    public func sepiaTone(intensity: Float) -> UIImage

    Parameters

    intensity

    Intensity of the filter.

    Return Value

    Returns the transformed image.

  • Apply the blur effect to the image.

    Declaration

    Swift

    public func blur(radius blurRadius: CGFloat, saturation: CGFloat = 1.8, tintColor: UIColor? = nil, maskImage: UIImage? = nil) -> UIImage

    Parameters

    blurRadius

    Blur radius.

    saturation

    Saturation delta factor, leave it default (1.8) if you don’t what is.

    tintColor

    Blur tint color, default is nil.

    maskImage

    Apply a mask image, leave it default (nil) if you don’t want to mask.

    Return Value

    Return the transformed image.