fix if structuring
This commit is contained in:
parent
b38aa60209
commit
b8c8ff3807
|
@ -47,16 +47,16 @@ 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
|
||||
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));
|
||||
|
||||
return $imageNew;
|
||||
}
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
$Storage = NULL;
|
||||
|
@ -68,10 +68,10 @@ if ( empty($_REQUEST['path']) )
|
|||
$Event = new Event( $_REQUEST['eid'] );
|
||||
$Storage = $Event->Storage();
|
||||
$path = $Event->Relative_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() );
|
||||
} 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->Relative_Path().'/'.sprintf("%'.0".ZM_EVENT_IMAGE_DIGITS.'d',$Frame->FrameId()).'-capture.jpg';
|
||||
}
|
||||
|
@ -81,88 +81,82 @@ if ( empty($_REQUEST['path']) )
|
|||
}
|
||||
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";
|
||||
}
|
||||
$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";
|
||||
}
|
||||
}
|
||||
|
||||
$scale=0;
|
||||
if( !empty($_REQUEST['scale']) )
|
||||
if (is_numeric($_REQUEST['scale']))
|
||||
{
|
||||
$x = $_REQUEST['scale'];
|
||||
if($x >= 1 and $x <= 400)
|
||||
$scale=$x;
|
||||
}
|
||||
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 (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 (is_numeric($_REQUEST['height']))
|
||||
{
|
||||
$x = $_REQUEST['height'];
|
||||
if($x >= 10 and $x <= 8000)
|
||||
$height=$x;
|
||||
}
|
||||
|
||||
|
||||
if ( $errorText )
|
||||
Error( $errorText );
|
||||
else
|
||||
if( ($scale==0 || $scale==100) && $width==0 && $height==0 )
|
||||
if ( ! readfile( $Storage->Path().'/'.$path ) ) {
|
||||
Error("No bytes read from ". $Storage->Path() . '/'.$path );
|
||||
if ( $errorText ) {
|
||||
Error( $errorText );
|
||||
} else {
|
||||
if ( ( $scale==0 || $scale==100 ) && $width==0 && $height==0 ) {
|
||||
if ( ! readfile( $Storage->Path().'/'.$path ) ) {
|
||||
Error("No bytes read from ". $Storage->Path() . '/'.$path );
|
||||
}
|
||||
} else {
|
||||
Error("Doing a scaled image: scale($scale) width($width) height($height)");
|
||||
$i = imagecreatefromjpeg ( $Storage->Path().'/'.$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) {// See if we really need to scale
|
||||
imagejpeg($i);
|
||||
imagedestroy($i);
|
||||
} else { // we do need to scale
|
||||
$iScale = imagescale($i, $width, $height);
|
||||
imagejpeg($iScale);
|
||||
imagedestroy($i);
|
||||
imagedestroy($iScale);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$i = imagecreatefromjpeg ( $Storage->Path().'/'.$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) // See if we really need to scale
|
||||
{
|
||||
imagejpeg($i);
|
||||
imagedestroy($i);
|
||||
}
|
||||
else // we do need to scale
|
||||
{
|
||||
$iScale = imagescale($i, $width, $height);
|
||||
imagejpeg($iScale);
|
||||
imagedestroy($i);
|
||||
imagedestroy($iScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue