Last active
August 29, 2015 14:19
-
-
Save fuba/3ea1171d53709708fc8a to your computer and use it in GitHub Desktop.
Fix aspect ratio of vlc 2.2.1 snapshots on Mac OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my @props = qw/dpiHeight dpiWidth pixelWidth pixelHeight/; | |
my $file = shift; | |
chomp $file; | |
exit if $file !~ /\.tiff$/; | |
my $outfile = $file; | |
$outfile =~ s/\-tiff//; | |
$outfile =~ s/\.tiff$/.png/; | |
exit if -e $outfile; | |
my $command = join " ", ( | |
'sips', | |
( map { '--getProperty '.$_ } @props ), | |
"'$file'" | |
); | |
my $r = `$command` or die $!; | |
my %d; | |
for my $prop (@props) { | |
($d{$prop}) = ( $r =~ /$prop\:\s+([\d\.]+)/m ); | |
die "$prop not found" unless defined $d{$prop}; | |
} | |
exit if ($d{dpiHeight} == $d{dpiWidth}); | |
my %nd = %d; | |
$nd{format} = 'png'; | |
if ($d{dpiHeight} > $d{dpiWidth}) { | |
$nd{dpiWidth} = $d{dpiHeight}; | |
my $frac = $d{dpiHeight} / $d{dpiWidth}; | |
$nd{pixelWidth} = int( $frac * $d{pixelWidth} ); | |
} | |
my $writecommand = join " ", ( | |
'sips', | |
( map { ( '--setProperty', $_, "'$nd{$_}'" ) } qw/format dpiHeight dpiWidth/ ), | |
"-z", $nd{pixelHeight}, $nd{pixelWidth}, | |
"'$file'", | |
'--out', | |
"'$outfile'" | |
); | |
`$writecommand`; | |
unlink $file; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>me.fuba.snapshot.watcher</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/path/to/watch_snapshot_dir.sh</string> | |
</array> | |
<key>RunAtLoad</key> | |
<true/> | |
<key>KeepAlive</key> | |
<true/> | |
<key>StandardOutPath</key> | |
<string>/var/log/watch_snapshot.out</string> | |
<key>StandardErrorPath</key> | |
<string>/var/log/watch_snapshot.err</string> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
/usr/local/bin/fswatch -0 ~/Dropbox/アプリ/capture/ | xargs -0 -n 1 fix_vlc_dpi.pl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment