Merge branch 'update_image_view' into storageareas
commit
e4566f2e8e
|
@ -70,7 +70,7 @@ class Frame {
|
|||
}
|
||||
|
||||
public function getImageSrc( ) {
|
||||
return ZM_BASE_URL.'/index.php?view=image&fid='.$this->{'Id'};
|
||||
return $_SERVER['PHP_SELF'].'?view=image&fid='.$this->{'Id'};
|
||||
} // end function getImageSrc
|
||||
|
||||
public static function find( $parameters = array(), $limit = NULL ) {
|
||||
|
|
|
@ -25,6 +25,8 @@ if ( !canView( 'Events' ) )
|
|||
}
|
||||
require_once('includes/Frame.php');
|
||||
|
||||
require_once('includes/Frame.php');
|
||||
|
||||
$eid = validInt($_REQUEST['eid']);
|
||||
if ( !empty($_REQUEST['fid']) )
|
||||
$fid = validInt($_REQUEST['fid']);
|
||||
|
@ -98,7 +100,7 @@ if ( $imageData['hasAnalImage'] ) { ?><a href="?view=frame&eid=<?php echo $e
|
|||
</p>
|
||||
<?php if (file_exists ($dImagePath)) { ?>
|
||||
<p id="diagImagePath"><?php echo $dImagePath ?></p>
|
||||
<p id="diagImage"><img src=?"<?php echo viewImagePath( $dImagePath ) ?>" width="<?php echo reScale( $event['Width'], $event['DefaultScale'], $scale ) ?>" height="<?php echo reScale( $event['Height'], $event['DefaultScale'], $scale ) ?>" class="<?php echo $imageData['imageClass'] ?>"/></p>
|
||||
<p id="diagImage"><img src="<?php echo viewImagePath( $dImagePath ) ?>" width="<?php echo reScale( $event['Width'], $event['DefaultScale'], $scale ) ?>" height="<?php echo reScale( $event['Height'], $event['DefaultScale'], $scale ) ?>" class="<?php echo $imageData['imageClass'] ?>"/></p>
|
||||
<?php } if (file_exists ($rImagePath)) { ?>
|
||||
<p id="refImagePath"><?php echo $rImagePath ?></p>
|
||||
<p id="refImage"><img src="<?php echo viewImagePath( $rImagePath ) ?>" width="<?php echo reScale( $event['Width'], $event['DefaultScale'], $scale ) ?>" height="<?php echo reScale( $event['Height'], $event['DefaultScale'], $scale ) ?>" class="<?php echo $imageData['imageClass'] ?>"/></p>
|
||||
|
|
|
@ -32,169 +32,159 @@
|
|||
// If both scale and either width or height are specified, scale is ignored
|
||||
//
|
||||
|
||||
if ( !canView( 'Events' ) )
|
||||
{
|
||||
$view = "error";
|
||||
if ( !canView( 'Events' ) ) {
|
||||
$view = 'error';
|
||||
return;
|
||||
}
|
||||
|
||||
require_once('includes/Storage.php');
|
||||
require_once('includes/Event.php');
|
||||
require_once('includes/Frame.php');
|
||||
|
||||
header( 'Content-type: image/jpeg' );
|
||||
|
||||
// Compatibility for PHP 5.4
|
||||
if (!function_exists('imagescale'))
|
||||
{
|
||||
function imagescale($image, $new_width, $new_height = -1, $mode = 0)
|
||||
{
|
||||
$mode; // Not supported
|
||||
if (!function_exists('imagescale')) {
|
||||
function imagescale($image, $new_width, $new_height = -1, $mode = 0) {
|
||||
$mode; // Not supported
|
||||
|
||||
$new_height = ($new_height == -1) ? imagesy($image) : $new_height;
|
||||
$imageNew = imagecreatetruecolor($new_width, $new_height);
|
||||
imagecopyresampled($imageNew, $image, 0, 0, 0, 0, (int)$new_width, (int)$new_height, imagesx($image), imagesy($image));
|
||||
$new_height = ($new_height == -1) ? imagesy($image) : $new_height;
|
||||
$imageNew = imagecreatetruecolor($new_width, $new_height);
|
||||
imagecopyresampled($imageNew, $image, 0, 0, 0, 0, (int)$new_width, (int)$new_height, imagesx($image), imagesy($image));
|
||||
|
||||
return $imageNew;
|
||||
}
|
||||
return $imageNew;
|
||||
}
|
||||
}
|
||||
|
||||
$Storage = NULL;
|
||||
$errorText = false;
|
||||
if ( empty($_REQUEST['path']) )
|
||||
{
|
||||
if ( ! empty($_REQUEST['fid']) ) {
|
||||
if ( ! empty($_REQUEST['eid'] ) ) {
|
||||
$Event = new Event( $_REQUEST['eid'] );
|
||||
$Frame = Frame::find_one( array( 'EventId' => $_REQUEST['eid'], 'FrameId' => $_REQUEST['fid'] ) );
|
||||
if ( ! $Frame ) {
|
||||
Fatal("No Frame found for event(".$_REQUEST['eid'].") and frame id(".$_REQUEST['fid'].")");
|
||||
}
|
||||
$Storage = $Event->Storage();
|
||||
$path = $Event->Path().'/'.sprintf("%'.0".ZM_EVENT_IMAGE_DIGITS.'d',$_REQUEST['fid']).'-capture.jpg';
|
||||
} else {
|
||||
if ( empty($_REQUEST['path']) ) {
|
||||
if ( ! empty($_REQUEST['fid']) ) {
|
||||
if ( ! empty($_REQUEST['eid'] ) ) {
|
||||
$Event = new Event( $_REQUEST['eid'] );
|
||||
$Frame = Frame::find_one( array( 'EventId' => $_REQUEST['eid'], 'FrameId' => $_REQUEST['fid'] ) );
|
||||
if ( ! $Frame ) {
|
||||
Fatal("No Frame found for event(".$_REQUEST['eid'].") and frame id(".$_REQUEST['fid'].")");
|
||||
}
|
||||
$path = $Event->Path().'/'.sprintf("%'.0".ZM_EVENT_IMAGE_DIGITS.'d',$_REQUEST['fid']).'-capture.jpg';
|
||||
} else {
|
||||
# If we are only specifying fid, then the fid must be the primary key into the frames table. But when the event is specified, then it is the frame #
|
||||
$Frame = new Frame( $_REQUEST['fid'] );
|
||||
$Event = new Event( $Frame->EventId() );
|
||||
$Storage = $Event->Storage();
|
||||
$path = $Event->Path().'/'.sprintf("%'.0".ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-capture.jpg';
|
||||
}
|
||||
} else {
|
||||
$errorText = "No image path";
|
||||
}
|
||||
$Frame = new Frame( $_REQUEST['fid'] );
|
||||
$Event = new Event( $Frame->EventId() );
|
||||
$path = $Event->Path().'/'.sprintf("%'.0".ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-capture.jpg';
|
||||
}
|
||||
} else {
|
||||
$errorText = "No image path";
|
||||
}
|
||||
|
||||
if ( ! file_exists( $path ) ) {
|
||||
# Generate the frame JPG
|
||||
if ( $Event->DefaultVideo() ) {
|
||||
$command ='ffmpeg -i '.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path;
|
||||
#$command ='ffmpeg -v 0 -i '.$Storage->Path().'/'.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path;
|
||||
Debug( "Running $command" );
|
||||
$output = array();
|
||||
$retval = 0;
|
||||
exec( $command, $output, $retval );
|
||||
Debug("Retval: $retval, output: " . implode("\n", $output));
|
||||
} else {
|
||||
Fatal("Can't create frame images from video becuase there is no video file for this event (".$Event->DefaultVideo() );
|
||||
}
|
||||
if ( $Event->DefaultVideo() ) {
|
||||
$command ='ffmpeg -i '.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path;
|
||||
#$command ='ffmpeg -v 0 -i '.$Storage->Path().'/'.$Event->Path().'/'.$Event->DefaultVideo().' -vf "select=gte(n\\,'.$Frame->FrameId().'),setpts=PTS-STARTPTS" '.$path;
|
||||
Debug( "Running $command" );
|
||||
$output = array();
|
||||
$retval = 0;
|
||||
exec( $command, $output, $retval );
|
||||
Debug("Retval: $retval, output: " . implode("\n", $output));
|
||||
} else {
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
Fatal("Can't create frame images from video becuase there is no video file for this event (".$Event->DefaultVideo() );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
$Storage = new Storage();
|
||||
$path = $_REQUEST['path'];
|
||||
if ( !empty($user['MonitorIds']) )
|
||||
{
|
||||
$imageOk = false;
|
||||
$pathMonId = substr( $path, 0, strspn( $path, "1234567890" ) );
|
||||
foreach ( preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) as $monId )
|
||||
{
|
||||
if ( $pathMonId == $monId )
|
||||
{
|
||||
$imageOk = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !$imageOk )
|
||||
$errorText = "No image permissions";
|
||||
}
|
||||
} else {
|
||||
$path = $_REQUEST['path'];
|
||||
if ( !empty($user['MonitorIds']) ) {
|
||||
$imageOk = false;
|
||||
$pathMonId = substr( $path, 0, strspn( $path, "1234567890" ) );
|
||||
foreach ( preg_split( '/["\'\s]*,["\'\s]*/', $user['MonitorIds'] ) as $monId ) {
|
||||
if ( $pathMonId == $monId ) {
|
||||
$imageOk = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !$imageOk )
|
||||
$errorText = "No image permissions";
|
||||
}
|
||||
if ( ! file_exists( $path ) ) {
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
Fatal("Image not found at $path");
|
||||
}
|
||||
}
|
||||
|
||||
$scale=0;
|
||||
if( !empty($_REQUEST['scale']) )
|
||||
if (is_numeric($_REQUEST['scale']))
|
||||
{
|
||||
$x = $_REQUEST['scale'];
|
||||
if($x >= 1 and $x <= 400)
|
||||
$scale=$x;
|
||||
if( !empty($_REQUEST['scale']) ) {
|
||||
if (is_numeric($_REQUEST['scale'])) {
|
||||
$x = $_REQUEST['scale'];
|
||||
if($x >= 1 and $x <= 400)
|
||||
$scale=$x;
|
||||
}
|
||||
}
|
||||
|
||||
$width=0;
|
||||
if( !empty($_REQUEST['width']) )
|
||||
if (is_numeric($_REQUEST['width']))
|
||||
{
|
||||
$x = $_REQUEST['width'];
|
||||
if($x >= 10 and $x <= 8000)
|
||||
$width=$x;
|
||||
if ( !empty($_REQUEST['width']) ) {
|
||||
if (is_numeric($_REQUEST['width'])) {
|
||||
$x = $_REQUEST['width'];
|
||||
if($x >= 10 and $x <= 8000)
|
||||
$width=$x;
|
||||
}
|
||||
}
|
||||
$height=0;
|
||||
if( !empty($_REQUEST['height']) )
|
||||
if (is_numeric($_REQUEST['height']))
|
||||
{
|
||||
$x = $_REQUEST['height'];
|
||||
if($x >= 10 and $x <= 8000)
|
||||
$height=$x;
|
||||
if( !empty($_REQUEST['height']) ) {
|
||||
if (is_numeric($_REQUEST['height'])) {
|
||||
$x = $_REQUEST['height'];
|
||||
if($x >= 10 and $x <= 8000)
|
||||
$height=$x;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( $errorText ) {
|
||||
Error( $errorText );
|
||||
Error( $errorText );
|
||||
} else {
|
||||
if ( ( $scale==0 || $scale==100 ) && $width==0 && $height==0 ) {
|
||||
if ( ! readfile( $path ) ) {
|
||||
Error("No bytes read from ". $path );
|
||||
}
|
||||
if ( ( $scale==0 || $scale==100 ) && $width==0 && $height==0 ) {
|
||||
if ( ! readfile( $path ) ) {
|
||||
Error("No bytes read from ". $path );
|
||||
}
|
||||
} else {
|
||||
Debug("Doing a scaled image: scale($scale) width($width) height($height)");
|
||||
$i = 0;
|
||||
if ( ! ( $width && $height ) ) {
|
||||
$i = imagecreatefromjpeg( $path );
|
||||
$oldWidth = imagesx( $i );
|
||||
$oldHeight = imagesy( $i );
|
||||
if ( $width == 0 && $height == 0 ) { // scale has to be set to get here with both zero
|
||||
$width = $oldWidth * $scale / 100.0;
|
||||
$height= $oldHeight * $scale / 100.0;
|
||||
} elseif ( $width == 0 && $height != 0 ) {
|
||||
$width = ($height * $oldWidth) / $oldHeight;
|
||||
} elseif ( $width != 0 && $height == 0 ) {
|
||||
$height = ($width * $oldHeight) / $oldWidth;
|
||||
}
|
||||
if ( $width == $oldWidth && $height == $oldHeight) {
|
||||
Warning( "No change to width despite scaling." );
|
||||
}
|
||||
}
|
||||
|
||||
# Slight optimisation, thumbnails always specify width and height, so we can cache them.
|
||||
$scaled_path = preg_replace('/\.jpg$/', "-${width}x${height}.jpg", $path );
|
||||
if ( file_exists( $scaled_path ) ) {
|
||||
Debug( "Using cached scaled image at $scaled_path.");
|
||||
if ( ! readfile( $scaled_path ) ) {
|
||||
Error("No bytes read from scaled image". $scaled_path );
|
||||
}
|
||||
} else {
|
||||
Debug( "Cached scaled image does not exist at $scaled_path. Creating it");
|
||||
ob_start();
|
||||
if ( ! $i )
|
||||
$i = imagecreatefromjpeg( $path );
|
||||
$iScale = imagescale( $i, $width, $height );
|
||||
imagejpeg( $iScale );
|
||||
imagedestroy( $i );
|
||||
imagedestroy( $iScale );
|
||||
$scaled_jpeg_data = ob_get_contents();
|
||||
file_put_contents( $scaled_path, $scaled_jpeg_data );
|
||||
ob_end_clean();
|
||||
echo $scaled_jpeg_data;
|
||||
}
|
||||
}
|
||||
Debug("Doing a scaled image: scale($scale) width($width) height($height)");
|
||||
$i = 0;
|
||||
if ( ! ( $width && $height ) ) {
|
||||
$i = imagecreatefromjpeg( $path );
|
||||
$oldWidth = imagesx( $i );
|
||||
$oldHeight = imagesy( $i );
|
||||
if ( $width == 0 && $height == 0 ) { // scale has to be set to get here with both zero
|
||||
$width = $oldWidth * $scale / 100.0;
|
||||
$height= $oldHeight * $scale / 100.0;
|
||||
} elseif ( $width == 0 && $height != 0 ) {
|
||||
$width = ($height * $oldWidth) / $oldHeight;
|
||||
} elseif ( $width != 0 && $height == 0 ) {
|
||||
$height = ($width * $oldHeight) / $oldWidth;
|
||||
}
|
||||
if ( $width == $oldWidth && $height == $oldHeight) {
|
||||
Warning( "No change to width despite scaling." );
|
||||
}
|
||||
}
|
||||
|
||||
# Slight optimisation, thumbnails always specify width and height, so we can cache them.
|
||||
$scaled_path = preg_replace('/\.jpg$/', "-${width}x${height}.jpg", $path );
|
||||
if ( file_exists( $scaled_path ) ) {
|
||||
Debug( "Using cached scaled image at $scaled_path.");
|
||||
if ( ! readfile( $scaled_path ) ) {
|
||||
Error("No bytes read from scaled image". $scaled_path );
|
||||
}
|
||||
} else {
|
||||
Debug( "Cached scaled image does not exist at $scaled_path. Creating it");
|
||||
ob_start();
|
||||
if ( ! $i )
|
||||
$i = imagecreatefromjpeg( $path );
|
||||
$iScale = imagescale( $i, $width, $height );
|
||||
imagejpeg( $iScale );
|
||||
imagedestroy( $i );
|
||||
imagedestroy( $iScale );
|
||||
$scaled_jpeg_data = ob_get_contents();
|
||||
file_put_contents( $scaled_path, $scaled_jpeg_data );
|
||||
ob_end_clean();
|
||||
echo $scaled_jpeg_data;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue