|
@@ -254,81 +254,6 @@ class NCUtility: NSObject {
|
|
|
return closure(imageNamePath)
|
|
|
}
|
|
|
|
|
|
- func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool) -> String? {
|
|
|
-
|
|
|
- var fileNamePNG = ""
|
|
|
-
|
|
|
- guard let svgUrlString = svgUrlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
|
|
|
- return nil
|
|
|
- }
|
|
|
- guard let iconURL = URL(string: svgUrlString) else {
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- if fileName == nil {
|
|
|
- fileNamePNG = iconURL.deletingPathExtension().lastPathComponent + ".png"
|
|
|
- } else {
|
|
|
- fileNamePNG = fileName!
|
|
|
- }
|
|
|
-
|
|
|
- let imageNamePath = CCUtility.getDirectoryUserData() + "/" + fileNamePNG
|
|
|
-
|
|
|
- if !FileManager.default.fileExists(atPath: imageNamePath) || rewrite == true {
|
|
|
-
|
|
|
- guard let imageData = try? Data(contentsOf:iconURL) else {
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- if let image = UIImage.init(data: imageData) {
|
|
|
-
|
|
|
- var newImage: UIImage = image
|
|
|
-
|
|
|
- if width != nil {
|
|
|
-
|
|
|
- let ratio = image.size.height / image.size.width
|
|
|
- let newSize = CGSize(width: width!, height: width! * ratio)
|
|
|
-
|
|
|
- let renderFormat = UIGraphicsImageRendererFormat.default()
|
|
|
- renderFormat.opaque = false
|
|
|
- let renderer = UIGraphicsImageRenderer(size: CGSize(width: newSize.width, height: newSize.height), format: renderFormat)
|
|
|
- newImage = renderer.image {
|
|
|
- (context) in
|
|
|
- image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- guard let pngImageData = newImage.pngData() else {
|
|
|
- return nil
|
|
|
- }
|
|
|
- CCUtility.write(pngImageData, fileNamePath: imageNamePath)
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- guard let svgImage: SVGKImage = SVGKImage(contentsOf: iconURL) else {
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- if width != nil {
|
|
|
- let scale = svgImage.size.height / svgImage.size.width
|
|
|
- svgImage.size = CGSize(width: width!, height: width! * scale)
|
|
|
- }
|
|
|
-
|
|
|
- guard let image: UIImage = svgImage.uiImage else {
|
|
|
- return nil
|
|
|
- }
|
|
|
- guard let pngImageData = image.pngData() else {
|
|
|
- return nil
|
|
|
- }
|
|
|
-
|
|
|
- CCUtility.write(pngImageData, fileNamePath: imageNamePath)
|
|
|
-
|
|
|
- return imageNamePath
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return imageNamePath
|
|
|
- }
|
|
|
-
|
|
|
@objc func startActivityIndicator(view: UIView, bottom: CGFloat) {
|
|
|
|
|
|
activityIndicator.color = NCBrandColor.sharedInstance.brand
|