Difference between revisions of "Tutorial: PhpRunner 9.8 and Photo Display"

From dftwiki3
Jump to: navigation, search
Line 106: Line 106:
  
 
</source>
 
</source>
 +
==How to compute dpi, width, height and store in MySQL DB==
 +
<br />
 +
::<source lang="php">
  
 +
function AfterAdd( $values, $keys, $inline, $pageObject ) {
  
 +
$fileInfozzz = $values["fileName"];
 +
$dicozzz = explode( ",", $fileInfozzz );
 +
$fileNamezzz = str_replace( "[{", "", $dicozzz[0] );
 +
$fileNamezzz = str_replace( "\"", "", explode( ":", $fileNamezzz )[1] );
 +
$fileNamezzz = str_replace( "\\", "", $fileNamezzz );
 +
$filePathzzz = $_SERVER["DOCUMENT_ROOT"]. "/photos/" . $fileNamezzz;
 +
$paramszzz = getimagesize( $filePathzzz );
 +
$widthzzz = (int) $paramszzz[0];
 +
$heightzzz = (int) $paramszzz[1];
 +
/*
 +
file_put_contents('php://stderr', print_r( "\nwidth = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $widthzzz, TRUE ));
 +
file_put_contents('php://stderr', print_r( "\nheight = ", TRUE ));
 +
file_put_contents('php://stderr', print_r( $heightzzz, TRUE ));
 +
*/
 +
 +
// get DPI info
 +
$dpi = 72;
 +
$cmd = 'identify -quiet -format "%x" '.$filename;     
 +
@exec( escapeshellcmd($cmd), $data );
 +
if($data && is_array($data)){
 +
  $data = explode(' ', $data[0]);
 +
  if($data[1] == 'PixelsPerInch'){
 +
      $dpi = $data[0];
 +
  } elseif($data[1] == 'PixelsPerCentimeter'){
 +
      $dpi = ceil($data[0] * 2.54);
 +
  }elseif($data[1] == 'Undefined'){
 +
      $dpi = $data[0];
 +
  }                     
 +
}
 +
$dpi = (int) $dpi;
 +
 +
//file_put_contents('php://stderr', print_r( "\n\n\ndpi=", TRUE ) );
 +
//file_put_contents('php://stderr', print_r( $dpi, TRUE ));
 +
//file_put_contents('php://stderr', print_r( "\n", TRUE ) );
 +
 +
$widthIn = $widthzzz / $dpi;
 +
$heightIn = $heightzzz / $dpi;
 +
 +
 +
// pass width and height to javascript
 +
//$pageObject->setProxyValue("widthzzz", $widthzzz);
 +
//$pageObject->setProxyValue("heightzzz",$heightzzz);
 +
 +
// --- get last record added to reproduced table
 +
$sql = "SELECT Id FROM reproduced ORDER BY Id DESC LIMIT 1";
 +
$res = CustomQuery($sql);
 +
$data = db_fetch_array($res);
 +
$Id = $data["Id"];
 +
 +
//--- display Id of last record
 +
//file_put_contents('php://stderr', print_r( $data["Id"], TRUE ));
 +
//file_put_contents('php://stderr', "\n" );
 +
 +
//--- update width and height of record just added ---
 +
$sql = "Update reproduced set dpi='$dpi', widthP='$widthzzz'," .
 +
      " widthIn='$widthIn', heightIn='$heightIn',".
 +
      " heightP='$heightzzz' where Id=".$Id;
 +
CustomQuery($sql);
 +
 +
} //function AfterAdd
 +
 +
</source>
 
</onlydft>
 
</onlydft>
 
<br />
 
<br />

Revision as of 14:58, 29 May 2018

D. Thiebaut (talk) 10:38, 25 May 2018 (EDT)



...