1

I have a script I've created that will pad a series of Jpgs, create a subdirectory in the working directory, move the padded Jpgs to the subdirectory, change to the subdirectory, and then use Imagemagick's convert command to overlay a single transparent .gif over the padded images. All but the last step works. If I run this script on one Jpg file it works correctly. But when I try it on multiple Jpgs it will only semi-work on one Jpg and not the others. I assume that I'm not using the correct naming variable in the last command, but I'm having no luck finding the correction.

Bash script:

#!/bin/bash

if yad \
--image "dialog-question" \
--title "Alert" \
--button=gtk-yes:0 \
--button=gtk-no:1 \
--text "Have you resized JPGs?"

then
  convert *.jpg "$i" -bordercolor black -border 120x0 "pad$i.jpg"

mkdir -p ./padded; mv pad*.jpg $_

cd padded

cp /home/mastergif/ggg.gif /home/test/padded

convert ggg.gif *.jpg "$i" -background black -gravity center -compose dstover -composite $i*.jpg
exec bash
else
exit 1
fi
Volker Siegel
  • 16,983
  • 5
  • 52
  • 79
whitewings
  • 2,377
  • 7
  • 32
  • 53
  • 1
    (1) I'm not familiar with the `convert` command, but, from your description of the result, it sounds like you need to run the final `convert` command once for *each* JPEG file (i.e., in a loop) rather than once for *all* the files.  (2) What is `$i`?  (3) Why does your script do `exec bash`? – G-Man Says 'Reinstate Monica' Mar 25 '16 at 07:28
  • @G-Man Thanks for the loop suggestion. I solved the problem. I don't know why `exec bash` is in there. I copied part of the script somewhere. I removed it from the script and the script runs fine, so I guess I don't need it. – whitewings Mar 25 '16 at 07:38
  • 1
    @user8547 The `exec bash` runs a new shell, but it will look like the script returned. The new shell runs in the new subdirectory, because of the `cd padded` above it. It's very confusing, but maybe it made sense for some situation. – Volker Siegel Sep 02 '16 at 18:25

1 Answers1

1

I solved the problem with the help of member G-Man. I needed a loop:

for i in *.jpg; do
c=$(($c+1))

convert ggg.gif "$i" -background black -gravity center -compose dstover -composite $c.jpg
done
whitewings
  • 2,377
  • 7
  • 32
  • 53