Packages

o

web.utils

ImageTransforms

object ImageTransforms

Functional utilities for image processing with safe IO using Either.

All operations that involve reading or writing files return TransformationResult, where Left(errorMessage) indicates failure and Right(file) indicates success.

Byte-array and InputStream variants are provided alongside the File-based ones for use in API contexts, where images arrive as raw bytes/streams and results are returned in-memory rather than written to disk.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ImageTransforms
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Type Members

  1. sealed trait Axis extends AnyRef
  2. sealed trait ImageFormat extends AnyRef
  3. sealed trait ThumbType extends AnyRef
  4. type TransformationBytesResult = Either[TransformationError, Array[Byte]]

    Result type for the byte/stream-based variants: Left(error) or Right(encoded bytes).

  5. final case class TransformationError(message: String) extends AnyVal with Product with Serializable
  6. type TransformationResult = Either[TransformationError, File]

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def addBorder(inputBytesSeq: Seq[Array[Byte]], color: RGBColor, thickness: Int): Seq[TransformationBytesResult]

    Takes a list of byte arrays and adds a border to them

    Takes a list of byte arrays and adds a border to them

    inputBytesSeq

    list of raw image byte arrays

    color

    RGBColor

    thickness

    factor as double

    returns

    sequence of TransformationBytesResult

  5. def addBorder(inputFiles: Seq[File], outputDir: File, color: RGBColor, thickness: Int): Seq[TransformationResult]

    Takes a list of Files and adds a border to them

    Takes a list of Files and adds a border to them

    inputFiles

    input

    outputDir

    output path

    color

    RGBColor

    thickness

    factor as double

    returns

    Either Seq of error messages or the output files

  6. def addBorder(inputStream: InputStream, rgb: RGBColor, thickness: Int): TransformationBytesResult

    Adds a border (as a stream)

    Adds a border (as a stream)

    inputStream

    input image stream

    rgb

    color

    thickness

    border thickness

    returns

    Either an error message or the encoded bytes

  7. def addBorder(inputBytes: Array[Byte], rgb: RGBColor, thickness: Int): TransformationBytesResult

    Adds a border (as bytes)

    Adds a border (as bytes)

    inputBytes

    input image bytes

    rgb

    color

    thickness

    border thickness

    returns

    Either an error message or the encoded bytes

  8. def addBorder(image: File, outputDir: File, rgb: RGBColor, thickness: Int): TransformationResult

    Adds a border

    Adds a border

    image

    input

    outputDir

    output path

    rgb

    color

    thickness

    border thickness

    returns

    Either an error message or the output File

  9. def addBorder(image: ImmutableImage, rgb: RGBColor, thickness: Int): ImmutableImage

    Adds a border

    Adds a border

    image

    input

    rgb

    color

    thickness

    border thickness

    returns

    border-padded image

  10. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  11. def autoCrop(inputStream: InputStream, bgColor: Option[Color]): TransformationBytesResult

    Automatically crops an image (as a stream), optionally using a color as the background reference, safely.

    Automatically crops an image (as a stream), optionally using a color as the background reference, safely.

    inputStream

    the input image stream to crop

    bgColor

    optional Color used as background

    returns

    Either an error message or the cropped, encoded bytes

  12. def autoCrop(inputBytes: Array[Byte], bgColor: Option[Color]): TransformationBytesResult

    Automatically crops an image (as bytes), optionally using a color as the background reference, safely.

    Automatically crops an image (as bytes), optionally using a color as the background reference, safely.

    inputBytes

    the input image bytes to crop

    bgColor

    optional Color used as background

    returns

    Either an error message or the cropped, encoded bytes

  13. def autoCrop(inputFile: File, outputFile: File, bgColor: Option[Color]): TransformationResult

    Automatically crops an image, optionally using a color as the background reference, safely.

    Automatically crops an image, optionally using a color as the background reference, safely.

    inputFile

    the input file to crop

    outputFile

    the destination file

    bgColor

    optional Color used as background

    returns

    TransformationResult

  14. def autoCrop(image: ImmutableImage, bgColor: Option[Color] = None): ImmutableImage

    Automatically crops an image, optionally using a color as the background reference, safely.

    Automatically crops an image, optionally using a color as the background reference, safely.

    image

    immutable image

    bgColor

    optional Color used as background

    returns

    TransformationResult

  15. def bound(inputStream: InputStream, dim: Dimension): TransformationBytesResult

    If the source image is larger, it will be scaled down, maintaining aspect ratio.

    If the source image is larger, it will be scaled down, maintaining aspect ratio. If the source image is smaller, it will be returned unmodified.

    inputStream

    input image stream

    dim

    Dimension(wxh)

    returns

    Either an error message or the encoded bytes

  16. def bound(inputBytes: Array[Byte], dim: Dimension): TransformationBytesResult

    If the source image is larger, it will be scaled down, maintaining aspect ratio.

    If the source image is larger, it will be scaled down, maintaining aspect ratio. If the source image is smaller, it will be returned unmodified.

    inputBytes

    input image bytes

    dim

    Dimension(wxh)

    returns

    Either an error message or the encoded bytes

  17. def bound(image: File, outputDir: File, dim: Dimension): TransformationResult

    If the source image is larger, it will be scaled down, maintaining aspect ratio.

    If the source image is larger, it will be scaled down, maintaining aspect ratio. If the source image is smaller, it will be returned unmodified.

    image

    input

    outputDir

    output path

    dim

    Dimension(wxh)

    returns

    Either an error message or the output File

  18. def bound(image: ImmutableImage, dims: Dimension): ImmutableImage

    If the source image is larger, it will be scaled down, maintaining aspect ratio.

    If the source image is larger, it will be scaled down, maintaining aspect ratio. If the source image is smaller, it will be returned unmodified.

    image

    input

    dims

    Dimension(wxh)

    returns

    bounded image

  19. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
  20. def convertTo(inputBytesSeq: Seq[Array[Byte]], format: ImageFormat): Seq[TransformationBytesResult]

    Convert a list of images (as bytes) to the given format safely.

    Convert a list of images (as bytes) to the given format safely.

    inputBytesSeq

    list of raw image byte arrays

    format

    image writer

    returns

    sequence of TransformationBytesResult

  21. def convertTo(inputFiles: Seq[File], outputDir: File, format: ImageFormat): Seq[TransformationResult]

    Convert a list of images to WebP safely.

    Convert a list of images to WebP safely.

    inputFiles

    list of image files

    outputDir

    folder to save converted images

    format

    image writer

    returns

    sequence of TransformationResult

  22. def convertTo(inputStream: InputStream, format: ImageFormat): TransformationBytesResult

    Convert a single image (as a stream) to the given format safely.

    Convert a single image (as a stream) to the given format safely.

    inputStream

    the image input stream

    format

    image writer

    returns

    Either an error message or the encoded bytes

  23. def convertTo(inputBytes: Array[Byte], format: ImageFormat): TransformationBytesResult

    Convert a single image (as bytes) to the given format safely.

    Convert a single image (as bytes) to the given format safely.

    inputBytes

    the raw image bytes

    format

    image writer

    returns

    Either an error message or the encoded bytes

  24. def convertTo(inputFile: File, outputDir: File, format: ImageFormat): TransformationResult

    Convert a single image to WebP safely.

    Convert a single image to WebP safely.

    inputFile

    the image file to convert

    outputDir

    folder to save the converted image

    format

    image writer

    returns

    Either an error message or the output File

  25. def createThumbnail(inputBytesSeq: Seq[Array[Byte]], thumbType: ThumbType): Seq[TransformationBytesResult]

    Generate thumbnails for a list of images (as bytes) safely.

    Generate thumbnails for a list of images (as bytes) safely.

    inputBytesSeq

    list of raw image byte arrays

    thumbType

    "desktop" or "mobile"

    returns

    sequence of TransformationBytesResult

  26. def createThumbnail(inputFiles: Seq[File], outputDir: File, thumbType: ThumbType): Seq[TransformationResult]

    Generate thumbnails for a list of images safely.

    Generate thumbnails for a list of images safely.

    inputFiles

    list of image files

    outputDir

    folder to save thumbnails

    thumbType

    "desktop" or "mobile"

    returns

    sequence of TransformationResult

  27. def createThumbnail(inputStream: InputStream, thumbType: ThumbType): TransformationBytesResult

    Generate a thumbnail for a single image (as a stream) safely.

    Generate a thumbnail for a single image (as a stream) safely.

    inputStream

    the image input stream

    thumbType

    "desktop" or "mobile"

    returns

    Either an error message or the encoded thumbnail bytes

  28. def createThumbnail(inputBytes: Array[Byte], thumbType: ThumbType): TransformationBytesResult

    Generate a thumbnail for a single image (as bytes) safely.

    Generate a thumbnail for a single image (as bytes) safely.

    inputBytes

    the raw image bytes

    thumbType

    "desktop" or "mobile"

    returns

    Either an error message or the encoded thumbnail bytes

  29. def createThumbnail(inputFile: File, outputDir: File, thumbType: ThumbType): TransformationResult

    Generate a thumbnail for a single image safely.

    Generate a thumbnail for a single image safely.

    inputFile

    the image file

    outputDir

    folder to save thumbnail

    thumbType

    "desktop" or "mobile"

    returns

    Either an error message or the thumbnail File

  30. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  31. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  32. def flip(inputStream: InputStream, axis: Axis): TransformationBytesResult

    Flips an image (as a stream)

    Flips an image (as a stream)

    inputStream

    input image stream

    axis

    Horizontal|Vertical

    returns

    Either an error message or the encoded bytes

  33. def flip(inputBytes: Array[Byte], axis: Axis): TransformationBytesResult

    Flips an image (as bytes)

    Flips an image (as bytes)

    inputBytes

    input image bytes

    axis

    Horizontal|Vertical

    returns

    Either an error message or the encoded bytes

  34. def flip(image: File, outputDir: File, axis: Axis): TransformationResult

    Flips an image

    Flips an image

    image

    input

    outputDir

    output path

    axis

    Horizontal|Vertical

    returns

    Either an error message or the output File

  35. def flip(image: ImmutableImage, axis: Axis): ImmutableImage

    Flips an image

    Flips an image

    image

    input

    axis

    Horizontal|Vertical

    returns

    flipped image

  36. def generatePlaceholders(number: Int, width: Int, height: Int, fillColor: Option[Color] = None, applyBlur: Boolean = true, outputDir: File): Seq[TransformationResult]

    Generates a series of placeholder images safely.

    Generates a series of placeholder images safely.

    number

    the number of placeholder images to generate

    width

    width of each image

    height

    height of each image

    fillColor

    optional Color to fill the image; if None, transparent

    applyBlur

    whether to apply a blur effect

    outputDir

    folder to write placeholder images

    returns

    sequence of TransformationResult

  37. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  38. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  39. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  40. def listImages(inputDir: File): Seq[File]

    List all supported image files in a folder.

    List all supported image files in a folder.

    inputDir

    the folder to scan for image files

    returns

    sequence of valid image files

  41. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  42. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  43. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  44. def scale(inputBytesSeq: Seq[Array[Byte]], factor: Double): Seq[TransformationBytesResult]

    Takes a list of byte arrays and scales them

    Takes a list of byte arrays and scales them

    inputBytesSeq

    list of raw image byte arrays

    factor

    factor as double

    returns

    sequence of TransformationBytesResult

  45. def scale(inputFiles: Seq[File], outputDir: File, factor: Double): Seq[TransformationResult]

    Takes a list of Files and scales them

    Takes a list of Files and scales them

    inputFiles

    input

    outputDir

    output path

    factor

    factor as double

    returns

    Either Seq of error messages or the output files

  46. def scale(inputStream: InputStream, factor: Double): TransformationBytesResult

    Scales an image (as a stream)

    Scales an image (as a stream)

    inputStream

    input image stream

    factor

    as double

    returns

    Either an error message or the encoded bytes

  47. def scale(inputBytes: Array[Byte], factor: Double): TransformationBytesResult

    Scales an image (as bytes)

    Scales an image (as bytes)

    inputBytes

    input image bytes

    factor

    as double

    returns

    Either an error message or the encoded bytes

  48. def scale(image: File, outputDir: File, factor: Double): TransformationResult

    Scales an image

    Scales an image

    image

    input

    factor

    as double

    returns

    Either an error message or the output File

  49. def scale(image: ImmutableImage, factor: Double): ImmutableImage

    Scales an image

    Scales an image

    image

    input

    factor

    as double

    returns

    scaled image

  50. def stripMetadata(inputStream: InputStream): TransformationBytesResult

    Removes all metadata from an image (as a stream) and re-encodes it as a clean PNG safely.

    Removes all metadata from an image (as a stream) and re-encodes it as a clean PNG safely.

    inputStream

    the image input stream to process

    returns

    Either an error message or the stripped PNG bytes

  51. def stripMetadata(inputBytes: Array[Byte]): TransformationBytesResult

    Removes all metadata from an image (as bytes) and re-encodes it as a clean PNG safely.

    Removes all metadata from an image (as bytes) and re-encodes it as a clean PNG safely.

    inputBytes

    the raw image bytes to process

    returns

    Either an error message or the stripped PNG bytes

  52. def stripMetadata(inputFile: File, outputFile: File): TransformationResult

    Removes all metadata from an image and saves it as a clean PNG safely.

    Removes all metadata from an image and saves it as a clean PNG safely.

    inputFile

    the image file to process

    outputFile

    destination file for stripped image

    returns

    TransformationResult

  53. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  54. def toString(): String
    Definition Classes
    AnyRef → Any
  55. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  56. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  57. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  58. def zoom(inputBytesSeq: Seq[Array[Byte]], factor: Double): Seq[TransformationBytesResult]

    Takes a list of byte arrays and zooms in them

    Takes a list of byte arrays and zooms in them

    inputBytesSeq

    list of raw image byte arrays

    factor

    factor as double

    returns

    sequence of TransformationBytesResult

  59. def zoom(inputFiles: Seq[File], outputDir: File, factor: Double): Seq[TransformationResult]

    Takes a list of Files and zooms in them

    Takes a list of Files and zooms in them

    inputFiles

    input

    outputDir

    output path

    factor

    factor as double

    returns

    Either Seq of error messages or the output files

  60. def zoom(inputStream: InputStream, factor: Double): TransformationBytesResult

    Close up (as a stream)

    Close up (as a stream)

    inputStream

    input image stream

    factor

    as double

    returns

    Either an error message or the encoded bytes

  61. def zoom(inputBytes: Array[Byte], factor: Double): TransformationBytesResult

    Close up (as bytes)

    Close up (as bytes)

    inputBytes

    input image bytes

    factor

    as double

    returns

    Either an error message or the encoded bytes

  62. def zoom(image: File, outputDir: File, factor: Double): TransformationResult

    Close up

    Close up

    image

    input

    factor

    as double

    returns

    Either an error message or the output File

  63. def zoom(image: ImmutableImage, factor: Double): ImmutableImage

    Close up

    Close up

    image

    input

    factor

    as double

    returns

    zoomed in image

  64. case object Desktop extends ThumbType with Product with Serializable
  65. case object Horizontal extends Axis with Product with Serializable
  66. case object Jpeg extends ImageFormat with Product with Serializable
  67. case object Mobile extends ThumbType with Product with Serializable
  68. case object Png extends ImageFormat with Product with Serializable
  69. case object Vertical extends Axis with Product with Serializable
  70. case object Webp extends ImageFormat with Product with Serializable

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from AnyRef

Inherited from Any

Ungrouped