|
@@ -407,8 +407,34 @@ class NCUtility: NSObject {
|
|
|
}
|
|
|
|
|
|
#if !EXTENSION
|
|
|
- @objc func createAvatar(fileNameSource: String, fileNameSourceAvatar: String) -> UIImage? {
|
|
|
+ @objc func createAvatar(fileNameSource: String, fileNameSourceAvatar: String, borderColor: UIColor, borderWidth: CGFloat) -> UIImage? {
|
|
|
|
|
|
+ guard let imageFile = UIImage(contentsOfFile: fileNameSource) else { return nil }
|
|
|
+ let size = NCBrandGlobal.shared.avatarSize
|
|
|
+ guard let imageSource = imageFile.resizeImage(size: CGSize(width: size, height: size), isAspectRation: true) else { return nil }
|
|
|
+
|
|
|
+ UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
|
|
|
+ imageSource.draw(in: CGRect(x: 0, y: 0, width: size, height: size))
|
|
|
+ let image = UIGraphicsGetImageFromCurrentImageContext()
|
|
|
+ UIGraphicsEndImageContext()
|
|
|
+
|
|
|
+ UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
|
|
|
+ let avatarImageView = NCAvatar.init(image: image, borderColor: borderColor, borderWidth: borderWidth)
|
|
|
+ guard let context = UIGraphicsGetCurrentContext() else { return nil }
|
|
|
+ avatarImageView.layer.render(in: context)
|
|
|
+ guard let imageAvatar = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
|
|
|
+ UIGraphicsEndImageContext()
|
|
|
+
|
|
|
+ guard let data = imageAvatar.pngData() else {
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ do {
|
|
|
+ try data.write(to: NSURL(fileURLWithPath: fileNameSourceAvatar) as URL, options: .atomic)
|
|
|
+ } catch { }
|
|
|
+
|
|
|
+ return imageAvatar
|
|
|
+
|
|
|
+ /*
|
|
|
guard let imageSource = UIImage(contentsOfFile: fileNameSource) else { return nil }
|
|
|
let size = NCBrandGlobal.shared.avatarSize
|
|
|
|
|
@@ -418,7 +444,7 @@ class NCUtility: NSObject {
|
|
|
UIGraphicsEndImageContext()
|
|
|
|
|
|
UIGraphicsBeginImageContextWithOptions(CGSize(width: size, height: size), false, UIScreen.main.scale)
|
|
|
- let avatarImageView = NCAvatar.init(image: image, borderColor: .lightGray, borderWidth: 1)
|
|
|
+ let avatarImageView = NCAvatar.init(image: image, borderColor: borderColor, borderWidth: borderWidth)
|
|
|
guard let context = UIGraphicsGetCurrentContext() else { return nil }
|
|
|
avatarImageView.layer.render(in: context)
|
|
|
guard let imageAvatar = UIGraphicsGetImageFromCurrentImageContext() else { return nil }
|
|
@@ -432,6 +458,7 @@ class NCUtility: NSObject {
|
|
|
} catch { }
|
|
|
|
|
|
return imageAvatar
|
|
|
+ */
|
|
|
}
|
|
|
#endif
|
|
|
|