// // UIImage+YYWebImage.h // YYWebImage // // Created by ibireme on 13/4/4. // Copyright (c) 2015 ibireme. // // This source code is licensed under the MIT-style license found in the // LICENSE file in the root directory of this source tree. // #import NS_ASSUME_NONNULL_BEGIN /** Provide some commen method for `UIImage`. Image process is based on CoreGraphic and vImage. */ @interface UIImage (YYWebImage) #pragma mark - Create image ///============================================================================= /// @name Create image ///============================================================================= /** Create an animated image with GIF data. After created, you can access the images via property '.images'. If the data is not animated gif, this function is same as [UIImage imageWithData:data scale:scale]; @discussion It has a better display performance, but costs more memory (width * height * frames Bytes). It only suited to display small gif such as animated emoticon. If you want to display large gif, see `YYImage`. @param data GIF data. @param scale The scale factor @return A new image created from GIF, or nil when an error occurs. */ + (nullable UIImage *)yy_imageWithSmallGIFData:(NSData *)data scale:(CGFloat)scale; /** Create and return a 1x1 point size image with the given color. @param color The color. */ + (nullable UIImage *)yy_imageWithColor:(UIColor *)color; /** Create and return a pure color image with the given color and size. @param color The color. @param size New image's type. */ + (nullable UIImage *)yy_imageWithColor:(UIColor *)color size:(CGSize)size; /** Create and return an image with custom draw code. @param size The image size. @param drawBlock The draw block. @return The new image. */ + (nullable UIImage *)yy_imageWithSize:(CGSize)size drawBlock:(void (^)(CGContextRef context))drawBlock; #pragma mark - Image Info ///============================================================================= /// @name Image Info ///============================================================================= /** Whether this image has alpha channel. */ - (BOOL)yy_hasAlphaChannel; #pragma mark - Modify Image ///============================================================================= /// @name Modify Image ///============================================================================= /** Draws the entire image in the specified rectangle, content changed with the contentMode. @discussion This method draws the entire image in the current graphics context, respecting the image's orientation setting. In the default coordinate system, images are situated down and to the right of the origin of the specified rectangle. This method respects any transforms applied to the current graphics context, however. @param rect The rectangle in which to draw the image. @param contentMode Draw content mode @param clips A Boolean value that determines whether content are confined to the rect. */ - (void)yy_drawInRect:(CGRect)rect withContentMode:(UIViewContentMode)contentMode clipsToBounds:(BOOL)clips; /** Returns a new image which is scaled from this image. The image will be stretched as needed. @param size The new size to be scaled, values should be positive. @return The new image with the given size. */ - (nullable UIImage *)yy_imageByResizeToSize:(CGSize)size; /** Returns a new image which is scaled from this image. The image content will be changed with thencontentMode. @param size The new size to be scaled, values should be positive. @param contentMode The content mode for image content. @return The new image with the given size. */ - (nullable UIImage *)yy_imageByResizeToSize:(CGSize)size contentMode:(UIViewContentMode)contentMode; /** Returns a new image which is cropped from this image. @param rect Image's inner rect. @return The new image, or nil if an error occurs. */ - (nullable UIImage *)yy_imageByCropToRect:(CGRect)rect; /** Returns a new image which is edge inset from this image. @param insets Inset (positive) for each of the edges, values can be negative to 'outset'. @param color Extend edge's fill color, nil means clear color. @return The new image, or nil if an error occurs. */ - (nullable UIImage *)yy_imageByInsetEdge:(UIEdgeInsets)insets withColor:(nullable UIColor *)color; /** Rounds a new image with a given corner size. @param radius The radius of each corner oval. Values larger than half the rectangle's width or height are clamped appropriately to half the width or height. */ - (nullable UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius; /** Rounds a new image with a given corner size. @param radius The radius of each corner oval. Values larger than half the rectangle's width or height are clamped appropriately to half the width or height. @param borderWidth The inset border line width. Values larger than half the rectangle's width or height are clamped appropriately to half the width or height. @param borderColor The border stroke color. nil means clear color. */ - (nullable UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius borderWidth:(CGFloat)borderWidth borderColor:(nullable UIColor *)borderColor; /** Rounds a new image with a given corner size. @param radius The radius of each corner oval. Values larger than half the rectangle's width or height are clamped appropriately to half the width or height. @param corners A bitmask value that identifies the corners that you want rounded. You can use this parameter to round only a subset of the corners of the rectangle. @param borderWidth The inset border line width. Values larger than half the rectangle's width or height are clamped appropriately to half the width or height. @param borderColor The border stroke color. nil means clear color. @param borderLineJoin The border line join. */ - (nullable UIImage *)yy_imageByRoundCornerRadius:(CGFloat)radius corners:(UIRectCorner)corners borderWidth:(CGFloat)borderWidth borderColor:(nullable UIColor *)borderColor borderLineJoin:(CGLineJoin)borderLineJoin; /** Returns a new rotated image (relative to the center). @param radians Rotated radians in counterclockwise.⟲ @param fitSize YES: new image's size is extend to fit all content. NO: image's size will not change, content may be clipped. */ - (nullable UIImage *)yy_imageByRotate:(CGFloat)radians fitSize:(BOOL)fitSize; /** Returns a new image rotated counterclockwise by a quarter‑turn (90°). ⤺ The width and height will be exchanged. */ - (nullable UIImage *)yy_imageByRotateLeft90; /** Returns a new image rotated clockwise by a quarter‑turn (90°). ⤼ The width and height will be exchanged. */ - (nullable UIImage *)yy_imageByRotateRight90; /** Returns a new image rotated 180° . ↻ */ - (nullable UIImage *)yy_imageByRotate180; /** Returns a vertically flipped image. ⥯ */ - (nullable UIImage *)yy_imageByFlipVertical; /** Returns a horizontally flipped image. ⇋ */ - (nullable UIImage *)yy_imageByFlipHorizontal; #pragma mark - Image Effect ///============================================================================= /// @name Image Effect ///============================================================================= /** Tint the image in alpha channel with the given color. @param color The color. */ - (nullable UIImage *)yy_imageByTintColor:(UIColor *)color; /** Returns a grayscaled image. */ - (nullable UIImage *)yy_imageByGrayscale; /** Applies a blur effect to this image. Suitable for blur any content. */ - (nullable UIImage *)yy_imageByBlurSoft; /** Applies a blur effect to this image. Suitable for blur any content except pure white. (same as iOS Control Panel) */ - (nullable UIImage *)yy_imageByBlurLight; /** Applies a blur effect to this image. Suitable for displaying black text. (same as iOS Navigation Bar White) */ - (nullable UIImage *)yy_imageByBlurExtraLight; /** Applies a blur effect to this image. Suitable for displaying white text. (same as iOS Notification Center) */ - (nullable UIImage *)yy_imageByBlurDark; /** Applies a blur and tint color to this image. @param tintColor The tint color. */ - (nullable UIImage *)yy_imageByBlurWithTint:(UIColor *)tintColor; /** Applies a blur, tint color, and saturation adjustment to this image, optionally within the area specified by @a maskImage. @param blurRadius The radius of the blur in points, 0 means no blur effect. @param tintColor An optional UIColor object that is uniformly blended with the result of the blur and saturation operations. The alpha channel of this color determines how strong the tint is. nil means no tint. @param tintBlendMode The @a tintColor blend mode. Default is kCGBlendModeNormal (0). @param saturation A value of 1.0 produces no change in the resulting image. Values less than 1.0 will desaturation the resulting image while values greater than 1.0 will have the opposite effect. 0 means gray scale. @param maskImage If specified, @a inputImage is only modified in the area(s) defined by this mask. This must be an image mask or it must meet the requirements of the mask parameter of CGContextClipToMask. @return image with effect, or nil if an error occurs (e.g. no enough memory). */ - (nullable UIImage *)yy_imageByBlurRadius:(CGFloat)blurRadius tintColor:(nullable UIColor *)tintColor tintMode:(CGBlendMode)tintBlendMode saturation:(CGFloat)saturation maskImage:(nullable UIImage *)maskImage; @end NS_ASSUME_NONNULL_END