Linux - A script to combine 2 images

October 2016

Wondering how to combine two pictures? There Gimp is perfect but it is also a lengthy process.
Here's a small script that will allow you to assemble two or more images (you can just change the script accordingly).

The code

echo  -n "give the name of the first image with the path "      
read image1     
echo  -n "give the name of the second image with the path"     
read image2     
echo  -n "name of file generated "     
read image3     
#echo -n " output size ex:800x600(will generate an image of 1600x600) "     
echo -n "Modify the size y/n "     
read modifiy     
case $modifiy in      
 montage  -geometry +1+1  $image1 $image2 $image3     
   gpicview $image3 &     
echo -n " output size ex:800x600(donnera 1600x600) "     
read taille     
echo -n " border y/n "     
read reponse      

case $reponse in     

 O|o )     



montage  -geometry $size1 $image1 $image2 $image3     

gpicview $image3 &     



Creating the script

  • Open your text editor (vim gedit kate etc..), Make a copy/paste the code, save it, for example, assemblephotos.
  • Open a terminal
  • Navigate to the directory where you saved assemblephotos, then type:
  • chmod +x assemblephotos what makes your script executable.
  • To run:
    • ./assemblephotos 
  • The program at the ends opens the picture in your image viewer.
  • In the script
    • gpicview 
  • You can put another, simply replace gpicview with your own.
  • To make life easier, run the script in the directory where the photos are.
  • You can embellish the script at will. For additional commands from the command editing:
  • $man mount
  • Required program

For Windows users:
  • You need to install imagemagick for Windows
  • Start>Run>cmd

The script should look like that:

Microsoft Windows XP [version 5.1.2600]   
(C) Copyright 1985-2001 Microsoft Corp.   

C:\Documents and Settings\jxxxx>cd C:\Documents and Settings\All Users\Documents\   
Mes images\Échantillons d'images   

C:\Documents and Settings\All Users\Documents\Mes images\Échantillons d'images>   
montage  -geometry +1+1 collines.jpg hiver.jpg total.jpg   

C:\Documents and Settings\All Users\Documents\Mes images\Échantillons d'images>   


Related :

This document entitled « Linux - A script to combine 2 images  » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.