SPB Git

Repository Public License

06-batch-image-conversion.yaml 4.0 KB 103 lines yaml

1# ORIX OS Automation2# File: Workflows/Examples/06-batch-image-conversion.yaml3# Description: Built-in automation: converts every image of a folder to one format with sequential names, originals untouched.4#5# Author: Simon-Pierre Boucher6# Contact: contact@spboucher.ai7#8# Limitations9# - Originals are never modified or removed; converted copies go to the output folder.10# - Names are <prefix>-<n>.<format> in listing order (alphabetical); numbers are not zero-padded (the expression11#   language has no padding function).12# - Existing files in the output folder are not overwritten: rerunning into a non-empty folder fails on the first collision.13# - `format` is one of png, jpeg, jpg, heic, tiff, gif, bmp (documents.imageConvert, ImageIO); another value fails the14#   first conversion. Animated GIFs lose their animation (first frame only); HEIC needs OS support.15# - Only the top level of the source folder is read, at most 500 entries.16apiVersion: orix.ai/v117kind: Automation18metadata:19  id: batch-image-conversion20  name: Batch image conversion and naming21  description: >-22    Converts every image of a folder to a chosen format and writes the copies to an output folder with23    sequential names, four at a time, then checks that one converted file exists per source image.24  tags: [images, convert, batch]25spec:26  triggers:27    - type: manual28  parameters:29    - name: sourceFolder30      type: path31      default: ~/ORIX Samples/batch-image-conversion/Originals32      description: Folder with the images to convert.33    - name: outputFolder34      type: path35      default: ~/ORIX Samples/batch-image-conversion/Converted36      description: Folder that receives the converted copies.37    - name: format38      type: string39      default: jpeg40      description: Target format (png, jpeg, jpg, heic, tiff, gif or bmp); also used as the file extension.41    - name: prefix42      type: string43      default: image44      description: Prefix of the new file names.45  permissions:46    filesystem:47      read: ["${{ params.sourceFolder }}", "${{ params.outputFolder }}"]48      write: ["${{ params.outputFolder }}"]49  budget:50    maxDurationSeconds: 90051    maxToolCalls: 200052  variables:53    extensions: [.png, .jpg, .jpeg, .heic, .tiff, .tif, .gif, .bmp]54  steps:55    - id: list56      tool: filesystem.list57      with:58        path: ${{ params.sourceFolder }}59        recursive: false60    - id: images61      needs: [list]62      transform: ${{ filter(steps.list.output.entries, e => e.type == "file" && contains(vars.extensions, lower(extname(e.name)))) }}63    - id: prepare64      tool: filesystem.mkdir65      with:66        path: ${{ params.outputFolder }}67    - id: convert68      name: Convert each image69      needs: [images, prepare]70      foreach: ${{ steps.images.output }}71      as: image72      concurrency: 473      collect: one74      steps:75        - id: one76          tool: documents.imageConvert77          with:78            source: ${{ image.path }}79            destination: ${{ params.outputFolder }}/${{ params.prefix }}-${{ index + 1 }}.${{ params.format }}80            format: ${{ params.format }}81            quality: 0.8582            overwrite: false83    - id: converted84      needs: [convert]85      tool: filesystem.list86      with:87        path: ${{ params.outputFolder }}88        recursive: false89    - id: check90      needs: [converted]91      verify:92        - truthy: ${{ len(steps.images.output) > 0 }}93        - equals: ["${{ steps.convert.output.count }}", "${{ len(steps.images.output) }}"]94        - equals: ["${{ sum(steps.convert.output.results, r => r.count) }}", "${{ len(steps.images.output) }}"]95        - truthy: ${{ count(steps.converted.output.entries, e => startsWith(e.name, params.prefix + "-") && endsWith(e.name, "." + params.format)) >= len(steps.images.output) }}96        - dirNonEmpty: ${{ params.outputFolder }}97    - id: result98      needs: [check]99      output:100        converted: ${{ steps.convert.output.count }}101        files: ${{ map(steps.convert.output.results, r => r.converted[0].destination) }}102        folder: ${{ params.outputFolder }}103
Files main
Menu

Theme