Skip to content

Commit

Permalink
Merge pull request #3 from xinsight/master
Browse files Browse the repository at this point in the history
limit image size for lorempixel
  • Loading branch information
larsacus committed Jul 1, 2013
2 parents e2acd26 + 2dc4478 commit 9ef412b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions PlaceKit/UIImageView+PlaceKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
/** Place a random image in a specific category with a given size from lorempixel.com
@param size The size in points of your random image
@warning Image size will be clamped to max size supported by service
@param category The category that you would like your image to be chosen from. A full list of valid categories can be found at http://lorempixel.com
*/
- (void)placeRandomImageWithSize:(CGSize)size
Expand All @@ -51,6 +52,7 @@
/** Place a random greyscale image in a specific category with a given size from lorempixel.com
@param size The size in points of your random greyscale image
@warning Image size will be clamped to max size supported by service
@param category The category that you would like your image to be chosen from. A full list of valid categories can be found at http://lorempixel.com
*/
- (void)placeRandomGreyscaleImageWithSize:(CGSize)size
Expand All @@ -59,12 +61,14 @@
/** Place a random image with a given size from lorempixel.com
@param size The size in points of your random image
@warning Image size will be clamped to max size supported by service
*/
- (void)placeRandomImageWithSize:(CGSize)size;

/** Place a random greyscale image with a given size from lorempixel.com
@param size The size in points of your random greyscale image
@warning Image size will be clamped to max size supported by service
*/
- (void)placeRandomGreyscaleImageWithSize:(CGSize)size;

Expand All @@ -89,20 +93,24 @@
/** Place a random image in a specific category with an inherited size from lorempixel.com
@param category The category that you would like your image to be chosen from. A full list of valid categories can be found at http://lorempixel.com
@warning Image size will be clamped to max size supported by service
*/
- (void)placeRandomImageFromCategory:(NSString *)category;

/** Place a random greyscale image in a specific category with an inherited size from lorempixel.com
@param category The category that you would like your image to be chosen from. A full list of valid categories can be found at http://lorempixel.com
@warning Image size will be clamped to max size supported by service
*/
- (void)placeRandomGreyscaleImageFromCategory:(NSString *)category;

/** Place a random image with an inherited size from lorempixel.com
@warning Image size will be clamped to max size supported by service
*/
- (void)placeRandomImage;

/** Place a random greyscale image with an inherited size from lorempixel.com
@warning Image size will be clamped to max size supported by service
*/
- (void)placeRandomGreyscaleImage;

Expand Down
13 changes: 12 additions & 1 deletion PlaceKit/UIImageView+PlaceKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,18 @@ - (void)placeRandomGreyscaleImage{
#pragma mark - Common
- (void)placeImageWithURLString:(NSString *)path size:(CGSize)size{
CGFloat screenScale = [[UIScreen mainScreen] scale];
NSString *urlString = [NSString stringWithFormat:path, size.width*screenScale, size.height*screenScale];
CGFloat w = size.width*screenScale;
CGFloat h = size.height*screenScale;
NSString *service = @"lorempixel.com";
if ([path rangeOfString:service].length > 0) {
CGFloat max = 1920.0f;
if (w > max || h > max) {
w = MIN(w,max);
h = MIN(h,max);
NSLog(@"%s: Warn: clamping image size to %@ max size. using %.0fx%.0f", __PRETTY_FUNCTION__, service, w, h);
}
}
NSString *urlString = [NSString stringWithFormat:path, w, h];
NSURL *url = [NSURL URLWithString:urlString];
[self setImageWithURL:url];
}
Expand Down

0 comments on commit 9ef412b

Please sign in to comment.