-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from boostcampwm-2022/feature_image
이미지 처리 및 캐싱 모듈 수정
- Loading branch information
Showing
8 changed files
with
89 additions
and
46 deletions.
There are no files selected for viewing
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
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
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
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
26 changes: 26 additions & 0 deletions
26
SpaceCapsule/SpaceCapsule/Manager/KingReceiver/Extensions/NSCache+subscript.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// NSCache+.swift | ||
// SpaceCapsule | ||
// | ||
// Created by 장재훈 on 2022/12/10. | ||
// | ||
|
||
import Foundation | ||
|
||
extension NSCache where KeyType == NSString, ObjectType == NSData { | ||
subscript(_ url: URL) -> NSData? { | ||
get { | ||
let key = url.absoluteString as NSString | ||
|
||
return object(forKey: key) | ||
} | ||
|
||
set { | ||
let key = url.absoluteString as NSString | ||
|
||
if let newValue { | ||
setObject(newValue, forKey: key) | ||
} | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
SpaceCapsule/SpaceCapsule/Manager/KingReceiver/Extensions/UIImage+resize.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// UIImage+.swift | ||
// SpaceCapsule | ||
// | ||
// Created by 장재훈 on 2022/12/10. | ||
// | ||
|
||
import UIKit.UIImage | ||
|
||
extension UIImage { | ||
static func resize(data: Data, to targetSize: CGSize, scale: CGFloat) -> UIImage? { | ||
let imageSourceOptions = [kCGImageSourceShouldCache: false] as CFDictionary | ||
guard let imageSource = CGImageSourceCreateWithData(data as CFData, imageSourceOptions) else { | ||
return nil | ||
} | ||
|
||
let maxDimension = max(targetSize.width, targetSize.height) * scale | ||
let resizingOptions = [ | ||
kCGImageSourceCreateThumbnailFromImageAlways: true, | ||
kCGImageSourceShouldCacheImmediately: true, | ||
kCGImageSourceCreateThumbnailWithTransform: true, | ||
kCGImageSourceThumbnailMaxPixelSize: maxDimension, | ||
] as CFDictionary | ||
|
||
guard let resizedImage = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, resizingOptions) else { | ||
return nil | ||
} | ||
|
||
return UIImage(cgImage: resizedImage) | ||
} | ||
} |
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
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