EFImageMode

public enum EFImageMode : CaseIterable

Image scaling modes for QR code watermark and icon positioning.

This enum defines how images (watermarks, icons) are scaled and positioned within QR codes. Each mode provides different behavior for handling aspect ratios and image fitting.

## Scaling Modes

  • scaleToFill: Stretches the image to fill the entire area, potentially distorting it
  • scaleAspectFit: Scales the image to fit within the area while maintaining aspect ratio
  • scaleAspectFill: Scales the image to fill the area while maintaining aspect ratio, potentially cropping

## Usage

 let icon = EFStyleParamIcon(
     image: .static(myImage),
     mode: .scaleAspectFill,  // Use aspect fill mode
     alpha: 1.0,
     borderColor: .black,
     percentage: 0.2
 )

## Visual Comparison

| Mode | Behavior | Aspect Ratio | Cropping | Distortion | |——|———-|————–|———-|————| | scaleToFill | Stretches to fill | Changed | No | Yes | | scaleAspectFit | Fits within bounds | Maintained | No | No | | scaleAspectFill | Fills bounds | Maintained | Yes | No |

  • Scales the image to fill the entire area by changing the aspect ratio if necessary.

    Declaration

    Swift

    case scaleToFill
  • Scales the image to fit within the area while maintaining the aspect ratio.

    Declaration

    Swift

    case scaleAspectFit
  • Scales the image to fill the area while maintaining the aspect ratio.

    Declaration

    Swift

    case scaleAspectFill

Utilities

  • Calculates the rectangle where the image will be positioned in the canvas.

    This method determines the exact position and size of the image within the canvas based on the scaling mode and the relative sizes of the image and canvas.

    Declaration

    Swift

    public func rectForContent(ofSize imageSize: CGSize,
                               inCanvasOfSize canvasSize: CGSize) -> CGRect

    Parameters

    imageSize

    The size of the image to be positioned.

    canvasSize

    The size of the canvas where the image will be placed.

    Return Value

    A CGRect defining the area where the image will be positioned.

  • Processes an image according to the scaling mode and target ratio.

    This method applies the scaling mode to transform the input image to match the desired canvas ratio, potentially resizing or cropping the image.

    Throws

    EFQRCodeError if image processing fails.

    Declaration

    Swift

    public func imageForContent(ofImage image: CGImage, inCanvasOfRatio canvasRatio: CGSize) throws -> CGImage

    Parameters

    image

    The CGImage to be processed.

    canvasRatio

    The target aspect ratio for the canvas.

    Return Value

    A processed CGImage that matches the scaling mode and target ratio.