All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cloudinary.transformation.layer.source.ImageSource.kt Maven / Gradle / Ivy

package com.cloudinary.transformation.layer.source

import com.cloudinary.transformation.ITransformableImage
import com.cloudinary.transformation.ImageTransformation
import com.cloudinary.transformation.Param
import com.cloudinary.transformation.TransformationDsl
import com.cloudinary.util.cldEncodePublicId

class ImageSource constructor(
    private val publicId: String,
    override val transformation: ITransformableImage<*>? = null
) : Source {
    override fun extraComponents(): List {
        return emptyList()
    }

    override fun toString(): String {
        return publicId.cldEncodePublicId()
    }

    companion object {
        fun publicId(publicId: String, options: (Builder.() -> Unit)? = null): ImageSource {
            val builder = Builder(publicId)
            options?.let { builder.it() }
            return builder.build()
        }
    }

    @TransformationDsl
    class Builder(private val publicId: String) {
        private var transformation: ITransformableImage<*>? = null

        fun transformation(transformation: ITransformableImage<*>) =
            apply { this.transformation = transformation }

        fun transformation(transformation: ImageTransformation.Builder.() -> Unit) = apply {
            val builder = ImageTransformation.Builder()
            builder.transformation()
            this.transformation = builder.build()
        }

        fun build() = ImageSource(publicId, transformation)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy