LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-03-2015, 03:20 PM   #1
emmfranklin
LQ Newbie
 
Registered: Jun 2015
Posts: 13

Rep: Reputation: Disabled
add filename as text in an image file.


Hi

I have a bunch of jpeg images.

say 001abcd.jpg
002abcd.jpg

and so on .

what i want is capture the filename and add it as a text in the image itself in one corner.
so the result would be .. for example the file 003abcd.jpg will have "003abcd" imprinted in one corner of that image. (extension need not be there)


i want a terminal command that can batch process hundreds of images and add its own filenames in its respective images.

i am using linux mint 17

something tells me that imagemagick can be useful..but i dont know scripting.

it is easy to put a single common text in all images. but i dont know how to put unique filenames as the text in the respective images in one go.
 
Old 06-04-2015, 10:34 AM   #2
mjolnir
Member
 
Registered: Apr 2003
Posts: 842

Rep: Reputation: 109Reputation: 109
Hello, and welcome to the forum. I'm "bumping" this because that sounds like a script I would also like to see. As you say it is easy to rename and add "common text" to all the images.
 
Old 06-04-2015, 10:48 AM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 27,186

Rep: Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064Reputation: 8064
Quote:
Originally Posted by emmfranklin View Post
Hi
I have a bunch of jpeg images.

say 001abcd.jpg 002abcd.jpg

and so on. what i want is capture the filename and add it as a text in the image itself in one corner. so the result would be .. for example the file 003abcd.jpg will have "003abcd" imprinted in one corner of that image. (extension need not be there)

i want a terminal command that can batch process hundreds of images and add its own filenames in its respective images. i am using linux mint 17 something tells me that imagemagick can be useful..but i dont know scripting. it is easy to put a single common text in all images. but i dont know how to put unique filenames as the text in the respective images in one go.
You are correct, and imagemagick can be used for this. Read their documentation:
http://www.imagemagick.org/Usage/annotating/#annotating

There are MANY easily-found bash scripting tutorials, so start there. We will be happy to HELP you if you're stuck, but this isn't the place to come and have someone write a script for you. Post what YOU have written/tried of your own, and we can help from there.

Otherwise, try looking up "bash script to return file names" in Google, which pulls up lots of methods to do this. Then, look up how to loop through all the files in a directory, and apply the action you would have found from the imagemagick page linked to you above.

You have all the tools needed to do this yourself.
 
1 members found this post helpful.
Old 06-06-2015, 03:21 AM   #4
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
There is also graphicsmagick a fork of imagemagick.
 
Old 06-06-2015, 03:30 PM   #5
buffer overflow
LQ Newbie
 
Registered: May 2015
Posts: 10

Rep: Reputation: Disabled
Here's a simple for loop script

Code:
for i in *.[Jj][Pp][Gg]; do convert "$i" label:"${i%.*}" -gravity East -append $HOME/tmp/"$i"; done
  1. The *.[Jj][Pp][Gg] will cover all image files with a mix of upper and lower case jpg letters.
  2. The "${i%.*}" will print the filename into the image minus the extension.
  3. The -gravity East will print the text in the lower right corner

Since you said, you wanted the filenames to match or reference the text in the images, then you will need to export the final results into a different location. The convert command will overwrite files without asking if present in the same folder.

The $HOME/tmp/"$i" does this. Create a tmp folder in the root directory of your home folder.

Note: I am using the tmp folder in this example, but you can use any folder for the final results, just make sure you put the correct path for the newly created images in the code above.

PS: Execute the script on a few test images to see if the results are what you're looking for.

Last edited by buffer overflow; 06-06-2015 at 03:51 PM.
 
1 members found this post helpful.
Old 06-07-2015, 09:28 AM   #6
mjolnir
Member
 
Registered: Apr 2003
Posts: 842

Rep: Reputation: 109Reputation: 109
Quote:
Originally Posted by buffer overflow View Post
Here's a simple for loop script

Code:
for i in *.[Jj][Pp][Gg]; do convert "$i" label:"${i.*}" -gravity East -append $HOME/tmp/"$i"; done
  1. The *.[Jj][Pp][Gg] will cover all image files with a mix of upper and lower case jpg letters.
  2. The "${i%.*}" will print the filename into the image minus the extension.
  3. The -gravity East will print the text in the lower right corner

Since you said, you wanted the filenames to match or reference the text in the images, then you will need to export the final results into a different location. The convert command will overwrite files without asking if present in the same folder.

The $HOME/tmp/"$i" does this. Create a tmp folder in the root directory of your home folder.

Note: I am using the tmp folder in this example, but you can use any folder for the final results, just make sure you put the correct path for the newly created images in the code above.

PS: Execute the script on a few test images to see if the results are what you're looking for.
I'm not the OP but it works fine for me, thanks. I already had a couple of perl scripts that I was using to batch process (annotate, re-size and rename) my photos. With the genesis of this thread I found and added a "mogrify" statement to the script that does what I wanted, gives me the option to add the file name as a second annotation but it's always nice to see another approach.

Last edited by mjolnir; 06-07-2015 at 09:38 AM.
 
Old 06-07-2015, 01:15 PM   #7
buffer overflow
LQ Newbie
 
Registered: May 2015
Posts: 10

Rep: Reputation: Disabled
Thanks mjolnir.

BTW, I noticed the code you quoted back to me is missing the percent sign '%' in the code.

