Nikon Lenses

Last Updated or created 2022-04-10

Created a graph for my Nikon lenses. It shows me what lens i can use at what Aperture / Range.

( https://media.henriaanstoot.nl/websites/lenses/ )

It uses canvas to draw lines and text, but thats only interesting for static stuff. ( https://www.w3schools.com/graphics/canvas_drawing.asp )
My example uses a php script to load information from a csv file. And loops though those entries and draw lens info.

Piece of canvas script to draw 17-70mm lens info.

ctx.fillStyle = 'rgba(0, 200, 100, 0.9)';
ctx.lineWidth=2;
ctx.beginPath();
ctx.moveTo(189.98560128675,163.25813588993);
ctx.lineTo(359.81942904592,202.49237972319);
ctx.lineTo(359.81942904592,250);
ctx.lineTo(189.98560128675,250);
ctx.strokeStyle="rgba(0,0,0,0.9)";
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = 'rgba(0,0,0,0.9';
ctx.save();
ctx.translate( 189.98560128675,153.25813588993);
ctx.rotate(-Math.PI / 4);
ctx.fillText("17-70mm", 0,0);
ctx.restore();

CSV lenses info

80;200;2.8;2.8;FX;80-200mm f/2.8
10;24;3.5;4.5;DX;10-24mm wide
28;100;3.5;5.6;;28-100mm leen
17;70;2.8;4;DX;17-70mm
35;35;1.8;1.8;DX;35mm f/1.8
60;60;2.8;2.8;FX;60mm f/2.8
28;300;3.5;5.6;FX;28-300mm

PHP Code to generate


<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Lens</title>
  <style type='text/css'>
    body{ background-color: ivory; }
#canvas{border:1px solid white;}

  </style>
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");
<?PHP
$log=yes;

print "ctx.strokeStyle = 'rgba(200, 0, 0, 0.1)';";
print "ctx.fillStyle = 'rgba(0, 0, 0, 0.9)';";
$apes=array(1.4,2,2.8,4,5.6);
$count=0;
foreach ($apes as &$value) {
$height=log($value)*110;
$count=$count+1;
$height=$height+50;
print "ctx.font = '20px Arial';";
print "ctx.fillText(\"$value\", 20, $height);";
print "ctx.lineWidth=2;";
print "ctx.moveTo(50, $height);";
print "ctx.lineTo(900, $height);";
}
print "ctx.stroke();";
$count=0;
$apes=array(8,16,32,64,128);
foreach ($apes as &$value) {
$width=log($value)*120;
$count=$count+1;
$width=$width-150;
print "ctx.fillText(\"$value\", $width, 270);";
}
print "ctx.font = '15px Arial';";
?>
ctx.beginPath();
ctx.moveTo(50,250);
ctx.lineTo(900,250);
ctx.moveTo(50,50);
ctx.lineTo(50,250);
ctx.lineWidth=1;
ctx.strokeStyle="rgba(0, 0, 0, 0.9)";
ctx.stroke();
<?PHP

$configfile="lenses.csv";

$config=get2DArrayFromCsv($configfile,";");

        foreach ($config as $value) {
$fp1=$value[0];
$fp2=$value[1];
$ap1=$value[2];
$ap2=$value[3];
$x1=(log($fp1)*120)-150;
$x2=(log($fp2)*120)-150;
$y1=(log($ap1)*110)+50;
$y2=(log($ap2)*110)+50;
if ( $x1 == $x2 ) { $color="200,0,0"; } else { $color="0,0,0"; }
if ( $x1 == $x2 ) { $x2 = $x2 + 6; }
$green=200;
$xx1=(log($fp1*2)*120)-150;
$xxx1=(log($fp1*2)*120)-160;
$xx2=(log($fp2*2)*120)-150;
$yy1=$y1-10;
$yyy1=$y1+10;

if ( $xx1 == $xx2 ) { $xx2 = $xx2 + 6; }
if ( $value[4] == "FX" ) { $col="200"; $trans=0.2; } else { $col="0";$trans=0.9;  }
?>

ctx.fillStyle = 'rgba(<?PHP print $col; ?>, <?PHP print $green; ?>, 100, <?PHP print $trans; ?>)';
ctx.lineWidth=2;
ctx.beginPath();
ctx.moveTo(<?PHP print "$x1"; ?>,<?PHP print "$y1"; ?>);
ctx.lineTo(<?PHP print "$x2"; ?>,<?PHP print "$y2"; ?>);
ctx.lineTo(<?PHP print "$x2"; ?>,<?PHP print "250"; ?>);
ctx.lineTo(<?PHP print "$x1"; ?>,<?PHP print "250"; ?>);
ctx.strokeStyle="rgba(<?PHP print "$color"; ?>,<?PHP print $trans;  ?>)";
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = 'rgba(<?PHP print "$color"; ?>,<?PHP print $trans;  ?>';
ctx.save();
ctx.translate( <?PHP print "$x1"; ?>,<?PHP print "$yy1"; ?>);
ctx.rotate(-Math.PI / 4);
ctx.fillText("<?PHP print "$value[5]"; ?>", 0,0);
ctx.restore();
<?PHP

if ( $value[4] == "FX" ) {
?>
ctx.fillStyle = 'rgba(0, <?PHP print "200"; ?>, 0, 0.9)';
ctx.beginPath();
ctx.moveTo(<?PHP print "$xx1"; ?>,<?PHP print "$y1"; ?>);
ctx.lineTo(<?PHP print "$xx2"; ?>,<?PHP print "$y2"; ?>);
ctx.lineTo(<?PHP print "$xx2"; ?>,<?PHP print "250"; ?>);
ctx.lineTo(<?PHP print "$xx1"; ?>,<?PHP print "250"; ?>);
ctx.strokeStyle="rgba(<?PHP print "$color"; ?>,0.9";
ctx.closePath();
ctx.fill();
ctx.stroke();
ctx.fillStyle = 'rgba(0, 0, 0, 0.9)';
ctx.save();
ctx.translate( <?PHP print "$xx1"; ?>,<?PHP print "$yy1"; ?>);
ctx.rotate(-Math.PI / 4);
ctx.fillText("<?PHP print "$value[5]"; ?> crop", <?PHP print "0"; ?>, <?PHP print "0"; ?>);
ctx.restore();
<?PHP
}
}
?>

ctx.fillStyle = 'rgba(0, 0, 0, 0.5)';
ctx.font = 'bold 10pt Calibri';

}//]]>

</script>

</head>
<body><small>
  <canvas id="canvas" width=700 height=300></canvas>
<P>
<?PHP
$configfile="lenses.csv";

   function get2DArrayFromCsv($file,$delimiter) {
       if (($handle = fopen($file, "r")) !== FALSE) {
           $i = 0;
           while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== FALSE) {
               for ($j=0; $j<count($lineArray); $j++) {
                   $data2DArray[$i][$j] = $lineArray[$j];
               }
               $i++;
           }
           fclose($handle);
       }
       return $data2DArray;
   }

$config=get2DArrayFromCsv($configfile,";");

        foreach ($config as $value) {
            print "<B>Lens = $value[5] </B><BR>";
            print "Focal min = $value[0] <BR>";
            print "Focal max = $value[1] <BR>";
            print "Arp min = $value[2] <BR>";
            print "Arp max = $value[3] <BR>";
            print "Crop (FX/DX) = $value[4] <P>";
        }


?>

</body>

</html>