Skip to content

Commit 361db66

Browse files
Copilotelifarley
andcommitted
Address code review feedback for vhs-strip-metadata.sh
- Support both ImageMagick v6 (convert) and v7 (magick) commands - Optimize find command to use single invocation with path pattern - Add CONVERT_CMD variable to dynamically select the right command - Verified end-to-end: deterministic output still works correctly Co-authored-by: elifarley <519940+elifarley@users.noreply.github.com>
1 parent fa4bd2d commit 361db66

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

docs/screencasts/bin/vhs-strip-metadata.sh

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ readonly NC='\033[0m'
4141
# Options (defaults)
4242
DRY_RUN=false
4343

44+
# ImageMagick command (will be set by check_imagemagick)
45+
CONVERT_CMD=""
46+
4447
#==============================================================================
4548
# Output Functions
4649
#==============================================================================
@@ -60,8 +63,17 @@ error() { msg "$RED" "ERROR: $*" >&2; exit 1; }
6063
#==============================================================================
6164

6265
check_imagemagick() {
63-
if ! command -v convert &> /dev/null; then
64-
error "ImageMagick's 'convert' command not found.\nInstall it with: sudo apt-get install imagemagick"
66+
# Check if ImageMagick is available (try both v7 'magick' and v6 'convert')
67+
if command -v magick &> /dev/null; then
68+
# ImageMagick 7+ uses 'magick' command
69+
CONVERT_CMD="magick"
70+
return 0
71+
elif command -v convert &> /dev/null; then
72+
# ImageMagick 6 uses 'convert' command
73+
CONVERT_CMD="convert"
74+
return 0
75+
else
76+
error "ImageMagick not found.\nInstall it with: sudo apt-get install imagemagick"
6577
fi
6678
}
6779

@@ -77,8 +89,8 @@ strip_image_metadata() {
7789
# Create temp file for the stripped version
7890
local temp_file="${image_file}.tmp"
7991

80-
# Strip metadata using ImageMagick
81-
if convert "$image_file" -strip "$temp_file" 2>/dev/null; then
92+
# Strip metadata using ImageMagick (supports both v6 'convert' and v7 'magick')
93+
if "$CONVERT_CMD" "$image_file" -strip "$temp_file" 2>/dev/null; then
8294
# Replace original with stripped version
8395
mv "$temp_file" "$image_file"
8496
return 0
@@ -91,8 +103,8 @@ strip_image_metadata() {
91103
}
92104

93105
find_image_files() {
94-
# Find all PNG and GIF files in docs/**/img/ directories
95-
find "$DOCS_DIR" -type d -name "img" -exec find {} -type f \( -name "*.png" -o -name "*.gif" \) \; | sort
106+
# Find all PNG and GIF files in docs/**/img/ directories using a single find command
107+
find "$DOCS_DIR" -path "*/img/*" -type f \( -name "*.png" -o -name "*.gif" \) | sort
96108
}
97109

98110
process_images() {

0 commit comments

Comments
 (0)