0

I have several hundreds of images in one folder (Folder A) that need to be merged with 2 files in another folder (Folder B).

Folder A contains square 100x100 images. I've created a header and footer that are 100px wide that are in Folder B.

I need to merge the header and footer in Folder B with the square images in Folder A.

So the end result should be:

-- HEADER --
  -IMAGE-
-- FOOTER --

I did a test for one image (see command below) where the header, image, and footer existed in the same folder, but how do I batch process it given my situation above?

convert -append -quality 100 -gravity Center "C:\test\*.jpg" "C:\test\output\img.jpg"

The other option may be to have one single file with a mask for the image so it gets inserted between the header and footer?

kaoscify
  • 1,743
  • 7
  • 37
  • 74

2 Answers2

2

For windows, is a good place to start.

Get-ChildItem C:\FolderA -Filter *.jpg | Foreach-Object {
    $img = $_.FullName
    $out = Join-Path C:\test $_.Name
    convert.exe C:\FolderB\header.jpg $img C:\FolderB\footer.jpg -append $out
}

For Unix/OSX/Linux, use

for img in `ls ./FolderA/*.jpg`; do
    convert ./FolderB/header.jpg $img ./FolderB/footer.jpg -append ./test/$out
done
emcconville
  • 23,800
  • 4
  • 50
  • 66
  • @MarkSetchell, by no means am I a `powershell` person, but a quick search on the included tag-link revealed [this](http://stackoverflow.com/a/18848848/438117) & [this](http://stackoverflow.com/a/13783881/438117). Everything else is standard. – emcconville Jul 14 '15 at 21:06
  • I get an error stating `convert.exe: unable to open image 'C:\output\C:\test\1.jpg': Invalid argument @ error/blob.c/OpenBlob/2695`. It's weird that the path looks like that? – kaoscify Jul 14 '15 at 22:44
  • @mapr - Ah, I'm a fool. `FullName` includes the complete OS path, not the filename. Updated answer to use `$_.Name` macro – emcconville Jul 15 '15 at 01:52
  • @emcconville Thank you! – kaoscify Jul 15 '15 at 05:29
2

Your question is very unclear - is there one single header and one single footer to go above and below each image, or does each image have its own header and footer - if so how do you tell which header/footer belong with which image? What is the output image supposed to be called? And so on...

Anyway, your solution will probably look something like this, although I never usually work in Windows, so make a backup first!

CD "Folder A"
FOR %%G in (*.JPG) DO convert "FolderB\header.jpg" "%%G" "FolderB\footer.jpg" -append "%%G"
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Sorry about the confusion. The header and footer remain the same for each image. The only thing that changes is the image in the middle. I will test your script out, thank you. – kaoscify Jul 14 '15 at 20:56
  • How can I specify a path to `(*.jpg)` in your code? If I add the path instead of CD into Folder A, then I get an error saying `C:\test\ was unexpected at this time`. – kaoscify Jul 14 '15 at 22:34
  • The following worked for me: `for /R "C:\FolderA" %g in (*.jpg) DO convert "C:\FolderB\header.png" "%g" "C:\FolderB\footer.jpg" -append "%g"`. Thanks so much for your help. – kaoscify Jul 14 '15 at 22:50
  • Glad to be of assistance :-) – Mark Setchell Jul 15 '15 at 13:29