Skip to content

0.0.4

Latest

Choose a tag to compare

@Little-tale Little-tale released this 30 Jun 11:41

UPDATE

1. The "DownSample" function is converted to "Public".

2. Task.detached (operation: _) that was being used internally has been removed

This means that the task attribute is inherited and applied at the discretion of the developer using the function. When canceling the task, modify the logic so that the internal logic stops.

3. Additionally, we have added onlyCompress functions.

    /// Compress the given image directly without resizing, targeting a specified file size in MB.
    /// This function keeps the original image dimensions but compresses it to meet the desired size.
    /// - Parameters:
    ///   - type: The desired image format (`jpeg` or `png`).
    ///   - targetMB: The maximum allowed file size in megabytes.
    /// - Returns: The compressed image data (`Data?`), or `nil` if compression fails.
    public func onlyCompressImage(type: ImageType, targetMB: Double) async -> Data? {
        return await SwiftImageCompressor.shared.onlyCompressImage(self, type: type, targetMB: targetMB)
    }
    
    /// Compress the given image directly without resizing, targeting a specified file size in MB.
    /// This function keeps the original image dimensions but compresses it to meet the desired size.
    /// - Parameters:
    ///   - type: The desired image format (`jpeg` or `png`).
    ///   - targetMB: The maximum allowed file size in megabytes.
    ///   - completion: The compressed image data (`Data?`), or `nil` if compression fails.
    public func onlyCompressImage(
        type: ImageType,
        targetMB: Double,
        completion: @Sendable @escaping (Data?) -> Void
    ) {
        SwiftImageCompressor.shared.onlyCompressImage(self, type: type, targetMB: targetMB, completion: completion)
    }