Skip to content

Instantly share code, notes, and snippets.

@dimohamdy
Last active April 6, 2019 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimohamdy/b481ac2a9442f866bb689d46af2a2dbb to your computer and use it in GitHub Desktop.
Save dimohamdy/b481ac2a9442f866bb689d46af2a2dbb to your computer and use it in GitHub Desktop.
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