Register
It is currently Fri Oct 24, 2014 1:02 am

Modifying existing script. Please help.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 5 posts ] 
Author Message
 PostPosted: Mon Jan 16, 2012 6:46 am   

Joined: Mon Jan 16, 2012 6:22 am
Posts: 1
Hi,
This script takes all pictures in a folder and adds an invisible watermark using steganography.
I would like to modify it so that i can use a wordlist for watermarking (lets say 100 ID's/names) and then creating a picture with each ID where basename is 01.file.jpeg.

Example
01.copyrighted.jpeg (watermark: John)
02.copyrighted.jpeg (watermark: Jenny)
And so on.

I'm new to bash scripting, so if anyone could modify this script to meet the requirements i would be really greatful!

echo -n "insert watermark: "
read var_watermark
echo $var_watermark > watermark
echo -n "Enter Password: "
stty -echo
read watermarkpassword
stty echo
echo " "
ls -1 *.[jJ][pP][gG] | while read file;
do {
steghide embed -p $watermarkpassword -cf "$file" -ef "watermark" -sf "`basename TAGGED_"$file"`"
}
done
rm -f watermark
echo "Done"


Top
 Profile  
 PostPosted: Tue Jan 17, 2012 10:11 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
You should enclose your code into "code" tags: either use square brackets, or click on Code.

Also, instead of parsing output of ls, it's better to use
Code:
for *.[jJ][pP][gG] ; do
    steghide embed -p $watermarkpassword -cf "$file" -ef "watermark" -sf "`basename TAGGED_"$file"`"
done

To change the script to read the names from a file is easy:
Code:
#!/bin/bash
echo -n "Enter Password: "
stty -echo
read watermarkpassword
stty echo
echo " "
i=1
for *.[jJ][pP][gG] ; do
    read watermark
    echo $watermark > watermark
    steghide embed -p $watermarkpassword -cf "$file" -ef watermark -sf $(printf '%02d.copyrighted.jpeg' $i)
    let i++
done < watermarkfile
rm -f watermark
echo "Done"


Top
 Profile  
 PostPosted: Wed Mar 28, 2012 2:41 pm   

Joined: Mon Feb 16, 2009 10:07 am
Posts: 19
Location: Paris - France
The solution is correct ... with the little exception that the 'file' variable is not assigned a value :)
I would suggest this little correction to the solution :

Code:
#!/bin/bash
declare -i i
echo -n "Enter Password: "
read -s watermarkpassword
echo " "
shopt -s nocasematch nullglob ; files=*".jpg" ; shopt -u nocasematch nullglob
for file in $files ; do
        read watermark
        echo $watermark > watermark
        steghide embed -p $watermarkpassword -cf "$file" -ef watermark -sf $( printf '%02d.copyrighted.jpeg' $(( ++i )) )
done < watermarkfile
rm -f watermark
echo "Done"


Top
 Profile ICQ YIM  
 PostPosted: Wed Mar 28, 2012 2:59 pm   

Joined: Mon Feb 16, 2009 10:07 am
Posts: 19
Location: Paris - France
sorry, read 'nocaseglob' instead of 'nocasematch' in the script above
here is the script again, with correction :

Code:
#!/bin/bash
declare -i i
echo -n "Enter Password: "
# read -s : silent : no echo, so stty is not necessary
read -s watermarkpassword
echo " "
# nocaseglob : ignore case in pathname expansion
# nullglob : return null and not the pattern if no file is matching the pattern
shopt -s nocaseglob nullglob ; files=*".jpg" ; shopt -u nocaseglob nullglob
for file in $files ; do
        read watermark
        echo $watermark > watermark
        steghide embed -p $watermarkpassword -cf "$file" -ef watermark -sf $( printf '%02d.copyrighted.jpeg' $(( ++i )) )
done < watermarkfile
rm -f watermark

echo "Done"


Top
 Profile ICQ YIM  
 PostPosted: Wed Mar 28, 2012 3:18 pm   

Joined: Mon Feb 16, 2009 10:07 am
Posts: 19
Location: Paris - France
another correction to the solution : to support spaces in file names

Code:
#!/bin/bash
declare -i i
echo -n "Enter Password: "
# read -s : silent : no echo, so stty is not necessary
read -s watermarkpassword
echo " "
# nocaseglob : ignore case in pathname expansion
# nullglob : return null and not the pattern if no file is matching the pattern
shopt -s nocaseglob nullglob ; files=( *".jpg" ); shopt -u nocaseglob nullglob
for file in "${files[@]}" ; do
        read watermark
        echo $watermark > watermark
        steghide embed -p $watermarkpassword -cf "$file" -ef watermark -sf $( printf '%02d.copyrighted.jpeg' $(( ++i )) )
done < watermarkfile
rm -f watermark
echo "Done"


Top
 Profile ICQ YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP