Birger Olsson
Avslutat medlemskap
Vilken version kör du Carl? Inga skräptecken? Allt på en rad? Punkt och inte komma?
Senast ändrad:
Plusmedlemskap kostar 349 kr per år
Follow along with the video below to see how to install our site as a web app on your home screen.
Notera: This feature may not be available in some browsers.
#!/usr/bin/php
<?php
$camera="/media/NIKON D50/";
$src="/media/NIKON D50/DCIM/";
$dstraw="/home/per/Foton/Orginalbilder/";
$dstjpg="/home/per/Foton/Orginalbilder/";
$tmp="/home/per/Foton/Orginalbilder/".time()."/";
function my_exit($str) {
exit("FEL - ".$str."\n\n");
}
if (in_array($argv[1], array('--help', '-help', '-h', '-?'))) {
?>
Ett bildflyttarskript för att flytta raw och jpgfiler
<?php
} else {
echo $argv[1];
if (!exec("which jhead")) my_exit("Programmet Jhead saknas, installera det! (apt-get install jhead)");
if (!exec("which exiftool")) my_exit("Programmet Exiftool saknas, installera det! (apt-get install libimage-exiftool-perl)");
is_dir($src) or my_exit("Källkatalogen ".$src." saknas, glömt att plugga in kameran?");
is_dir($dstjpg) or my_exit("Målkatalogen ".$dstjpg." saknas, sätt i hårddisk eller något");
is_dir($dstraw) or my_exit("Målkatalogen ".$dstraw." saknas, sätt i hårddisk eller något");
@mkdir($tmp) or my_exit("Kan inte skapa tempkatalog");
disk_free_space($tmp)>1000000000 or my_exit("För lite utrymme");
echo "Kopierar bilderna från kameran\n";
exec("cp -r ".str_replace(" ","\ ",$src)."* ". escapeshellarg($tmp));
echo "Raderar data\n";
exec("rm -rf ".str_replace(" ","\ ",$src)."*");
exec("umount ".str_replace(" ","\ ",$camera));
echo "Klar! nu går det att stänga av kameran\n\n";
echo "Flyttar och döper om filer\n\n";
foreach (scandir($tmp) as $dir ){
$tmpdir=$tmp.$dir;
if ($dir != '.' && $dir != '..' && is_dir($tmpdir)){
foreach (glob($tmpdir."/*") as $file) {
$extension=pathinfo($file,PATHINFO_EXTENSION);
if($extension=="NEF" || $extension=="JPG") {
$date=exec("exiftool -fast -s -s -s -EXIF:CreateDate ".str_replace(" ","\ ",$file));
$time=substr($date,11,5);
$time=str_replace(":","",$time);
$hour=substr($date,11,2);
$sec="s".substr($date,17,2);
$date=str_replace(":","-",substr($date,0,10));
if($hour<4) {
$datedir=strtotime($date);
$datedir=date("Y-m-d",$datedir-3600*24);
} else {
$datedir=$date;
}
touch($file,strtotime("$date $time$sec")); // ställer in filsystemtid från exif
if($extension=="NEF"){
$newdir=$dstraw.$datedir;
$ext=".nef";
} else {
$newdir=$dstjpg.$datedir;
$ext=".jpg";
exec("jhead -autorot ".str_replace(" ","\ ",$file));
}
if(!is_dir($newdir)){
@mkdir($newdir) or my_exit("Får ej skapa målkatalog");
}
echo "Importerar ".basename($file)."\n";
$newfile="$newdir/$date $time";
// Flytta in filen till rätt ställe, bara kolla om det finns fler med samma tid först
unset($equal_hm,$equal_s);
foreach ( scandir($newdir) as $f ) {
if ( strstr($f,"$date $time")&& strstr($f,$ext)){
$equal_hm["$newdir/$f"]="foo";
}
}
if( !$equal_hm) {
// det ingen fil med samma H:M, spara med H:M
rename($file,$newfile.$ext);
} else {
// det finns filer med samma H:M
// sparar med H:M-num
// kollar hur många det är och fixar första om det bara är en
$no_files_equal_hm = count($equal_hm);
$no=$no_files_equal_hm + 1;
rename($file,$newfile."-".$no.$ext);
if($no_files_equal_hm==1) {
list($file2, $sec2) = each($equal_hm);
rename($file2,substr($file2,0,-4)."-1".$ext);
}
}
}
}
exec("rmdir ".str_replace(" ","\ ",$tmpdir));
}
}
exec("rmdir ".str_replace(" ","\ ",$tmp));
}
echo "\nKlar!\n\n";
$line = trim(fgets(STDIN));
?>
Och titta på de ställen där SRC expanderas. Eventuellt kan du behöva stoppa ":ar run expansionerna.
#! /bin/bash
prefix=foo
compare=no
last=0
for f in *.jpg; do
echo f==${f}
f1=${f#${prefix}}
f2=${f1%.jpg}
if [ ${compare} == yes ]; then
while ! ((${last}+1 == ${f2})); do
cp -p "${prefix}${last}.jpg" "${prefix}$((${last}+1)).jpg"
last=$((${last}+1))
done
last=$((${last}+1))
else
compare=yes
last=${f2}
fi
echo f2=${f2}
done
#!/bin/bash
convert_image() {
for arg; do
dirname=${arg%/*}
prefix_arg=${arg/$dirname\//web_}
convert -scale 400x400 -unsharp 0.5x0.5+1.65+0.03 \
-quality 76 "$arg" "$prefix_arg"
done
}
export -f convert_image
NPROC=`grep ^processor /proc/cpuinfo | wc -l`
find . -name '*.jpg' -print0 | xargs -0 -n 1 -P $NPROC bash -c 'convert_image "$@"' --
#!/bin/bash
# Before running this script you might want to edit
# some lines, or remark some for which you do not need,
# At least take a look in the gps-section, if you do
# or do not have such a device.
clear
rm -rf /tmp/foto
mkdir /tmp/foto
date +20%y-%m-%d > /tmp/foto/date
echo "Rensat från tmp filer..."
#----------- Check -----------------
zenity --question --title "Time" --text "Is time correct? `date +20%y-%m-%d`"
case $? in
0) :;; #ok
1) exit 0;; #cancel
esac
echo ""
if [ -e /dev/ttyUSB0 ];
then echo "Gps-device present"
touch /tmp/foto/gps
else zenity --question --text "/dev/ttyUSB0 not found, skip gps?"
case $? in
0) :;; #ok
1) zenity --info --text "Aborted." #Cancel
exit 0;;
esac
fi
#----------- Here we go -----------
echo ""
#Kopies gps-data to tmp
#If you have a ex. Garmin-device you might want to
#change the -i -option to "garmin" instead of dg-100.
#Also, see the 'erase' section here, on the second line, 'erase' is set to "1"
#and will erase all data on the device after successful transmission.
if [ -e /tmp/foto/gps ] ; then
zenity --question --text "Charge /tmp with gps-data now?" --timeout=10
case $? in
0) gpsbabel -i dg-100,erase=0 -f /dev/ttyUSB0 -o gpx -F /tmp/`date +20%y-%m-%d`.gpx
gpsbabel -i dg-100,erase=1 -f /dev/ttyUSB0 -o kml -F /tmp/`date +20%y-%m-%d`.kml ;;
1) zenity --info --text "Aborted."
exit 0;;
esac
else :
fi
echo ""
#---- Create creation-date -folder ---
#---- and copy files with some mods --
zenity --info --text "Ready to handle all files!"
for x in $1/* ; do
echo "processing $x"
mkdir -p $2/$(exiv2 $x | grep timestamp | awk '{print $4}' | sed 's/:/-/g')
if [ -e /tmp/foto/gps ]
then gpscorrelate --timeadd +01 -g /tmp/`date +20%y-%m-%d`.gpx $x #gps-tags
echo $x tagged!
else :
fi
case $x in
*.jpg)
jhead -autorot $x;;
*.JPG)
jhead -autorot $x;;
*);;
esac
/bin/cp -p $x $2/$(exiv2 $x | grep timestamp | awk '{print $4}' | sed 's/:/-/g')
done
if [ -d $2/gps-trashcan -a -e /tmp/`date +20%y-%m-%d`.??? ];
then cp /tmp/`date +20%y-%m-%d`.??? $2/gps-trashcan/ && echo 'Copied gps-files to trashcan.'
fi
exit 0
#!/bin/bash
# Before running this script you might want to edit
# some lines, or remark some for which you do not need,
# At least take a look in the gps-section, if you do
# or do not have such a device.
clear
rm -rf /tmp/foto
mkdir /tmp/foto
date +20%y-%m-%d > /tmp/foto/date
echo "Rensat från tmp filer..."
#----------- Check -----------------
if [ ! -d "$2"]; then
echo "Mount your kamera first."
exit 0
fi
echo `date +20%y-%m-%d` # Check time
echo 'Is time correct? (y/n)?'
read -p "" ANS ;
if [ "$ANS" = "y" ] ;
then :
else echo "Correct time first, then rerun the script"
fi
echo ""
if [ -e /dev/ttyUSB0 ] # Is gps attached?
then echo "Gps-device present.." && touch /tmp/foto/do-gps
else echo "/dev/ttyUSB0 not found, is your device powered on?"
echo "Continue without adding coordinates?"
read -p 'Continue (y/n)?' ANS
if [ "$ANS" = "y" ];
then echo "No coordinates it is..."
else exit 0
fi
fi
#----------- Here we go -----------
echo ""
#Kopies gps-data to tmp
#If you have a ex. Garmin-device you might want to
#change the -i -option to "garmin" instead of dg-100.
#Also, see the 'erase' section here, on the second line, 'erase' is set to "1"
#and will erase all data on the device after successful transmission.
if [ -e /tmp/foto/do-gps ]
then echo "Loading /tmp with gps-data..."
gpsbabel -i dg-100,erase=0 -f /dev/ttyUSB0 -o gpx -F /tmp/`date +20%y-%m-%d`.gpx
gpsbabel -i dg-100,erase=1 -f /dev/ttyUSB0 -o kml -F /tmp/`date +20%y-%m-%d`.kml
# stty -F /dev/ttyUSB0 -parenb cs8 cread 115200 -cstopb # (Might need this, if no ttyUSB*)
else :
fi
echo ""
#---- Create creation-date -folder ---
#---- and copy files with some mods --
for x in $1/* ; do
echo "processing $x"
mkdir -p $2/$(exiv2 $x | grep timestamp | awk '{print $4}' | sed 's/:/-/g')
if [ -e /tmp/foto/do-gps ]
then gpscorrelate --timeadd +01 -g /tmp/`date +20%y-%m-%d`.gpx $x #gps-tags
echo $x tagged!
else :
fi
case $x in
*.jpg)
jhead -autorot $x;;
*.JPG)
jhead -autorot $x;;
*);;
esac
/bin/cp -p $x $2/$(exiv2 $x | grep timestamp | awk '{print $4}' | sed 's/:/-/g')
done
if [ -d $2/gps-trashcan -a -e /tmp/`date +20%y-%m-%d`.??? ];
then cp /tmp/`date +20%y-%m-%d`.??? $2/gps-trashcan/ && echo 'Copied gps-files to trashcan.'
fi
echo 'All done!'
exit 0