X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=driver%2Fxscreensaver-getimage-desktop;h=158dea0996d276933f93a1677d1965be5ff768bc;hp=40c6173cbc46a6c6a45b8e5891413c2642b5477a;hb=0d6b320def9180cf907ceaed56b23a972a11b757;hpb=3f438031d610c7e15fd33876a879b97e290e05fb diff --git a/driver/xscreensaver-getimage-desktop b/driver/xscreensaver-getimage-desktop index 40c6173c..158dea09 100755 --- a/driver/xscreensaver-getimage-desktop +++ b/driver/xscreensaver-getimage-desktop @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# Copyright © 2003 Jamie Zawinski . +# Copyright © 2003, 2005 Jamie Zawinski . # # Permission to use, copy, modify, distribute, and sell this software and its # documentation for any purpose is hereby granted without fee, provided that @@ -34,7 +34,7 @@ use diagnostics; use strict; my $progname = $0; $progname =~ s@.*/@@g; -my $version = q{ $Revision: 1.2 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; +my $version = q{ $Revision: 1.3 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; my @grabber = ("screencapture", "-x"); my @converter = ("pdf2jpeg"); @@ -101,22 +101,45 @@ sub grab_image { } } - # Convert the PDF to a JPEG + # On MacOS 10.3, "screencapture -x" always wrote a PDF. + # On 10.4.2, it writes a PNG by default, and the output format can be + # changed with the new "-t" argument. + # + # So, for maximal compatibility, we run it without "-t", but look at + # the first few bytes to see if it's a PDF, and if it is, convert it + # to a JPEG first. Otherwise, we assume that whatever screencapture + # wrote is a file format that xscreensaver-getimage-file can already + # cope with (though it will have the extension ".pdf", regardless of + # what is actually in the file). + # + my $pdf_p = 0; { - my $jpgfile = $tmpfile; - $jpgfile =~ s/\.[^.]+$//; - $jpgfile .= ".jpg"; - - @cmd = (@converter, $tmpfile, $jpgfile); - push @cmd, "--verbose" if ($verbose); - - print STDERR "$progname: executing \"" . join(' ', @cmd) . "\"\n" - if ($verbose); - system (@cmd); - unlink $tmpfile; - $tmpfile = $jpgfile; + local *IN; + open (IN, "<$tmpfile") || error ("$tmpfile: $!"); + my $buf = ''; + read (IN, $buf, 10); + close IN; + $pdf_p = ($buf =~ m/^%PDF-/s); } + # If it's a PDF, convert it to a JPEG. + # + if ($pdf_p) + { + my $jpgfile = $tmpfile; + $jpgfile =~ s/\.[^.]+$//; + $jpgfile .= ".jpg"; + + @cmd = (@converter, $tmpfile, $jpgfile); + push @cmd, "--verbose" if ($verbose); + + print STDERR "$progname: executing \"" . join(' ', @cmd) . "\"\n" + if ($verbose); + system (@cmd); + unlink $tmpfile; + $tmpfile = $jpgfile; + } + @st = stat($tmpfile); $size = (@st ? $st[7] : 0); if ($size <= 2048) {