mirror of
https://github.com/HaschekSolutions/pictshare.git
synced 2025-11-19 06:28:01 +00:00
added gif resize functionality
This commit is contained in:
@@ -17,19 +17,11 @@ class Image
|
|||||||
|
|
||||||
function forceResize(&$img,$size)
|
function forceResize(&$img,$size)
|
||||||
{
|
{
|
||||||
if(!is_numeric($size))
|
$pm = new PictshareModel();
|
||||||
$size = explode('x',$size);
|
|
||||||
|
|
||||||
if(is_array($size))
|
$sd = $pm->sizeStringToWidthHeight($size);
|
||||||
{
|
$maxwidth = $sd['maxwidth'];
|
||||||
$maxwidth = $size[0];
|
$maxheight = $sd['maxheight'];
|
||||||
$maxheight = $size[1];
|
|
||||||
}
|
|
||||||
else if($size)
|
|
||||||
{
|
|
||||||
$maxwidth = $size;
|
|
||||||
$maxheight = $size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -76,19 +68,11 @@ class Image
|
|||||||
*/
|
*/
|
||||||
function resize(&$img,$size)
|
function resize(&$img,$size)
|
||||||
{
|
{
|
||||||
if(!is_numeric($size))
|
$pm = new PictshareModel();
|
||||||
$size = explode('x',$size);
|
|
||||||
|
|
||||||
if(is_array($size))
|
$sd = $pm->sizeStringToWidthHeight($size);
|
||||||
{
|
$maxwidth = $sd['maxwidth'];
|
||||||
$maxwidth = $size[0];
|
$maxheight = $sd['maxheight'];
|
||||||
$maxheight = $size[1];
|
|
||||||
}
|
|
||||||
else if($size)
|
|
||||||
{
|
|
||||||
$maxwidth = $size;
|
|
||||||
$maxheight = $size;
|
|
||||||
}
|
|
||||||
|
|
||||||
$width = imagesx($img);
|
$width = imagesx($img);
|
||||||
$height = imagesy($img);
|
$height = imagesy($img);
|
||||||
|
|||||||
@@ -175,7 +175,14 @@ function renderImage($data)
|
|||||||
}
|
}
|
||||||
else //user wants gif
|
else //user wants gif
|
||||||
{
|
{
|
||||||
|
if(!$cached && $data['size'])
|
||||||
|
{
|
||||||
|
$pm->resizeFFMPEG($data,$cachepath,'gif');
|
||||||
|
}
|
||||||
header ("Content-type: image/gif");
|
header ("Content-type: image/gif");
|
||||||
|
if(file_exists($cachepath))
|
||||||
|
readfile($cachepath);
|
||||||
|
else
|
||||||
readfile($path);
|
readfile($path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +190,7 @@ function renderImage($data)
|
|||||||
case 'mp4':
|
case 'mp4':
|
||||||
if(!$cached && !$data['preview'])
|
if(!$cached && !$data['preview'])
|
||||||
{
|
{
|
||||||
$pm->resizeMP4($data,$cachepath);
|
$pm->resizeFFMPEG($data,$cachepath,'mp4');
|
||||||
$path = $cachepath;
|
$path = $cachepath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ class PictshareModel extends Model
|
|||||||
return $ismp4;
|
return $ismp4;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resizeMP4($data,$cachepath)
|
function resizeFFMPEG($data,$cachepath,$type='mp4')
|
||||||
{
|
{
|
||||||
$file = ROOT.DS.'upload'.DS.$data['hash'].DS.$data['hash'];
|
$file = ROOT.DS.'upload'.DS.$data['hash'].DS.$data['hash'];
|
||||||
$file = escapeshellarg($file);
|
$file = escapeshellarg($file);
|
||||||
@@ -661,27 +661,20 @@ class PictshareModel extends Model
|
|||||||
|
|
||||||
if(!$size) return $file;
|
if(!$size) return $file;
|
||||||
|
|
||||||
if(!is_numeric($size))
|
$sd = $this->sizeStringToWidthHeight($size);
|
||||||
$size = explode('x',$size);
|
$maxwidth = $sd['width'];
|
||||||
|
$maxheight = $sd['height'];
|
||||||
|
|
||||||
if(is_array($size))
|
switch($type)
|
||||||
{
|
{
|
||||||
$maxwidth = $size[0];
|
case 'mp4':
|
||||||
$maxheight = $size[1];
|
$addition = '-c:v libx264';
|
||||||
}
|
break;
|
||||||
else if($size)
|
|
||||||
{
|
|
||||||
$maxwidth = $size;
|
|
||||||
$maxheight = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if($maxwidth>1080)
|
|
||||||
$maxwidth = 1080;
|
|
||||||
|
|
||||||
//if(!$maxheight)
|
|
||||||
$maxheight = 'trunc(ow/a/2)*2';
|
$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);
|
system($cmd);
|
||||||
|
|
||||||
@@ -772,7 +765,6 @@ class PictshareModel extends Model
|
|||||||
"width"=> $data['width'],
|
"width"=> $data['width'],
|
||||||
"height"=> $data['height'],
|
"height"=> $data['height'],
|
||||||
"title"=> "PictShare",
|
"title"=> "PictShare",
|
||||||
//"url"=> $url.'/raw',
|
|
||||||
"provider_name"=> "PictShare",
|
"provider_name"=> "PictShare",
|
||||||
"provider_url"=> DOMAINPATH,
|
"provider_url"=> DOMAINPATH,
|
||||||
"html"=> '<video id="video" poster="'.$url.'/preview'.'" preload="auto" autoplay="autoplay" muted="muted" loop="loop" webkit-playsinline>
|
"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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user