X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=driver%2Fxscreensaver-getimage-desktop;h=627cd254b2273f46c5b69dcd2ff09f91917e20ef;hp=f7d9e7650aa371aaf5bd049dfa95f330099246ac;hb=6b1c86cf395f59389e4ece4ea8f4bea2c332745b;hpb=96a411663168b0ba5432b407a83be55f3df0c802 diff --git a/driver/xscreensaver-getimage-desktop b/driver/xscreensaver-getimage-desktop index f7d9e765..627cd254 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 @@ -30,11 +30,11 @@ # Created: 20-Oct-2003. require 5; -use diagnostics; +#use diagnostics; # Fails on some MacOS 10.5 systems use strict; my $progname = $0; $progname =~ s@.*/@@g; -my $version = q{ $Revision: 1.1 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; +my $version = q{ $Revision: 1.4 $ }; $version =~ s/^[^0-9]+([0-9.]+).*$/$1/; my @grabber = ("screencapture", "-x"); my @converter = ("pdf2jpeg"); @@ -81,7 +81,7 @@ sub grab_image { my $tmpdir = $ENV{TMPDIR}; $tmpdir = "/tmp" unless $tmpdir; - my $tmpfile = "$tmpdir/xssgrab.$$.pdf"; + my $tmpfile = sprintf ("%s/xssgrab.%08x.pdf", $tmpdir, rand(0xffffffff)); my @cmd = (@grabber, $tmpfile); unlink $tmpfile; @@ -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) {