putting two images together


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting putting two images together
# 1  
Old 07-17-2012
putting two images together

Hi,

I generated many figures in .png format (approximately 120). Right now I need to pair the figures on a single page so that the files with the same file name (i.e. jack) that end with .matrix.png are placed on the left and .cdt.png is on the right (so jack.matrix.png with jack.cdt.png etc... many names). I was doing this using powerpoint and it is taking forever. I was wondering if there is some sort of short cut (command line or whatever) that can join the two images together. The file format of the output can be anything (.png, jpg, .ppt, etc).

Any help would be great

thanks

Last edited by kylle345; 07-17-2012 at 11:45 PM..
# 2  
Old 07-17-2012
The convert utility which is a part of imagemagick will do what you need. Basic command line is:

Code:
convert +append image1.jpg image2.jpg product.jpg

The two images are placed side by side; use -append for a 'top to bottom' arrangement. With this you can easily write a script to process all of the files.

If you don't already have it installed, this might be a good starting point:
http://www.imagemagick.org
This User Gave Thanks to agama For This Post:
# 3  
Old 07-17-2012
thanks it turns out I have the command function. So how would i do it for all the files simultaneously or consecutively (i.e. all files that match with the initial name e.g. joe.matrix.png matched with joe.cdt.png.... jack.matrix.png with jack.cdt.png)

Thanks
# 4  
Old 07-17-2012
If you have imagemagick installed this script should join your two images:

Code:
for left in *.matrix.png
do
   right=${left/matrix.png/cdt.png}
   result=${left/matrix.png/joined.png}
   [ -f "$right" ] && convert "$right" "$left" +append "$result"
done

# 5  
Old 07-18-2012
Thanks for the reply but I made a mistake in my explanation. I also need the initial names prior to the .cdt.png or .matrix.png to match. So if the name of the file is joe.cdt.png then I would want it to match joe.matrix.png. There are over 100 files with different names that need to be matched up and doing this manually is quite troublesome. Any help would be great

Thanks

---------- Post updated at 11:40 AM ---------- Previous update was at 12:26 AM ----------

Hi not sure if anyone can help me modify this code I wrote. Again I am trying to join two files that share the same name but different ending

Code:
for f in *.cdt; do var=`echo "$f" | sed 's/\.cdt$//'`; convert +append $var.cdt.png $var.matrix.png $var_merged.png; done

thanks
# 6  
Old 07-18-2012
How about this instead?

ls lists all files in the current folder.

awk selects .cdt files, and prints the filename minus the extension.

The loop checks for prefix.cdt.png and prefix.matrix.png and, if both are present, merges them with convert.

Code:
ls | awk -F"." '/[.]cdt$/ { print $1 }' | while read PREFIX
do
        [ -f "$PREFIX".cdt.png ] || continue
        [ -f "$PREFIX".matrix.png ] || continue
        echo convert +append ${PREFIX}.cdt.png ${PREFIX}.matrix.png ${PREFIX}_merged.png
done

Remove the 'echo' once you're sure it does what you want.
# 7  
Old 07-18-2012
Hi I have been working on this for a few hours now and still can't get it to work. Like I would put the command in but no files get outputted.

any help here would be great

thanks
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Hardware

Putting an old hd in a new computer

What are the steps you need to take when you put an old HD in a new computer? I just did this. Every time it makes it to the windows boot screen then restarts. I have a bunch of old engineering software that is not compatible with the newer versions of windows. I figured this out after I bought... (6 Replies)
Discussion started by: cokedude
6 Replies

2. Shell Programming and Scripting

Bash Script to find/sort/move images/duplicate images from USB drive

Ultimately, I'm looking to create a script that allows me to plug in a usb drive with lots of jpegs on it & copy them over to a folder on my hard drive. So in the process of copying I am looking to hash check them, record dupes to a file, copy only 1 of the identical files (if it doesn't exsist... (1 Reply)
Discussion started by: JonaQuinn
1 Replies

3. Shell Programming and Scripting

Other way aside from putting more PIPES (|)

I already manage to get the output that i want.. but wat if removing all the pipes and convert it 1 liner with less pipes. My command below can get the ouput that i want. i just want to remove the pipes or less pipes. #cat file1 us-west-2a running i-3397a421... (2 Replies)
Discussion started by: kenshinhimura
2 Replies

4. UNIX for Dummies Questions & Answers

Putting $$ before filename

Hello , I am searching a directory for a file and have to assign the filename to a variable . The variable must have form $$filename So my code is echo "'$$filename='`ls -lrt *PreMatch*.csv| head -1 | nawk '{print $9}'`" however $$ is converting to a number . How could I make it $$... (3 Replies)
Discussion started by: Pratik4891
3 Replies

5. Shell Programming and Scripting

Need help putting output on one line

Good afternoon, I have been searching the web, and these forums for help. I will try my best to explain the issue, and what my desired results are. I am doing queries in MYSQL, and need the output to be sent to a file. That file needs to have things with the same ID on the same line. To... (14 Replies)
Discussion started by: brianjb
14 Replies

6. Programming

putting numbers behind eachother

I want to make a program where you have to insert binary numbers like this: do { iBinary = getche(); }while(iBinary == 1 || iBinary == 0); after you get the numbers I want them to be placed behind eachother so you will get: input: 1 1 0 1 output: 1101 (7 Replies)
Discussion started by: metal005
7 Replies

7. UNIX for Dummies Questions & Answers

putting Linux on an old windows PC

Hello, I was just reading around these forums when I had an idea, without being able to really answer my question for myself due to some circumstances, so hopefully someone can give me a hand. I have an old desktop PC that has served me very well. I got an Asus G73JH though, so I mostly used the... (2 Replies)
Discussion started by: Patriots12
2 Replies

8. Shell Programming and Scripting

Putting a character between two other characters?

I need to separate Pascal style identifiers (TheyLookLikeThis) into words separated by an underscore (_). I've tried sed 's//&_&/' but this won't work (obviously). I'd love some help. (4 Replies)
Discussion started by: Ilja
4 Replies

9. UNIX for Dummies Questions & Answers

Putting Wallpaper on the Desktop

How do I put wallpaper from the internet on the Unix desktop? For example, I want to know how to perform the same operation as "right click-> Set as Wallpaper" on a graphics on a web page, in Windows. Thanks! :rolleyes: (3 Replies)
Discussion started by: pireifej
3 Replies

10. UNIX for Dummies Questions & Answers

Putting pC on network

How do I put a my PC with linux 7.0 on a class B network. Can someone give me info or text that will guide me? (1 Reply)
Discussion started by: Rush
1 Replies
Login or Register to Ask a Question