1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- //
- // KMImageModel.swift
- // PDF Reader Pro
- //
- // Created by liujiajie on 2023/12/5.
- //
- import Foundation
- func moniker(x: Float) -> String {
- if x > 1048576 {
- return "G"
- }else if x >= 1024 {
- return "M"
- }else{
- return "K"
- }
- }
- func truesize(x: Float) -> Float {
- if x > 1048576 {
- return x / 1048576.0
- }else if x >= 1024 {
- return x / 1024.0
- }else{
- return x
- }
- }
- class KMImageModel: NSObject{
- var photoPath: String = ""
- var photoName: String = ""
- var photoSize: String = ""
- var photoScale: String = ""
-
- init(filepath: String) {
- super.init()
- self.photoPath = filepath
- let attributesDic = try? FileManager.default.attributesOfItem(atPath: filepath)
- let fileSize = attributesDic?[FileAttributeKey.size] as? Float ?? 0
- let size = fileSize/1024.0
- self.photoSize = String(format: "%.1f %@", truesize(x: size), moniker(x: size))
- self.photoName = filepath.lastPathComponent
- let img = NSImage(contentsOfFile: filepath)
- self.photoScale = String(format: "%.0f x %.0f", img?.size.width ?? 0, img?.size.height ?? 0)
- }
- }
|