Latest 0.1.1
Homepage https://github.com/huang-kun/JKResize
License MIT
Platforms ios 5.0, requires ARC
Frameworks UIKit
Authors

CI Status
Version
License
Platform

Installation

JKResize is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "JKResize"

Usage

Here is a description for How to use JKResize.

Can use UIImage Category to get aspect resized image

First of all, import "UIImage+JKResize.h"
Then you can use one of these:

Get a resized image which fits into the target size.

UIImage *resizedImage = [image resizedImageScaleAspectFitToSize:targetSize];

Get a resized image which fills into the target size.

UIImage *resizedImage = [image resizedImageScaleAspectFillToSize:size option:JKResizeImageScaleAspectFillCenter];

Get a resized image which fills into the target size with top-left alignment.

UIImage *resizedImage = [image resizedImageScaleAspectFillToSize:size option:JKResizeImageScaleAspectFillOrigin];

Demo

Octocat

Debug

There is a debug option for checking how the image resize work.
To turn on the debug mode, follow the steps:

  1. Go to UIImage+JKResize.m
  2. Find code #define jk_debug_uiimage_JKResize_visualize_rect 1, make sure the value is 1, not 0
  3. Find code NSLog(@"break me here: %@", fullImage);, Set a breakpoint here
  4. Run the program. When breakpoint gets hit, check out the preview of fullImage variable (The partial image in red rect is the actual displayed image, the green rect shows the original image)

DebugScreenShot

Calculate the size and rect for generic purpose

The JKResize raw functions are available for calculating result from any generic CGSize or CGRect value which fits or fills in specific CGSize or CGRect.

CGSize jk_sizeForAspectResize(CGSize originalSize, CGSize inSize, JKResizeScaleRule scaleRule);
CGRect jk_rectForAspectResize(CGSize originalSize, CGRect inRect, JKResizeScaleRule scaleRule, JKResizeAlignment alignment);

Example:

CGSize originalSize = CGSizeMake(100,100);
CGSize inSize = CGSizeMake(100, 50);
CGSize s = jk_sizeForAspectResize(originalSize, inSize, JKResizeScaleAspectFit);
// (CGSize) s = (width = 50, height = 50)

CGRect inRect = CGRectMake(50, 50, 100, 50);
CGRect r = jk_rectForAspectResize(originalSize, inRect, JKResizeScaleAspectFill, JKResizeAlignmentCenter);
// (CGRect) r = (origin = (x = 50, y = 25), size = (width = 100, height = 100))

Requirements

iOS 5.0
ARC enabled

Author

huang-kun, [email protected]

License

JKResize is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "JKResize",
    "version": "0.1.1",
    "summary": "JKResize is a helper tool for image resizing and returning correct size with specific aspect rule condition.",
    "description": "Here are some cases you might consider using JKResize.n.Can use UIImage Category to get aspect resized imagen.Calculate the aspect resized CGSize and CGRect values for generic purpose",
    "homepage": "https://github.com/huang-kun/JKResize",
    "license": "MIT",
    "authors": {
        "huang-kun": "[email protected]"
    },
    "source": {
        "git": "https://github.com/huang-kun/JKResize.git",
        "tag": "0.1.1"
    },
    "platforms": {
        "ios": "5.0"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*",
    "resource_bundles": {
        "JKResize": [
            "Pod/Assets/*.png"
        ]
    },
    "public_header_files": "Pod/Classes/**/*.h",
    "frameworks": "UIKit"
}

Pin It on Pinterest

Share This