Not sure if it's firefox or the the LQ forum software. I've noticed that certain characters will not show at all when using the code tag. When I posted the code yesterday, the % sign didn't appeared in the code as well. I was stomp as to why. Then I tried the Go Advanced edit feature and the percent sign appeared in the code as it should be.

It's very weird...

Last edited by buffer overflow; 06-07-2015 at 01:31 PM.
 
Old 06-07-2015, 01:31 PM   #8
emmfranklin
LQ Newbie
 
Registered: Jun 2015
Posts: 13

Original Poster
Rep: Reputation: Disabled
Thanks Buffer Overflow you solved it . this was part of an Infrared Motion Detection project

[QUOTE] You solved my case Buffer Overflow and i made few alternatives using your idea.

Code:
for i in *.[Jj][Pp][Gg]; do convert "$i" -background black -fill white -pointsize 30 label:"${i%.*}" -gravity South -append $HOME/tmp/"$i"; done

this command
adds filename over the image as text
in the bottom center
background black
and text is white
the result is all copied in a tmp folder in the home folder


Code:
for i in *.[Jj][Pp][Gg]; do convert "$i" -background none -fill white -pointsize 30 label:"${i%.*}" -gravity South -composite -append $HOME/tmp/"$i"; done

this command

background transparent
and text is white

rest all same


Code:
for i in *.[Jj][Pp][Gg]; do convert "$i" -background none -fill white -font DejaVu-Sans-Bold -pointsize 30 -strokewidth 1 -stroke black label:"${i%.*}" -gravity East -composite -append $HOME/tmp/"$i"; done
this command

bottom right
background transparent
and text is white
font is dejavusans bold
with black outline
rest all same


thats all
thanks again everyone..

you need not read further i am just describing why i needed this idea.

Infrared Motion detection guide.
the purpose of my question was a project i am trying.
i needed to install a motion detection infrared camera (something like paranormal activity)(i am serious)

i needed
an infrared camera . ( i am going to convert a cheap webcam to infrared) (not done yet)

a motion detection software. ( linux has a software called motion)
it clicks pictures continuously the moment it sees a movement. in the end i get a large number of jpeg images .
a 30 sec movement caused approximately 800 images to be captured by motion software. each jpeg image had the date and time signature as the filename.

motion is working well as expected in my laptop .
next
i have to stitch all the images into a single video and see the result as a continuous video.
this is also successful by using a terminal command

so my whole project is successful as long as im trying it during the day time using a normal webcam.

technically my project is complete for a day camera job.

one question came into my mind.

consider i kept the camera on for 8 hours. and the images got captured whenever there was movement.
i might end up with several thousands of images.

i would even combine the entire images into video.
now while seeing the video
how can one find out at what time did a given movement happened.

for example consider a bird came and sat on the table at 1.30 pm.
definetly the motion will be captured. and i would be able to make the video later.

but how can i find out at what time the bird come on the table.
one difficult way is to see every image in the entire batch of thousands of images and see when the picture of bird was captured. the filename will give the answer for my time.

another idea i thought was to keep a digital table clock in front of the camera view somewhere in the room.
but that was silly. idea.

because everytime the time would change the software would detect motion and would capture unnecessary images. in the end it may capture the entire 8 hours length of images.

no use.

finally i thought . there should be a software technique to imprint the filename onto the image as text somewhere in the bottom. because the filename has the time signature already.

so when i run the video later i ll get to see the time signature also . that will help me to know what time the event occured.

this is exactly what you solved. thanks ..again Buffer Overflow.

so now not only this is a solution to my question . this is also a guide to make a motion detection video.
 
Old 06-07-2015, 01:34 PM   #9
buffer overflow
LQ Newbie
 
Registered: May 2015
Posts: 10

Rep: Reputation: Disabled
You''re welcome emmfranklin and welcome to LQ!
 
Old 06-07-2015, 07:46 PM   #10
buffer overflow
LQ Newbie
 
Registered: May 2015
Posts: 10

Rep: Reputation: Disabled
@ emmfranklin

I was experimenting with the gravity option. You probably may know this. But you can put the texts in the extreme corners by using NorthEast, NorthWest,SouthWest and SouthEast with the gravity switch.
Attached Thumbnails
Click image for larger version

Name:	northeast.jpg
Views:	28
Size:	3.9 KB
ID:	18640   Click image for larger version

Name:	northwest.jpg
Views:	24
Size:	4.0 KB
ID:	18641   Click image for larger version

Name:	southeast.jpg
Views:	19
Size:	4.0 KB
ID:	18642   Click image for larger version

Name:	southwest.jpg
Views:	16
Size:	4.2 KB
ID:	18643  

Last edited by buffer overflow; 06-07-2015 at 09:22 PM.
 
1 members found this post helpful.
Old 06-08-2015, 12:39 AM   #11
emmfranklin
LQ Newbie
 
Registered: Jun 2015
Posts: 13

Original Poster
Rep: Reputation: Disabled
Yes Buffer overflow

You are right again

The SouthEast argument brings the text to the right hand side corner bottom

While East brings it to right centre

All interested readers may experiment with North, East, West, South, or NorthEast,NorthWest, SouthEast, Southwest.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
sed - How to add filename again at the end of a file temm Programming 15 02-25-2012 08:46 AM
Add text from mysql to image mspec Linux - Newbie 1 02-25-2012 04:40 AM
[SOLVED] Add filename to file output sarenace Programming 4 02-06-2012 04:34 PM
How to Add Text to An Image? VorlonInfoTech Linux - Software 1 02-01-2004 09:23 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration