marinofaggiana 4 years ago
parent
commit
11b60c156c
4 changed files with 30 additions and 28 deletions
  1. 2 2
      Cartfile.resolved
  2. 1 1
      Share/ShareViewController.m
  3. 0 17
      iOSClient/Utility/CCGraphics.m
  4. 27 8
      iOSClient/Utility/NCUtility.swift

+ 2 - 2
Cartfile.resolved

@@ -19,11 +19,11 @@ github "malcommac/SwiftRichString" "3.7.1"
 github "marinofaggiana/KTVHTTPCache" "2.0.2"
 github "marinofaggiana/TOPasscodeViewController" "0.0.7"
 github "marinofaggiana/XLForm" "eb9381ad8129f60402bf412250fb31b95a628a08"
-github "nextcloud/ios-communication-library" "8f2602605288b5b14831b4f44696837bb6aa492b"
+github "nextcloud/ios-communication-library" "89104a0371e86a392e5ca211a596c0c821ef6bbb"
 github "realm/realm-cocoa" "v5.2.0"
 github "rechsteiner/Parchment" "v1.7.0"
 github "scenee/FloatingPanel" "v1.7.5"
 github "tilltue/TLPhotoPicker" "2.0.11"
 github "weichsel/ZIPFoundation" "0.9.10"
-github "yahoojapan/SwiftyXMLParser" "5.1.0"
+github "yahoojapan/SwiftyXMLParser" "5.2.0"
 github "yannickl/QRCodeReader.swift" "10.1.1"

+ 1 - 1
Share/ShareViewController.m

@@ -405,7 +405,7 @@
     else if (UTTypeConformsTo(fileUTI, kUTTypeImage)) {
         image = [UIImage imageWithContentsOfFile:[NSTemporaryDirectory() stringByAppendingString:fileName]];
         if (image) {
-            image = [NCUtility.sharedInstance resizeImageWithImage:image newWidth:cell.frame.size.width];
+            image = [NCUtility.sharedInstance resizeImageWithImage:image toHeight:cell.frame.size.width];
         } else {
             image = [UIImage imageNamed:@"file_photo"];
         }

+ 0 - 17
iOSClient/Utility/CCGraphics.m

@@ -51,23 +51,6 @@
     return thumbnailImage;
 }
 
-// mix two image
-+ (UIImage *)overlayImage:(UIImage *)backgroundImage watermarkImage:(UIImage *)watermarkImage where:(NSString *)where
-{    
-    UIGraphicsBeginImageContext(backgroundImage.size);
-    [backgroundImage drawInRect:CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height)];
-    
-    if ([where isEqualToString:@"right"]) [watermarkImage drawInRect:CGRectMake(backgroundImage.size.width - watermarkImage.size.width, backgroundImage.size.height - watermarkImage.size.height, watermarkImage.size.width, watermarkImage.size.height)];
-    
-    if ([where isEqualToString:@"left"]) [watermarkImage drawInRect:CGRectMake(0, backgroundImage.size.height - watermarkImage.size.height, backgroundImage.size.width - watermarkImage.size.width, backgroundImage.size.height - watermarkImage.size.height)];
-    
-    
-    UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
-    UIGraphicsEndImageContext();
-    
-    return result;
-}
-
 + (UIImage *)generateImageFromVideo:(NSString *)videoPath
 {
     NSURL *url = [NSURL fileURLWithPath:videoPath];

+ 27 - 8
iOSClient/Utility/NCUtility.swift

@@ -92,16 +92,35 @@ class NCUtility: NSObject {
         return false
     }
     
-    @objc func resizeImage(image: UIImage, newWidth: CGFloat) -> UIImage {
+    @objc func resizeImage(image: UIImage, toHeight: CGFloat) -> UIImage {
+        return autoreleasepool { () -> UIImage in
+            let toWidth = image.size.width * (toHeight/image.size.height)
+            let targetSize = CGSize(width: toWidth, height: toHeight)
+            let size = image.size
+        
+            let widthRatio  = targetSize.width  / size.width
+            let heightRatio = targetSize.height / size.height
+        
+            // Orientation detection
+            var newSize: CGSize
+            if(widthRatio > heightRatio) {
+            newSize = CGSize(width: size.width * heightRatio, height: size.height * heightRatio)
+            } else {
+            newSize = CGSize(width: size.width * widthRatio,  height: size.height * widthRatio)
+            }
         
-        let scale = newWidth / image.size.width
-        let newHeight = image.size.height * scale
-        UIGraphicsBeginImageContext(CGSize(width: newWidth, height: newHeight))
-        image.draw(in: (CGRect(x: 0, y: 0, width: newWidth, height: newHeight)))
-        let newImage = UIGraphicsGetImageFromCurrentImageContext()!
-        UIGraphicsEndImageContext()
+            // Calculated rect
+            let rect = CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)
+        
+            // Resize
+            UIGraphicsBeginImageContextWithOptions(newSize, false, 1.0)
+            image.draw(in: rect)
         
-        return newImage
+            let newImage = UIGraphicsGetImageFromCurrentImageContext()
+            UIGraphicsEndImageContext()
+        
+            return newImage!
+        }
     }
     
     func cellBlurEffect(with frame: CGRect) -> UIView {