Skip to content

Commit b049f27

Browse files
committed
[UIImage] Save to temp file
1 parent dfd0828 commit b049f27

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,15 @@ Convert a String to Data then save it to the given URL path
353353
```swift
354354
saveAsPNG(path:URL) -> Bool
355355
```
356+
357+
Save an image to a temporary file
358+
359+
```swift
360+
tempURLForImage(named name: String) -> URL?
361+
```
362+
363+
Resize an image
364+
356365
```swift
357366
resize(width: CGFloat) -> UIImage
358367
resize(height: CGFloat) -> UIImage

Sources/Non_Extension/UIImage.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ extension UIImage {
3333
}
3434
return true
3535
}
36+
37+
#if !IS_EXTENSION
38+
/**
39+
Saves a `UIImage` to the temporary directory as a `.png` and returns the URL
40+
- Parameters:
41+
- named: The filename to use (`.png` will automatically be appended)
42+
*/
43+
func tempURLForImage(named name: String) -> URL? {
44+
45+
let fileManager = FileManager.default
46+
let url = fileManager.temporaryDirectory.appendingPathComponent("\(name).png")
47+
guard self.saveAsPNG(path: url) else { return nil }
48+
return url
49+
}
50+
#endif
3651
}
3752

3853
public

0 commit comments

Comments
 (0)