From 0fd0ef9a1ec9325027b66235d9e204144ec79e7d Mon Sep 17 00:00:00 2001
From: David Rouquet <david.rouquet@tetras-libre.fr>
Date: Fri, 2 May 2025 16:13:02 +0200
Subject: [PATCH] crop images

---
 tetras_extraction/script/cropImages.sh | 31 ++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 tetras_extraction/script/cropImages.sh

diff --git a/tetras_extraction/script/cropImages.sh b/tetras_extraction/script/cropImages.sh
new file mode 100644
index 0000000..a35e009
--- /dev/null
+++ b/tetras_extraction/script/cropImages.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+# Check if the directory is provided as an argument
+if [ -z "$1" ]; then
+  echo "Usage: $0 <directory>"
+  exit 1
+fi
+
+# Get the directory from the first argument
+DIRECTORY=$1
+
+# Check if the provided argument is a directory
+if [ ! -d "$DIRECTORY" ]; then
+  echo "Error: $DIRECTORY is not a valid directory."
+  exit 1
+fi
+
+# Recursively iterate over files in the directory
+find "$DIRECTORY" -type f | while read -r filepath; do
+  # Check if the file is an image
+  file_type=$(file --mime-type -b "$filepath")
+  if [[ $file_type == image/* ]]; then
+    # Apply the magick convert command with -trim option
+    magick convert "$filepath" -trim "$filepath"
+    echo "Processed: $filepath"
+  else
+    echo "Skipped (not an image): $filepath"
+  fi
+done
+
+echo "All files processed."
-- 
GitLab