shell - Pass .txt list of .jpgs to convert (bash) -


i'm working on exercise requires me write shell script function take single command-line argument directory. script takes given directory, , finds .jpgs in directory , sub-directories, , creates image-strip of .jpgs in order of modification time (newest on bottom).

so far, i've written:

#!bin/bash/  dir=$1 #the first argument given saved dir variable   #find .jpgs in given directory #then ls run .jpgs, date format %s (in seconds) #sed lets 'cut' process ignore spaces in columns #fields 6 , 7 (the name , time stamp) cut , sorted modification date #then, field 2 (the file name) selected input #finally, entire sorted output saved in .txt file  find "$dir" -name "*.jpg" -exec ls -l --time-style=+%s {} + | sed 's/  */ /g' | cut -d' ' -f6,7 | sort -n | cut -d' ' -f2 > jgps.txt 

the script correctly outputs directory's .jpgs in order of time modification. part struggling on how give list in .txt file convert -append command create image-strip me (for aren't aware of command, inputted is: convert -append image1.jpg image2.jpg image3.jpg imagestrip.jpgwith imagestrip.jpg being name of completed image strip file made of previous 3 images).

i can't quite figure out how pass .txt list of files , paths command. i've been scouring man pages find possible solution no viable ones have arisen.

put list of filenames in file called filelist.txt , call convert filename prepended ampersand:

convert @filelist.txt -append result.jpg 

here's little example:

# create 3 blocks of colour convert xc:red[200x100]    red.png convert xc:lime[200x100]   green.png convert xc:blue[200x100]   blue.png  # put names in file called "filelist.txt" echo "red.png green.png blue.png" > filelist.txt  # tell imagemagick make strip convert @filelist.txt +append strip.png 

enter image description here

as there's image pesky space in name...

# make pesky 1 convert -background black -pointsize 128 -fill white label:"pesky" -resize x100 "image pesky space.png"  # whack in list im echo "red.png green.png blue.png 'image pesky space.png'" > filelist.txt  # im stuff convert @filelist.txt +append strip.png 

enter image description here

by way, poor practice parse output of ls in case there spaces in filenames. if want find list of images, across directories , sort them time, @ this:

# find image files - ignoring case, "jpg", "jpg" both work find . -type f -iname \*.jpg  # exec `stat` file ages , quoted names ... -exec stat --format "%y:%n {} \;  # sort that, , strip times , colon @ start ... | sort -n | sed 's/^.*://'  # put find . -type f -iname \*.jpg -exec stat --format "%y:%n {} \; | sort -n | sed 's/^.*://' 

now can either redirect filelist.txt , call convert this:

find ...as above... > file list.txt convert @filelist +append strip.jpg 

or, if want avoid intermediate files , in 1 go, can make monster convert reads filelist standard input stream:

find ...as above... | sed 's/^.*://' | convert @- +append strip.jpg 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -