Merge branch 'mkirk/note-to-self-avatar-2'

pull/1/head
Michael Kirk 7 years ago
commit 8746055e13

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "note-24@1x.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "note-24@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "note-24@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 447 B

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -490,15 +490,18 @@ import SignalMessaging
let dstScale: CGFloat = 1.0 // The size is specified in pixels, not in points.
UIGraphicsBeginImageContextWithOptions(dstSizePixels, !hasAlpha, dstScale)
let context = UIGraphicsGetCurrentContext()
context!.interpolationQuality = .high
guard let context = UIGraphicsGetCurrentContext() else {
owsFailDebug("could not generate dst image.")
return nil
}
context.interpolationQuality = .high
let imageViewFrame = imageRenderRect(forDstSize: dstSizePixels)
srcImage.draw(in: imageViewFrame)
let scaledImage = UIGraphicsGetImageFromCurrentImageContext()
if scaledImage == nil {
guard let scaledImage = UIGraphicsGetImageFromCurrentImageContext() else {
owsFailDebug("could not generate dst image.")
return nil
}
UIGraphicsEndImageContext()
return scaledImage

@ -648,7 +648,7 @@ public class ImageEditorModel: NSObject {
defer { UIGraphicsEndImageContext() }
guard let context = UIGraphicsGetCurrentContext() else {
owsFailDebug("Could not create output context.")
owsFailDebug("context was unexpectedly nil")
return nil
}
context.interpolationQuality = .high

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "OWSContactAvatarBuilder.h"
@ -90,6 +90,27 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable UIImage *)buildSavedImage
{
if ([self.signalId isEqualToString:TSAccountManager.localNumber]) {
NSString *noteToSelfCacheKey = [NSString stringWithFormat:@"%@:note-to-self", self.cacheKey];
UIImage *_Nullable cachedAvatar =
[OWSContactAvatarBuilder.contactsManager.avatarCache imageForKey:noteToSelfCacheKey
diameter:(CGFloat)self.diameter];
if (cachedAvatar) {
return cachedAvatar;
}
UIImage *image = [self noteToSelfImageWithConversationColorName:self.colorName];
if (!image) {
OWSFailDebug(@"Could not generate avatar.");
return nil;
}
[OWSContactAvatarBuilder.contactsManager.avatarCache setImage:image
forKey:noteToSelfCacheKey
diameter:self.diameter];
return image;
}
return [OWSContactAvatarBuilder.contactsManager imageForPhoneIdentifier:self.signalId];
}
@ -162,6 +183,38 @@ NS_ASSUME_NONNULL_BEGIN
return image;
}
- (nullable UIImage *)noteToSelfImageWithConversationColorName:(ConversationColorName)conversationColorName
{
UIImage *baseImage = [[UIImage imageNamed:@"note-to-self-avatar"] asTintedImageWithColor:UIColor.whiteColor];
UIColor *backgroundColor = [OWSConversationColor conversationColorOrDefaultForColorName:conversationColorName].themeColor;
CGFloat paddingFactor = 1.6;
CGFloat paddedWidth = baseImage.size.width * paddingFactor;
CGFloat paddedheight = baseImage.size.height * paddingFactor;
UIGraphicsBeginImageContextWithOptions(CGSizeMake(paddedWidth, paddedheight), NO, 0.0);
CGContextRef _Nullable context = UIGraphicsGetCurrentContext();
if (context == nil) {
OWSFailDebug(@"failure: context was unexpectedly nil");
return nil;
}
[backgroundColor setFill];
CGContextFillRect(context, CGRectMake(0, 0, paddedWidth, paddedheight));
CGPoint origin = CGPointMake((paddedWidth - baseImage.size.width) / 2.0f,
(paddedheight - baseImage.size.height) / 2.0f);
[baseImage drawAtPoint:origin];
UIImage *paddedImage = UIGraphicsGetImageFromCurrentImageContext();
if (paddedImage == nil) {
OWSFailDebug(@"failure: paddedImage was unexpectedly nil");
return nil;
}
UIGraphicsEndImageContext();
return paddedImage;
}
@end
NS_ASSUME_NONNULL_END

@ -1,5 +1,5 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -11,6 +11,7 @@ extension UIImage {
defer { UIGraphicsEndImageContext() }
guard let context = UIGraphicsGetCurrentContext() else {
owsFailDebug("context was unexpectedly nil")
return nil
}

Loading…
Cancel
Save