Module: DFC::Image

Instance Method Summary # collapse

Instance Method Details

#convert(input, output, max_width: nil, max_height: nil, flip_h: nil, flip_v: nil, crop_x: nil, crop_y: nil, crop_width: nil, crop_height: nil, operations: nil) ⇒ Boolean

Note:

本方法自动去重 ‘operations` 参数,避免重复执行相同的操作。

Note:

仅支持 4 通道(RGBA)图像处理,所有图片都转换为 RGBA 格式进行操作。

Returns 处理成功返回 ‘true`,否则返回 `false`。.

Examples:

# 处理图片,裁剪 300x300 大小并水平翻转,最后保存为 BMP 格式:
process_image("input.jpg", "output.bmp",
              max_width: 500, max_height: 500,
              crop_width: 300, crop_height: 300,
              operations: ["flip_h", "flip_v", "flip_h", "crop", "resize"])
# 实际执行顺序: 水平翻转 垂直翻转 裁剪 调整大小 保存为 BMP

Parameters:

  • input (String)

    输入图片文件路径。

  • output (String)

    输出图片文件路径(支持 png、jpg、jpeg、bmp、webp)。

  • max_width (Integer) (defaults to: nil)

    (可选)调整图片的最大宽度,默认不缩放。

  • max_height (Integer) (defaults to: nil)

    (可选)调整图片的最大高度,默认不缩放。

  • crop_x (Integer) (defaults to: nil)

    (可选)裁剪区域起点 x 坐标,默认居中裁剪。

  • crop_y (Integer) (defaults to: nil)

    (可选)裁剪区域起点 y 坐标,默认居中裁剪。

  • crop_width (Integer) (defaults to: nil)

    (可选)裁剪区域的宽度,默认不裁剪。

  • crop_height (Integer) (defaults to: nil)

    (可选)裁剪区域的高度,默认不裁剪。

  • flip_h (True/False) (defaults to: nil)

    (可选)水平翻转,默认不水平翻转。

  • flip_v (True/False) (defaults to: nil)

    (可选)垂直翻转,默认不垂直翻转。

  • operations (Array<String>) (defaults to: nil)

    (可选)执行的图片操作顺序,支持:

    • ‘“resize”`:调整图片大小(优先级最高)。

    • ‘“crop”`:裁剪图片(如果未指定起点,则居中裁剪)。

    • ‘“flip_h”`:水平翻转图片。

    • ‘“flip_v”`:垂直翻转图片。

    **默认执行顺序:** ‘[“resize”, “crop”, “flip_h”, “flip_v”]`

Returns:

  • (Boolean)

    处理成功返回 ‘true`,否则返回 `false`。