움직이지 않는 gif도 mp4로 변환되는 문제 수정

FFmpeg 사용 불가 안내 메시지 추가
추후에 활용하기 위한 type, width, height, duration 컬럼 추가
업로드시 이미지, 오디오, 동영상 파일의 확장자가 잘못된 경우 올바른 확장자를 덧붙이는 기능 추가
This commit is contained in:
conory 2019-10-01 22:50:38 +09:00
parent cdbc2d7a82
commit 16e44d44c7
18 changed files with 331 additions and 180 deletions

View file

@ -8,14 +8,43 @@ namespace Rhymix\Framework;
class Image
{
/**
* Check Check if file is an image
* Check if a file is an image
*
* @param string $filename
* @return bool
*/
public static function isImage($filename)
{
return strtolower(array_shift(explode('/', @mime_content_type($filename)))) === 'image';
return array_shift(explode('/', Storage::getContentType($filename))) === 'image';
}
/**
* Check if a file is an animated GIF.
*
* @param string $filename
* @return bool
*/
public static function isAnimatedGIF($filename)
{
if (Storage::getContentType($filename) !== 'image/gif')
{
return false;
}
if (!$fp = @fopen($filename, 'rb'))
{
return false;
}
$frames = 0;
while (!feof($fp) && $frames < 2)
{
$frames += preg_match_all('#\x00\x21\xF9\x04.{4}\x00[\x2C\x21]#s', fread($fp, 1024 * 16) ?: '');
if (!feof($fp))
{
fseek($fp, -9, SEEK_CUR);
}
}
fclose($fp);
return $frames > 1;
}
/**
@ -38,9 +67,9 @@ class Image
'width' => $image_info[0],
'height' => $image_info[1],
'type' => image_type_to_extension($image_info[2], false),
'bits' => $image_info['bits'],
'channels' => $image_info['channels'],
'mime' => $image_info['mime'],
'bits' => $image_info['bits'] ?? null,
'channels' => $image_info['channels'] ?? null,
];
}
}