Skip to content

Instantly share code, notes, and snippets.

@fuba
Last active August 29, 2015 14:19
Show Gist options
  • Save fuba/3ea1171d53709708fc8a to your computer and use it in GitHub Desktop.
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
#!/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;
<?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>
#!/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