Fixed getting dimensions of videos and flashes
This commit is contained in:
parent
dd02938a96
commit
60f4dd9d4a
11 changed files with 203 additions and 220 deletions
130
src/Services/ImageConverter.php
Normal file
130
src/Services/ImageConverter.php
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Helpers\MimeHelper;
|
||||
use Szurubooru\Helpers\ProgramExecutor;
|
||||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||
|
||||
class ImageConverter
|
||||
{
|
||||
const PROGRAM_NAME_DUMP_GNASH = 'dump-gnash';
|
||||
const PROGRAM_NAME_SWFRENDER = 'swfrender';
|
||||
const PROGRAM_NAME_FFMPEG = 'ffmpeg';
|
||||
const PROGRAM_NAME_FFMPEGTHUMBNAILER = 'ffmpegthumbnailer';
|
||||
|
||||
private $imageManipulator;
|
||||
|
||||
public function __construct(ImageManipulator $imageManipulator)
|
||||
{
|
||||
$this->imageManipulator = $imageManipulator;
|
||||
}
|
||||
|
||||
|
||||
public function createImageFromBuffer($source)
|
||||
{
|
||||
$tmpSourcePath = tempnam(sys_get_temp_dir(), 'thumb') . '.dat';
|
||||
$tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
|
||||
try
|
||||
{
|
||||
file_put_contents($tmpSourcePath, $source);
|
||||
if (!$this->convert($tmpSourcePath, $tmpTargetPath))
|
||||
throw new \Exception('Error while converting supplied file to image');
|
||||
|
||||
$tmpSource = file_get_contents($tmpTargetPath);
|
||||
return $this->imageManipulator->loadFromBuffer($tmpSource);
|
||||
}
|
||||
finally
|
||||
{
|
||||
$this->deleteIfExists($tmpSourcePath);
|
||||
$this->deleteIfExists($tmpTargetPath);
|
||||
}
|
||||
}
|
||||
|
||||
public function convert($sourcePath, $targetPath)
|
||||
{
|
||||
$mime = MimeHelper::getMimeTypeFromFile($sourcePath);
|
||||
|
||||
if (MimeHelper::isImage($mime))
|
||||
{
|
||||
copy($sourcePath, $targetPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (MimeHelper::isFlash($mime))
|
||||
return $this->convertFromFlash($sourcePath, $targetPath);
|
||||
|
||||
if (MimeHelper::isVideo($mime))
|
||||
return $this->convertFromVideo($sourcePath, $targetPath);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function convertFromFlash($sourcePath, $targetPath)
|
||||
{
|
||||
if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_DUMP_GNASH))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_DUMP_GNASH,
|
||||
[
|
||||
'--screenshot', 'last',
|
||||
'--screenshot-file', $targetPath,
|
||||
'-1',
|
||||
'-r1',
|
||||
'--max-advances', '15',
|
||||
$sourcePath,
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($targetPath) and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_SWFRENDER))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_SWFRENDER,
|
||||
[
|
||||
'swfrender',
|
||||
$sourcePath,
|
||||
'-o',
|
||||
$targetPath,
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($targetPath))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function convertFromVideo($sourcePath, $targetPath)
|
||||
{
|
||||
if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEGTHUMBNAILER))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_FFMPEGTHUMBNAILER,
|
||||
[
|
||||
'-i' . $sourcePath,
|
||||
'-o' . $targetPath,
|
||||
'-s0',
|
||||
'-t12%%'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($targetPath) and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
|
||||
{
|
||||
ProgramExecutor::run(self::PROGRAM_NAME_FFMEPG,
|
||||
[
|
||||
'-i', $sourcePath,
|
||||
'-vframes', '1',
|
||||
$targetPath
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($targetPath))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function deleteIfExists($path)
|
||||
{
|
||||
if (file_exists($path))
|
||||
unlink($path);
|
||||
}
|
||||
}
|
|
@ -18,6 +18,7 @@ use Szurubooru\SearchServices\Requirements\RequirementCompositeValue;
|
|||
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
|
||||
use Szurubooru\Services\AuthService;
|
||||
use Szurubooru\Services\HistoryService;
|
||||
use Szurubooru\Services\ImageConverter;
|
||||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||
use Szurubooru\Services\NetworkingService;
|
||||
use Szurubooru\Services\TagService;
|
||||
|
@ -36,6 +37,7 @@ class PostService
|
|||
private $networkingService;
|
||||
private $tagService;
|
||||
private $historyService;
|
||||
private $imageConverter;
|
||||
private $imageManipulator;
|
||||
|
||||
public function __construct(
|
||||
|
@ -49,6 +51,7 @@ class PostService
|
|||
NetworkingService $networkingService,
|
||||
TagService $tagService,
|
||||
HistoryService $historyService,
|
||||
ImageConverter $imageConverter,
|
||||
ImageManipulator $imageManipulator)
|
||||
{
|
||||
$this->config = $config;
|
||||
|
@ -61,6 +64,7 @@ class PostService
|
|||
$this->networkingService = $networkingService;
|
||||
$this->tagService = $tagService;
|
||||
$this->historyService = $historyService;
|
||||
$this->imageConverter = $imageConverter;
|
||||
$this->imageManipulator = $imageManipulator;
|
||||
}
|
||||
|
||||
|
@ -247,9 +251,17 @@ class PostService
|
|||
|
||||
$post->setContent($content);
|
||||
|
||||
$image = $this->imageManipulator->loadFromBuffer($content);
|
||||
$post->setImageWidth($this->imageManipulator->getImageWidth($image));
|
||||
$post->setImageHeight($this->imageManipulator->getImageHeight($image));
|
||||
try
|
||||
{
|
||||
$image = $this->imageConverter->createImageFromBuffer($content);
|
||||
$post->setImageWidth($this->imageManipulator->getImageWidth($image));
|
||||
$post->setImageHeight($this->imageManipulator->getImageHeight($image));
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$post->setImageWidth(null);
|
||||
$post->setImageHeight(null);
|
||||
}
|
||||
|
||||
$post->setOriginalFileSize(strlen($content));
|
||||
}
|
||||
|
|
|
@ -1,47 +1,48 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Services\ImageManipulation\IImageManipulator;
|
||||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||
|
||||
class ImageThumbnailGenerator implements IThumbnailGenerator
|
||||
class ThumbnailGenerator
|
||||
{
|
||||
private $imageManipulator;
|
||||
const CROP_OUTSIDE = 0;
|
||||
const CROP_INSIDE = 1;
|
||||
|
||||
public function __construct(ImageManipulator $imageManipulator)
|
||||
private $imageManipulator;
|
||||
private $imageConverter;
|
||||
|
||||
public function __construct(ImageManipulator $imageManipulator, ImageConverter $imageConverter)
|
||||
{
|
||||
$this->imageManipulator = $imageManipulator;
|
||||
$this->imageConverter = $imageConverter;
|
||||
}
|
||||
|
||||
public function generate($source, $width, $height, $cropStyle)
|
||||
{
|
||||
try
|
||||
$image = $this->imageConverter->createImageFromBuffer($source);
|
||||
if (!$image)
|
||||
throw new \Exception('Error while loading supplied image');
|
||||
|
||||
$srcWidth = $this->imageManipulator->getImageWidth($image);
|
||||
$srcHeight = $this->imageManipulator->getImageHeight($image);
|
||||
|
||||
switch ($cropStyle)
|
||||
{
|
||||
$image = $this->imageManipulator->loadFromBuffer($source);
|
||||
$srcWidth = $this->imageManipulator->getImageWidth($image);
|
||||
$srcHeight = $this->imageManipulator->getImageHeight($image);
|
||||
case ThumbnailGenerator::CROP_OUTSIDE:
|
||||
$this->cropOutside($image, $srcWidth, $srcHeight, $width, $height);
|
||||
break;
|
||||
|
||||
switch ($cropStyle)
|
||||
{
|
||||
case IThumbnailGenerator::CROP_OUTSIDE:
|
||||
$this->cropOutside($image, $srcWidth, $srcHeight, $width, $height);
|
||||
break;
|
||||
case ThumbnailGenerator::CROP_INSIDE:
|
||||
$this->cropInside($image, $srcWidth, $srcHeight, $width, $height);
|
||||
break;
|
||||
|
||||
case IThumbnailGenerator::CROP_INSIDE:
|
||||
$this->cropInside($image, $srcWidth, $srcHeight, $width, $height);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown thumbnail crop style');
|
||||
}
|
||||
|
||||
return $this->imageManipulator->saveToBuffer(
|
||||
$image,
|
||||
IImageManipulator::FORMAT_JPEG);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return null;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Unknown thumbnail crop style');
|
||||
}
|
||||
|
||||
return $this->imageManipulator->saveToBuffer(
|
||||
$image,
|
||||
IImageManipulator::FORMAT_JPEG);
|
||||
}
|
||||
|
||||
private function cropOutside(&$image, $srcWidth, $srcHeight, $dstWidth, $dstHeight)
|
|
@ -1,60 +0,0 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
use Szurubooru\Helpers\ProgramExecutor;
|
||||
|
||||
class FlashThumbnailGenerator implements IThumbnailGenerator
|
||||
{
|
||||
const PROGRAM_NAME_DUMP_GNASH = 'dump-gnash';
|
||||
const PROGRAM_NAME_SWFRENDER = 'swfrender';
|
||||
|
||||
private $imageThumbnailGenerator;
|
||||
|
||||
public function __construct(ImageThumbnailGenerator $imageThumbnailGenerator)
|
||||
{
|
||||
$this->imageThumbnailGenerator = $imageThumbnailGenerator;
|
||||
}
|
||||
|
||||
public function generate($source, $width, $height, $cropStyle)
|
||||
{
|
||||
$tmpSourcePath = tempnam(sys_get_temp_dir(), 'thumb') . '.dat';
|
||||
$tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
|
||||
file_put_contents($tmpSourcePath, $source);
|
||||
|
||||
if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_DUMP_GNASH))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_DUMP_GNASH,
|
||||
[
|
||||
'--screenshot', 'last',
|
||||
'--screenshot-file', $tmpTargetPath,
|
||||
'-1',
|
||||
'-r1',
|
||||
'--max-advances', '15',
|
||||
$tmpSourcePath,
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($tmpTargetPath) and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_SWFRENDER))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_SWFRENDER,
|
||||
[
|
||||
'swfrender',
|
||||
$tmpSourcePath,
|
||||
'-o',
|
||||
$tmpTargetPath,
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($tmpTargetPath))
|
||||
{
|
||||
unlink($tmpSourcePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
$ret = $this->imageThumbnailGenerator->generate(file_get_contents($tmpTargetPath), $width, $height, $cropStyle);
|
||||
unlink($tmpSourcePath);
|
||||
unlink($tmpTargetPath);
|
||||
return $ret;
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
|
||||
interface IThumbnailGenerator
|
||||
{
|
||||
const CROP_OUTSIDE = 0;
|
||||
const CROP_INSIDE = 1;
|
||||
|
||||
public function generate($sourceString, $width, $height, $cropStyle);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
use Szurubooru\Helpers\MimeHelper;
|
||||
|
||||
class SmartThumbnailGenerator implements IThumbnailGenerator
|
||||
{
|
||||
private $flashThumbnailGenerator;
|
||||
private $videoThumbnailGenerator;
|
||||
private $imageThumbnailGenerator;
|
||||
|
||||
public function __construct(
|
||||
FlashThumbnailGenerator $flashThumbnailGenerator,
|
||||
VideoThumbnailGenerator $videoThumbnailGenerator,
|
||||
ImageThumbnailGenerator $imageThumbnailGenerator)
|
||||
{
|
||||
$this->flashThumbnailGenerator = $flashThumbnailGenerator;
|
||||
$this->videoThumbnailGenerator = $videoThumbnailGenerator;
|
||||
$this->imageThumbnailGenerator = $imageThumbnailGenerator;
|
||||
}
|
||||
|
||||
public function generate($source, $width, $height, $cropStyle)
|
||||
{
|
||||
$mime = MimeHelper::getMimeTypeFromBuffer($source);
|
||||
|
||||
if (MimeHelper::isFlash($mime))
|
||||
return $this->flashThumbnailGenerator->generate($source, $width, $height, $cropStyle);
|
||||
|
||||
if (MimeHelper::isVideo($mime))
|
||||
return $this->videoThumbnailGenerator->generate($source, $width, $height, $cropStyle);
|
||||
|
||||
if (MimeHelper::isImage($mime))
|
||||
return $this->imageThumbnailGenerator->generate($source, $width, $height, $cropStyle);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
namespace Szurubooru\Services\ThumbnailGenerators;
|
||||
use \Szurubooru\Helpers\ProgramExecutor;
|
||||
|
||||
class VideoThumbnailGenerator implements IThumbnailGenerator
|
||||
{
|
||||
const PROGRAM_NAME_FFMPEG = 'ffmpeg';
|
||||
const PROGRAM_NAME_FFMPEGTHUMBNAILER = 'ffmpegthumbnailer';
|
||||
|
||||
private $imageThumbnailGenerator;
|
||||
|
||||
public function __construct(ImageThumbnailGenerator $imageThumbnailGenerator)
|
||||
{
|
||||
$this->imageThumbnailGenerator = $imageThumbnailGenerator;
|
||||
}
|
||||
|
||||
public function generate($source, $width, $height, $cropStyle)
|
||||
{
|
||||
$tmpSourcePath = tempnam(sys_get_temp_dir(), 'thumb') . '.dat';
|
||||
$tmpTargetPath = tempnam(sys_get_temp_dir(), 'thumb') . '.png';
|
||||
file_put_contents($tmpSourcePath, $source);
|
||||
|
||||
if (ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEGTHUMBNAILER))
|
||||
{
|
||||
ProgramExecutor::run(
|
||||
self::PROGRAM_NAME_FFMPEGTHUMBNAILER,
|
||||
[
|
||||
'-i' . $tmpSourcePath,
|
||||
'-o' . $tmpTargetPath,
|
||||
'-s0',
|
||||
'-t12%%'
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($tmpTargetPath) and ProgramExecutor::isProgramAvailable(self::PROGRAM_NAME_FFMPEG))
|
||||
{
|
||||
ProgramExecutor::run(self::PROGRAM_NAME_FFMEPG,
|
||||
[
|
||||
'-i', $tmpSourcePath,
|
||||
'-vframes', '1',
|
||||
$tmpTargetPath
|
||||
]);
|
||||
}
|
||||
|
||||
if (!file_exists($tmpTargetPath))
|
||||
{
|
||||
unlink($tmpSourcePath);
|
||||
return null;
|
||||
}
|
||||
|
||||
$ret = $this->imageThumbnailGenerator->generate(file_get_contents($tmpTargetPath), $width, $height, $cropStyle);
|
||||
unlink($tmpSourcePath);
|
||||
unlink($tmpTargetPath);
|
||||
return $ret;
|
||||
}
|
||||
}
|
|
@ -2,8 +2,7 @@
|
|||
namespace Szurubooru\Services;
|
||||
use Szurubooru\Config;
|
||||
use Szurubooru\Dao\PublicFileDao;
|
||||
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerator;
|
||||
|
||||
class ThumbnailService
|
||||
{
|
||||
|
@ -14,7 +13,7 @@ class ThumbnailService
|
|||
public function __construct(
|
||||
Config $config,
|
||||
PublicFileDao $fileDao,
|
||||
SmartThumbnailGenerator $thumbnailGenerator)
|
||||
ThumbnailGenerator $thumbnailGenerator)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->fileDao = $fileDao;
|
||||
|
@ -46,11 +45,11 @@ class ThumbnailService
|
|||
switch ($this->config->misc->thumbnailCropStyle)
|
||||
{
|
||||
case 'outside':
|
||||
$cropStyle = IThumbnailGenerator::CROP_OUTSIDE;
|
||||
$cropStyle = ThumbnailGenerator::CROP_OUTSIDE;
|
||||
break;
|
||||
|
||||
case 'inside':
|
||||
$cropStyle = IThumbnailGenerator::CROP_INSIDE;
|
||||
$cropStyle = humbnailGenerator::CROP_INSIDE;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -9,6 +9,7 @@ use Szurubooru\FormData\UploadFormData;
|
|||
use Szurubooru\Injector;
|
||||
use Szurubooru\Services\AuthService;
|
||||
use Szurubooru\Services\HistoryService;
|
||||
use Szurubooru\Services\ImageConverter;
|
||||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||
use Szurubooru\Services\NetworkingService;
|
||||
use Szurubooru\Services\PostService;
|
||||
|
@ -29,6 +30,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
|||
private $networkingServiceMock;
|
||||
private $tagService;
|
||||
private $historyServiceMock;
|
||||
private $imageConverterMock;
|
||||
private $imageManipulatorMock;
|
||||
|
||||
public function setUp()
|
||||
|
@ -45,6 +47,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
|||
$this->tagService = Injector::get(TagService::class);
|
||||
$this->historyServiceMock = $this->mock(HistoryService::class);
|
||||
$this->configMock->set('database/maxPostSize', 1000000);
|
||||
$this->imageConverterMock = $this->mock(ImageConverter::class);
|
||||
$this->imageManipulatorMock = $this->mock(ImageManipulator::class);
|
||||
}
|
||||
|
||||
|
@ -59,6 +62,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
|||
$this->postDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0));
|
||||
$this->authServiceMock->expects($this->once())->method('getLoggedInUser')->willReturn(new User(5));
|
||||
$this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new Snapshot());
|
||||
$this->imageConverterMock->expects($this->never())->method('createImageFromBuffer');
|
||||
|
||||
$this->postService = $this->getPostService();
|
||||
$savedPost = $this->postService->createPost($formData);
|
||||
|
@ -109,6 +113,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
|||
|
||||
$this->postDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0));
|
||||
$this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new Snapshot());
|
||||
$this->imageConverterMock->expects($this->once())->method('createImageFromBuffer');
|
||||
|
||||
$this->postService = $this->getPostService();
|
||||
$savedPost = $this->postService->createPost($formData);
|
||||
|
@ -128,6 +133,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
|||
|
||||
$this->postDaoMock->expects($this->once())->method('save')->will($this->returnArgument(0));
|
||||
$this->historyServiceMock->expects($this->once())->method('getPostChangeSnapshot')->willReturn(new Snapshot());
|
||||
$this->imageConverterMock->expects($this->once())->method('createImageFromBuffer');
|
||||
|
||||
$this->postService = $this->getPostService();
|
||||
$savedPost = $this->postService->createPost($formData);
|
||||
|
@ -210,6 +216,7 @@ final class PostServiceTest extends AbstractDatabaseTestCase
|
|||
$this->networkingServiceMock,
|
||||
$this->tagService,
|
||||
$this->historyServiceMock,
|
||||
$this->imageConverterMock,
|
||||
$this->imageManipulatorMock);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,19 +2,17 @@
|
|||
namespace Szurubooru\Tests\Services;
|
||||
use Szurubooru\Helpers\ProgramExecutor;
|
||||
use Szurubooru\Injector;
|
||||
use Szurubooru\Services\ImageConverter;
|
||||
use Szurubooru\Services\ImageManipulation\ImageManipulator;
|
||||
use Szurubooru\Services\ThumbnailGenerators\FlashThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerators\VideoThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerator;
|
||||
use Szurubooru\Tests\AbstractTestCase;
|
||||
|
||||
final class ThumbnailGeneratorTest extends AbstractTestCase
|
||||
{
|
||||
public function testFlashThumbnails()
|
||||
{
|
||||
if (!ProgramExecutor::isProgramAvailable(FlashThumbnailGenerator::PROGRAM_NAME_DUMP_GNASH)
|
||||
and !ProgramExecutor::isProgramAvailable(FlashThumbnailGenerator::PROGRAM_NAME_SWFRENDER))
|
||||
if (!ProgramExecutor::isProgramAvailable(ImageConverter::PROGRAM_NAME_DUMP_GNASH)
|
||||
and !ProgramExecutor::isProgramAvailable(ImageConverter::PROGRAM_NAME_SWFRENDER))
|
||||
{
|
||||
$this->markTestSkipped('External software necessary to run this test is missing.');
|
||||
}
|
||||
|
@ -26,7 +24,7 @@ final class ThumbnailGeneratorTest extends AbstractTestCase
|
|||
$this->getTestFile('flash.swf'),
|
||||
150,
|
||||
150,
|
||||
IThumbnailGenerator::CROP_OUTSIDE);
|
||||
ThumbnailGenerator::CROP_OUTSIDE);
|
||||
|
||||
$image = $imageManipulator->loadFromBuffer($result);
|
||||
$this->assertEquals(150, $imageManipulator->getImageWidth($image));
|
||||
|
@ -35,8 +33,8 @@ final class ThumbnailGeneratorTest extends AbstractTestCase
|
|||
|
||||
public function testVideoThumbnails()
|
||||
{
|
||||
if (!ProgramExecutor::isProgramAvailable(VideoThumbnailGenerator::PROGRAM_NAME_FFMPEG)
|
||||
and !ProgramExecutor::isProgramAvailable(VideoThumbnailGenerator::PROGRAM_NAME_FFMPEGTHUMBNAILER))
|
||||
if (!ProgramExecutor::isProgramAvailable(ImageConverter::PROGRAM_NAME_FFMPEG)
|
||||
and !ProgramExecutor::isProgramAvailable(ImageConverter::PROGRAM_NAME_FFMPEGTHUMBNAILER))
|
||||
{
|
||||
$this->markTestSkipped('External software necessary to run this test is missing.');
|
||||
}
|
||||
|
@ -48,7 +46,7 @@ final class ThumbnailGeneratorTest extends AbstractTestCase
|
|||
$this->getTestFile('video.mp4'),
|
||||
150,
|
||||
150,
|
||||
IThumbnailGenerator::CROP_OUTSIDE);
|
||||
ThumbnailGenerator::CROP_OUTSIDE);
|
||||
|
||||
$image = $imageManipulator->loadFromBuffer($result);
|
||||
$this->assertEquals(150, $imageManipulator->getImageWidth($image));
|
||||
|
@ -64,7 +62,7 @@ final class ThumbnailGeneratorTest extends AbstractTestCase
|
|||
$this->getTestFile('image.jpg'),
|
||||
150,
|
||||
150,
|
||||
IThumbnailGenerator::CROP_OUTSIDE);
|
||||
ThumbnailGenerator::CROP_OUTSIDE);
|
||||
|
||||
$image = $imageManipulator->loadFromBuffer($result);
|
||||
$this->assertEquals(150, $imageManipulator->getImageWidth($image));
|
||||
|
@ -74,7 +72,7 @@ final class ThumbnailGeneratorTest extends AbstractTestCase
|
|||
$this->getTestFile('image.jpg'),
|
||||
150,
|
||||
150,
|
||||
IThumbnailGenerator::CROP_INSIDE);
|
||||
ThumbnailGenerator::CROP_INSIDE);
|
||||
|
||||
$image = $imageManipulator->loadFromBuffer($result);
|
||||
$this->assertEquals(150, $imageManipulator->getImageWidth($image));
|
||||
|
@ -86,13 +84,12 @@ final class ThumbnailGeneratorTest extends AbstractTestCase
|
|||
$thumbnailGenerator = $this->getThumbnailGenerator();
|
||||
$imageManipulator = $this->getImageManipulator();
|
||||
|
||||
$result = $thumbnailGenerator->generate(
|
||||
$this->setExpectedException(\Exception::class);
|
||||
$thumbnailGenerator->generate(
|
||||
$this->getTestFile('text.txt'),
|
||||
150,
|
||||
150,
|
||||
IThumbnailGenerator::CROP_OUTSIDE);
|
||||
|
||||
$this->assertNull($result);
|
||||
ThumbnailGenerator::CROP_OUTSIDE);
|
||||
}
|
||||
|
||||
public function getImageManipulator()
|
||||
|
@ -102,6 +99,6 @@ final class ThumbnailGeneratorTest extends AbstractTestCase
|
|||
|
||||
public function getThumbnailGenerator()
|
||||
{
|
||||
return Injector::get(SmartThumbnailGenerator::class);
|
||||
return Injector::get(ThumbnailGenerator::class);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
<?php
|
||||
namespace Szurubooru\Tests\Services;
|
||||
use Szurubooru\Dao\PublicFileDao;
|
||||
use Szurubooru\Services\ThumbnailGenerators\IThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerators\SmartThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailGenerator;
|
||||
use Szurubooru\Services\ThumbnailService;
|
||||
use Szurubooru\Tests\AbstractTestCase;
|
||||
|
||||
|
@ -19,7 +18,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
|||
$this->configMock = $this->mockConfig();
|
||||
$this->fileDaoMock = $this->mock(PublicFileDao::class);
|
||||
$this->thumbnailServiceMock = $this->mock(ThumbnailService::class);
|
||||
$this->thumbnailGeneratorMock = $this->mock(SmartThumbnailGenerator::class);
|
||||
$this->thumbnailGeneratorMock = $this->mock(ThumbnailGenerator::class);
|
||||
}
|
||||
|
||||
public function testGetUsedThumbnailSizes()
|
||||
|
@ -100,7 +99,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
|||
'content of file',
|
||||
100,
|
||||
100,
|
||||
IThumbnailGenerator::CROP_OUTSIDE)
|
||||
ThumbnailGenerator::CROP_OUTSIDE)
|
||||
->willReturn(null);
|
||||
|
||||
$this->fileDaoMock
|
||||
|
@ -130,7 +129,7 @@ final class ThumbnailServiceTest extends AbstractTestCase
|
|||
'content of file',
|
||||
100,
|
||||
100,
|
||||
IThumbnailGenerator::CROP_OUTSIDE)
|
||||
ThumbnailGenerator::CROP_OUTSIDE)
|
||||
->willReturn('content of thumbnail');
|
||||
|
||||
$this->fileDaoMock
|
||||
|
|
Loading…
Reference in a new issue