Created
January 30, 2016 04:11
-
-
Save weekwood/2133aecc03e8e1b8232c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSURL+YZThumbnail.m | |
// YuanZi | |
// | |
// Created by di wu on 5/4/15. | |
// Copyright (c) 2015 Yuanzi. All rights reserved. | |
// | |
#import "NSURL+YZThumbnail.h" | |
@implementation NSURL (YZThumbnail) | |
- (NSURL *)thumbnailWithSize:(CGSize)size { | |
NSString *str = [[self cdnURL] absoluteString]; | |
NSString *imageWidth = [NSString stringWithFormat:@"%ld", (long)size.width]; | |
NSString *imageHeight = [NSString stringWithFormat:@"%ld", (long)size.height]; | |
NSString *imageStr = [NSString stringWithFormat:@"%@@%@w_%@h.png", str, imageWidth, imageHeight]; | |
return [NSURL URLWithString:imageStr]; | |
} | |
- (NSURL *)topicListThumbnail { | |
NSString *str = [[self cdnURL] absoluteString]; | |
NSNumber *imageWidth = @(CGRectGetWidth([UIScreen mainScreen].bounds) * 2); | |
NSString *imageHeight = [NSString stringWithFormat:@"%@", @450]; | |
NSString *imageStr = [NSString stringWithFormat:@"%@@%@w_450h_1e%@%@x%@-5rc.jpg", str, imageWidth, @"%7C", imageWidth, imageHeight]; | |
return [NSURL URLWithString:imageStr]; | |
} | |
- (NSURL *)strategyUserPhotoThumbnail { | |
NSString *str = [[self cdnURL] absoluteString]; | |
NSString *imageStr = [NSString stringWithFormat:@"%@@100w_100h_1e_1c_100-0ci.png", str]; | |
return [NSURL URLWithString:imageStr]; | |
} | |
- (NSURL *)userPhotoThumbnail { | |
NSString *str = [[self cdnURL] absoluteString]; | |
NSString *imageStr = [NSString stringWithFormat:@"%@@200w_200h_1e_1c_200-0ci.png", str]; | |
return [NSURL URLWithString:imageStr]; | |
} | |
- (NSURL *)noticeUserThumbnail { | |
NSString *str = [[self cdnURL] absoluteString]; | |
NSString *imageStr = [NSString stringWithFormat:@"%@@35w_35h_1e_1c_40-0ci.png", str]; | |
return [NSURL URLWithString:imageStr]; | |
} | |
- (NSURL *)strategyCoverThumbnail { | |
NSNumber *width = @(CGRectGetWidth([UIScreen mainScreen].bounds) - 7.5); | |
NSString *str = [[self cdnURL] absoluteString]; | |
NSString *imageStr = [NSString stringWithFormat:@"%@@%dw_%dh_1e%@%dx%d-5rc.jpg", str, [width intValue], [width intValue], @"%7C", | |
[width intValue], [width intValue]]; | |
return [NSURL URLWithString:imageStr]; | |
} | |
- (NSURL *)bannerCoverThumbnail { | |
NSNumber *imageWidth = @(CGRectGetWidth([UIScreen mainScreen].bounds) * 2); | |
NSString *imageHeight = [NSString stringWithFormat:@"%@", @300]; | |
NSString *str = [[self cdnURL] absoluteString]; | |
NSString *imageStr = [NSString | |
stringWithFormat:@"%@@%@w_300h_1e%@%@x%@-5rc.jpg", str, [imageWidth stringValue], @"%7C", [imageWidth stringValue], imageHeight]; | |
return [NSURL URLWithString:imageStr]; | |
} | |
- (NSURL *)cdnURL { | |
NSString *str = [self absoluteString]; | |
if ([str rangeOfString:@"http://yuanzi-dev.oss-cn-hangzhou.aliyuncs.com"].location != NSNotFound) { | |
str = [str stringByReplacingOccurrencesOfString:@"http://yuanzi-dev.oss-cn-hangzhou.aliyuncs.com" | |
withString:@"http://assets-dev.iyuanzi.net"]; | |
} else if ([str rangeOfString:@"http://yuanzi-beijing.oss-cn-beijing.aliyuncs.com"].location != NSNotFound) { | |
str = [str stringByReplacingOccurrencesOfString:@"http://yuanzi-beijing.oss-cn-beijing.aliyuncs.com" | |
withString:@"http://assets.iyuanzi.net"]; | |
} else if ([str rangeOfString:@"http://img.iyuanzi.net"].location != NSNotFound) { | |
str = [str stringByReplacingOccurrencesOfString:@"http://img.iyuanzi.net" withString:@"http://assets.iyuanzi.net"]; | |
} | |
return [NSURL URLWithString:str]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment