added gif resize functionality

This commit is contained in:
Christian Haschek
2015-11-27 13:03:21 +01:00
parent 845ac61b53
commit 0e362c3d8a
3 changed files with 51 additions and 52 deletions

View File

@@ -17,19 +17,11 @@ class Image
function forceResize(&$img,$size)
{
if(!is_numeric($size))
$size = explode('x',$size);
$pm = new PictshareModel();
if(is_array($size))
{
$maxwidth = $size[0];
$maxheight = $size[1];
}
else if($size)
{
$maxwidth = $size;
$maxheight = $size;
}
$sd = $pm->sizeStringToWidthHeight($size);
$maxwidth = $sd['maxwidth'];
$maxheight = $sd['maxheight'];
@@ -76,19 +68,11 @@ class Image
*/
function resize(&$img,$size)
{
if(!is_numeric($size))
$size = explode('x',$size);
$pm = new PictshareModel();
if(is_array($size))
{
$maxwidth = $size[0];
$maxheight = $size[1];
}
else if($size)
{
$maxwidth = $size;
$maxheight = $size;
}
$sd = $pm->sizeStringToWidthHeight($size);
$maxwidth = $sd['maxwidth'];
$maxheight = $sd['maxheight'];
$width = imagesx($img);
$height = imagesy($img);

View File

@@ -175,7 +175,14 @@ function renderImage($data)
}
else //user wants gif
{
if(!$cached && $data['size'])
{
$pm->resizeFFMPEG($data,$cachepath,'gif');
}
header ("Content-type: image/gif");
if(file_exists($cachepath))
readfile($cachepath);
else
readfile($path);
}
@@ -183,7 +190,7 @@ function renderImage($data)
case 'mp4':
if(!$cached && !$data['preview'])
{
$pm->resizeMP4($data,$cachepath);
$pm->resizeFFMPEG($data,$cachepath,'mp4');
$path = $cachepath;
}

View File

@@ -650,7 +650,7 @@ class PictshareModel extends Model
return $ismp4;
}
function resizeMP4($data,$cachepath)
function resizeFFMPEG($data,$cachepath,$type='mp4')
{
$file = ROOT.DS.'upload'.DS.$data['hash'].DS.$data['hash'];
$file = escapeshellarg($file);
@@ -661,27 +661,20 @@ class PictshareModel extends Model
if(!$size) return $file;
if(!is_numeric($size))
$size = explode('x',$size);
$sd = $this->sizeStringToWidthHeight($size);
$maxwidth = $sd['width'];
$maxheight = $sd['height'];
if(is_array($size))
switch($type)
{
$maxwidth = $size[0];
$maxheight = $size[1];
}
else if($size)
{
$maxwidth = $size;
$maxheight = 0;
case 'mp4':
$addition = '-c:v libx264';
break;
}
if($maxwidth>1080)
$maxwidth = 1080;
//if(!$maxheight)
$maxheight = 'trunc(ow/a/2)*2';
$cmd = "$bin -i $file -y -vf scale=\"$maxwidth:$maxheight\" -c:v libx264 -f mp4 $cachepath";
$cmd = "$bin -i $file -y -vf scale=\"$maxwidth:$maxheight\" $addition -f $type $cachepath";
system($cmd);
@@ -772,7 +765,6 @@ class PictshareModel extends Model
"width"=> $data['width'],
"height"=> $data['height'],
"title"=> "PictShare",
//"url"=> $url.'/raw',
"provider_name"=> "PictShare",
"provider_url"=> DOMAINPATH,
"html"=> '<video id="video" poster="'.$url.'/preview'.'" preload="auto" autoplay="autoplay" muted="muted" loop="loop" webkit-playsinline>
@@ -786,8 +778,24 @@ class PictshareModel extends Model
}
}
function getMP4PathOfGif($gifpath)
function sizeStringToWidthHeight($size)
{
if(!$size || !$this->isSize($size)) return false;
if(!is_numeric($size))
$size = explode('x',$size);
if(is_array($size))
{
$maxwidth = $size[0];
$maxheight = $size[1];
}
else if($size)
{
$maxwidth = $size;
$maxheight = $size;
}
return array('width'=>$maxwidth,'height'=>$maxheight);
}
}