#!/usr/bin/perl # Make an HTML azimuth scale bar # Copyright : https://www.gnu.org/licenses/gpl.html # Author : https://www.jidanni.org/ # Created On : Sun Sep 29 23:02:14 2019 # Last Modified By: Dan Jacobson # Last Modified On: Thu Mar 12 06:14:51 2020 # Update Count : 337 use strict; use warnings FATAL => q(all); my $match = pop or die "Give regexp to match photo name"; die "Only one argument allowed." if @ARGV; my %h; for ( { # From 24.153105,120.687882 apparent roof location, back calculated from row of solar panels. # So now compute from rooftop to rooftop, not ground to ground. Total => { Name => 'gdi/20200118_X0.jpg', columns => 200, indent => 0, width => 1603, height => 376 }, left => { Name => '中華電信力行服務中心', azimuth => 269.29 - 180, #746m, not using Google 3D pic. pixel => 363 }, right => { Name => '進化精武路口西南角興建中之大樓', azimuth => 314.81 - 180, #crane base, 882m pixel => 1419 } }, { Total => { Name => 'gdi/20200118_X1.jpg', columns => 143, indent => 0, width => 1145, height => 337 }, left => { Name => '進化精武路口西南角興建中之大樓', azimuth => 314.81 - 180, #crane base, 882m pixel => 59 }, right => { Name => 'Baseball field north and south lights', azimuth => 350.82 - 180, pixel => 1043 } }, { Total => { # ----------- NOT from same spot as last Name => 'gdi/20200118_X2.jpg', columns => 170, indent => 0, width => 1366, height => 399 }, left => { Name => 'Gold covered pool', azimuth => 179, pixel => 204 }, right => { Name => 'zunxian + yucai S building', azimuth => 208, pixel => 1119 } }, { Total => { Name => 'gdi/20200118_X3.jpg', columns => 110, indent => 0, width => 888, height => 342 }, left => { Name => '中華電信三民林森路口針塔', azimuth => 218, pixel => 165 }, right => { Name => '中友百貨左緣', azimuth => 239, pixel => 860 } }, { Total => { # ----------- NOT from same spot as last. Use 24.153015,120.687711 roof to roof Name => 'gdi/20200118_X4.jpg', columns => 227, indent => 0, width => 1823, height => 439 }, left => { Name => '中友百貨左緣', azimuth => 63 + 180, # 3D off pixel => 78 }, right => { Name => '立夫醫療大樓 育德路', azimuth => 124 + 180, # 3D off pixel => 1791 # crease } }, { Total => { Name => 'gdi/20200118_X5.jpg', columns => 237, indent => 0, width => 1898, height => 480 }, left => { Name => '立夫醫療大樓 育德路', azimuth => 124 + 180, # 3D off pixel => 54 # crease }, right => { Name => '世基金融中心 進化北路 238 號', azimuth => 343.89, pixel => 1199 } }, { Total => { Name => '20191128_tztrain_yuanzui.jpg', columns => 147, indent => 0, width => 1178, height => 582 }, left => { Name => 'Xiaoxue Shan', azimuth => 63.7, pixel => 185 }, right => { Name => '稍來山南端 Shaolai Mtn. south edge', azimuth => 70.1, pixel => 695 } }, { Total => { Name => '20190626_0820_845nw.jpg', columns => 211, indent => 0, width => 1693, height => 486 }, left => { Name => 'Red house at saddle', azimuth => 134 + 180, pixel => 382 }, right => { Name => 'Edge of far stuff', azimuth => 336, pixel => 1668 } }, { Total => { Name => '20191006_064107_south_east.jpg', columns => 209, indent => 0, width => 1677, height => 362 }, left => { Name => 'Baimao south edge', azimuth => 132.15, pixel => 244 }, right => { Name => 'Zhimao Shan Nanfeng', azimuth => 168.4, pixel => 1117 } }, { Total => { Name => '20191006_064044_east.jpg', columns => 168, indent => 0, width => 1354, height => 218 }, left => { Name => 'Baigu Dashan Xifeng', azimuth => 87.54, pixel => 80 }, right => { Name => 'Baimao south edge', azimuth => 132.15, pixel => 1332 } }, { Total => { Name => '20191006_064058_northeast.jpg', columns => 188, indent => 0, width => 1509, height => 197 }, left => { Name => 'M001', azimuth => 43.71, pixel => 118 }, right => { Name => 'Baigu Dashan Xifeng', azimuth => 87.54, pixel => 1339 } }, { Total => { Name => '20191217_845m_east.jpg', columns => 178, indent => 0, width => 1430, height => 249 }, left => { Name => 'Baigu/gou Shan', azimuth => 85.1, pixel => 502 }, right => { Name => 'Jilong Shan', azimuth => 94.1, pixel => 1163 } }, { Total => { Name => '20190609_060051mtn3.jpg', columns => 129, indent => 4, width => 1008, height => 164 }, left => { Name => '大尖山', azimuth => 159.81, pixel => 329 }, right => { Name => '治茆山南峰', azimuth => 167.34, pixel => 864 } }, { Total => { Name => '20010324tianleng.jpg', columns => 74, indent => 0, width => 595, height => 438 }, left => { Name => 'left', azimuth => 155, pixel => 0 }, right => { Name => 'right', azimuth => 205, pixel => 595 } } ) { next unless %$_{Total}->{Name} =~ /$match/; die "More than one match" if %h; %h = %$_; } die "No matches." unless %h; %h = ( Name => shift, # JPG name. Just a comment actually. width => shift, left => { Name => shift, #Just a comment actually azimuth => shift, pixel => shift, }, right => { Name => shift, #Just a comment actually azimuth => shift, pixel => shift, }, ##0 at first. Then change by reading what calculator_bar helps show: columns => shift, indent => shift, #0, or 4 if in
\n}; exit; } die if $h{right}{pixel} <= $h{left}{pixel}; for ( $h{right}{azimuth} ) { if ( $h{left}{azimuth} > $_ ) { $_ += 360; } } my $PixelsPerDegree = ( $h{right}{pixel} - $h{left}{pixel} ) / ( $h{right}{azimuth} - $h{left}{azimuth} ); my @azimuth = $h{left}{azimuth} - $h{left}{pixel} / $PixelsPerDegree; push @azimuth, $azimuth[0] + $h{Total}{width} / $PixelsPerDegree; $h{Total}{columns} -= $h{Total}{indent}; my @r; for ( 0 .. $h{Total}{columns} ) { push @r, ( $azimuth[0] + ( $azimuth[1] - $azimuth[0] ) * $_ / $h{Total}{columns} ) % 360; } printf qq{}, @{ $h{Total} }{qw/Name width height/}; calculator_bar( $h{Total}{indent} .. $ENV{cols} || 211 ); print qq{
\n}; printf q{\n}; sub calculator_bar { print " "; my $l; for (@_) { next unless $_; next if $_ % 10; $l .= sprintf "%10d", $_; } print substr( $l, $_[0] ), "\n"; for (@_) { my $k = $_ % 10; print $k ? $k : " "; } print "\n"; } sub azimuth_bar { my $last = $_[0]; my $pad = length( $_[0] ) - 1; for (@_) { if ( $_ == $last ) { $pad++; next; } if ( length($last) != length ) { $pad++; } $last = $_; # if ( $_ % ( 2 + length ) ) { $pad++; next; } if ( $_ % 10 ) { $pad++; next; } print "-" for 0 .. $pad - length; print $_ ; $pad = 0; } print "-" for 0 .. $pad - length $r[-1]; print "\n"; for (@_) { print $_ % 10; } print "\n"; } ## Gosh, we don't even need to use pixels (and thus gimp)... just columns. One day do that. ## But maybe not as precise... ## Local Variables: ## compile-command: "cols=244 ./azimuthbar REGEXP" ## End:}, @{ $h{Total} }{qw/Name width height/}, ( @r[ 0, -1 ] ) x 4; azimuth_bar(@r); print qq{