Last active
April 6, 2019 10:36
-
-
Save dimohamdy/b481ac2a9442f866bb689d46af2a2dbb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FilesHelper { | |
//get image path in Public folder | |
static func getImagePath(fileName:String) -> URL{ | |
let directory = DirectoryConfig.detect() | |
let workingDirectory = directory.workDir | |
let workingDirectoryPath = URL(fileURLWithPath:workingDirectory) | |
let destination = workingDirectoryPath.appendingPathComponent("Public/\(fileName)") | |
return destination | |
} | |
//check if the image resized before or not | |
static func isFound(fileName:String) -> Bool{ | |
let destination = getImagePath(fileName: fileName) | |
return FileManager().fileExists(atPath: destination.path) | |
} | |
static func geNewFileName(urlString:String,width:Int,height:Int) -> String{ | |
//add width and height in image name to enable the image to be resized with different size | |
let fileNameWithoutExtension = urlString.fileName() | |
let fileExtension = urlString.fileExtension() | |
return "\(fileNameWithoutExtension)_\(width)x\(height).\(fileExtension)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment