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
3
  • 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? Mar 25, 2016 at 7: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, 2016 at 7: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. Sep 2, 2016 at 18:25

1 Answer 1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .