Perl Skript jpgs4m740.pl

Aus M740 WikiWeb

Wechseln zu: Navigation, Suche


Übersicht

Betriebssystem:

Funktionen:

  • Berechnet thumbnails und Playlisten für jpg Bilder

Bedienung:

  • Durch Aufruf mit --help (zwei mal Minus) erhält man eine kleine online Hilfe.
  • Man befinde sich im gesharten Verzeichnis. Man wechsle in ein Verzeichnis mit jpg Bildern z.B. mit cd jpgs. Dann mit folgendem Aufruf die thumbs und Playlist für alle jpg Bilder erzeugen: jpgs4m740.pl -p /pvr/media/PC1/jpgs. Eine Playlist jpgs.plp wird hierbei erzeugt. Der Pfad für die USB-HDD ist wohl immer /pvr/media/USB-HDD/.

Änderungen

  • Verwendung von montage anstatt convert da damit Bilder nicht unnötig verzerrt werden und auch Bilder in portrait Orientierung richtig behandelt werden. Aufgabe der Unterstützung von nconvert da (noch) keine entspr. Lösung für XnView bekannt.
  • Tobias Hüttner: Habe das Skript auch unter Windows zum Laufen gebracht und etwas erweitert, es arbeitet nun auch rekursiv über Directorybäume

Das Skript

Am Einfachsten per copy and paste in jpgs4m740.pl speichern. Ggf. ausführbar machen (chmod 755 jpgs4m740.pl).

#! /usr/bin/perl -w
#
################################################################################
# author       : Josef G. Bauer (http://www.m740.de/wiki/index.php/Benutzer:Jgb)
# description  : create image thumbs and playlist for Siemens M 740 AV
# dependencies : perl, ImageMagick (http://www.imagemagick.org)
################################################################################

# default values
$path = "/pvr/media/PC1/jpgs";
$use_nconvert = 0;
$force_new_thumbs = 0;

sub usage
{
    print "$0 --- create thumbs and playlist for jpg images for the Siemens M 740 AV\n";
    print "$0 --- usage: $0 [--help] [OPTIONS]\n";
    print "\t\t options:\n";
    print "\t\t  --help     show this usage\n";
    print "\t\t  -p #       path [$path]\n";
    print "\t\t  -n         deprecated option: use nconvert (XnView) [use montage (ImageMagick)]\n";
    print "\t\t  -f         for new thumbs [only if outdated]\n";
   
    exit;
}

# process command line options
while ( $#ARGV>=0 )
{
    $_ = $ARGV[0];

    if ( /^-p$/ ) { shift; $path = shift; next;}
    if ( /^--help$/ ) { usage;}
    if ( /^-n$/ ) { shift; $use_nconvert = 1; next}
    if ( /^-f$/ ) { shift; $force_new_thumbs = 1; next}

    if ( /^-/ ) {
        print STDERR "$0: ERROR: unrecognized option '$_' ?\n";
        usage;
    }
    last;
}

# get list of jpgs
@jpgs = (glob("*.JPG"), glob("*.jpg"));

# create thumbs
foreach $p ( @jpgs )
{
    $_ = $p;
    s/\.jpg$//gxi;
    if ( $force_new_thumbs || !(-r "$_.ths") || ( (-M $p) < (-M "$_.ths") ) )
    {
	if ( $use_nconvert ) # nconvert (XnView)
	{
	    $cmd = "nconvert -resize 720 576 -out png -o $_.ths $p";
	    system( $cmd );
	    $cmd = "nconvert -resize 240 192 -out png -o $_.thp -in png $_.ths";
	    system( $cmd );
	    print "$p\n";
	}
	else # convert (ImageMagick)
	{
	    $cmd = "montage -background black -geometry 720x576 $p png:$_.ths";
	    system( $cmd );
	    $cmd = "montage -background black -geometry 240x192 png:$_.ths png:$_.thp";
	    system( $cmd );
	    print "$p\n";
	}
    }
}

# create playlist
unless ( open(FH, ">jpgs.plp" ) ) { die "$0: can't open playlist"; }
print FH << 'EOF';
Name	(null)
EOF
print FH "FileURL	$path/jpgs.plp\n";
print FH << 'EOF';
MimeType	(null)
CreationTime	0
LastModificationTime	0
Looping	1
PlaybackMode	1
EOF
$N = ($#jpgs) + 1;
print FH "N\t$N\n";
$i = 0;
foreach $p ( @jpgs )
{
    $_ = $p;
    s/\.jpg$//gxi;
    print FH "\t$i	$path/$p\n";
    print FH "\t$i	(null)\n";
    print FH "\t$i	0\n";
    print FH "\t$i	(null)\n";
    print FH "\t$i	(null)\n";
    print FH "\t$i	$_\n";
    
    $i++;
}



#####################################  Neue Version, 12.2.2005

#! /usr/bin/perl -w
#
################################################################################
# author       : Josef G. Bauer (http://www.m740.de/wiki/index.php/Benutzer:Jgb)
# 		 modified by Tobias Hüttner:
# 		 added: 
# 		 	- recursive directory search
# description  : create image thumbs and playlist for Siemens M 740 AV and Siemens M 750 S
# dependencies : perl, ImageMagick (http://www.imagemagick.org)
################################################################################

# Please fill in your PC* and Playlist Settings here.
$PC1="/cygdrive/d/";
$PC2="/cygdrive/i/Reisen/";
$PC3="/cygdrive/e/Evas_Daten/Eigene\ Dateien/Bilder/";
$PC4="";
$PC5="";
$PlaylistPath="/pvr/media/PC3/Playlists/";

# don't modify below this line if you are user and not programmer
# initialization
$use_nconvert = 0;
$force_new_thumbs = 0;


sub usage
{
    print "$0 --- create thumbs and playlist for jpg images for the Siemens M 740 AV\n";
    print "\t\t usage:\n";
    print "\t\t  jpeg2Gigaset <pathname> (with trailing '/') <playliste name> (without .plp) [,force] (if force new thumbs)\n";
}

# process command line options

if ( $#ARGV>=1 )
{
    $path = $ARGV[0];
    $playlist = $ARGV[1];
    if ($#ARGV>=2)
    {
   	 if (index($ARGV[2],"force")>=0)
		{
			$force_new_thumbs=1;
		}
    }
}
else
{
	usage;
	die "";
}

use File::Find;
print "Path: $path\n\n";

$count=0;

find(\&countJPG, $path);

print "Count: $count\n\n";

unless ( open(FH, "> $playlist.plp" ) ) { die "Can't open playlist $playlist"; }
binmode(FH);

print FH "Name	$playlist\n";
print FH "FileURL	$PlaylistPath$playlist.plp\n";
print FH << 'EOF';
MimeType	(null)
CreationTime	0
LastModificationTime	0
Looping	1
PlaybackMode	1
EOF
print FH "N\t$count\n";

print "Playlist: $PlaylistPath$playlist.plp\n\n";

$index=0;
find(\&processDirectory, $path);


sub countJPG
{
	
	# get list of jpgs
	#@jpgs = (glob("*.JPG"), glob("*.jpg"));
	
	if (index($_,"JPG")>=0 || index($_,"jpg") >=0)
	{
		$count=$count+1;
	}
		
}

sub mapFileName
{
	local $filename = $_[0] ;
	
	$filename=~s/$PC1/\/pvr\/media\/PC1\//gi;
	$filename=~s/$PC2/\/pvr\/media\/PC2\//gi;
	$filename=~s/$PC3/\/pvr\/media\/PC3\//gi;
	$filename=~s/$PC4/\/pvr\/media\/PC4\//gi;
	$filename=~s/$PC5/\/pvr\/media\/PC5\//gi;

	$filename;
}
		

sub processDirectory
{
	
	if (index($_,"JPG")>=0 || index($_,"jpg") >=0)
	{
		$p = $File::Find::name;
		$f = $_;
    		s/\.jpg$//gxi;
   		if ( $force_new_thumbs || !(-r "$_.ths") || ( (-M $p) < (-M "$_.ths") ) )
   		{
			if ( $use_nconvert ) # nconvert (XnView)
				{
				    $cmd = "nconvert -resize 720 576 -out png -o $_.ths $p";
				    system( $cmd );
				    $cmd = "nconvert -resize 240 192 -out png -o $_.thp -in png $_.ths";
				    system( $cmd );
				}
				else # convert (ImageMagick)
				{
				    $cmd = "montage -background black -geometry 720x576 $f png:$_.ths";
				    system( $cmd );
				    $cmd = "convert -depth 8 png:$_.ths png:$_.ths";
				    system( $cmd );
				    #print "$cmd\n";
				    $cmd = "montage -background black -depth 8 -geometry 240x192 png:$_.ths png:$_.thp";
				    system( $cmd );
				    $cmd = "convert -depth 8 png:$_.thp png:$_.thp";
				    system( $cmd ); 
				}
			
		 }

		$fileindex=$index+1;
		print "$fileindex of $count: $p\n";

		# create playlist
		$filename=mapFileName($p);
    		print FH "\t$index	$filename\n";
   		print FH "\t$index	(null)\n";
    		print FH "\t$index	0\n";
    		print FH "\t$index	(null)\n";
    		print FH "\t$index	(null)\n";
    		print FH "\t$index	$_\n";
  
		$index=$index+1;
	}
}
Persönliche Werkzeuge