Added script for generating thumbnails
This commit is contained in:
parent
a2fefc6560
commit
d49aef6e47
3 changed files with 55 additions and 10 deletions
22
scripts/thumbnails.php
Normal file
22
scripts/thumbnails.php
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
require_once(__DIR__
|
||||||
|
. DIRECTORY_SEPARATOR . '..'
|
||||||
|
. DIRECTORY_SEPARATOR . 'src'
|
||||||
|
. DIRECTORY_SEPARATOR . 'Bootstrap.php');
|
||||||
|
|
||||||
|
use Szurubooru\Injector;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
|
use Szurubooru\Dao\PostDao;
|
||||||
|
use Szurubooru\Services\PostThumbnailService;
|
||||||
|
|
||||||
|
$size = isset($argv[1]) ? $argv[1] : 160;
|
||||||
|
|
||||||
|
$postDao = Injector::get(PostDao::class);
|
||||||
|
$postThumbnailService = Injector::get(PostThumbnailService::class);
|
||||||
|
|
||||||
|
foreach ($postDao->findAll() as $post)
|
||||||
|
{
|
||||||
|
$thumbnailName = $postThumbnailService->generateIfNeeded($post, $size, $size);
|
||||||
|
echo '.';
|
||||||
|
}
|
||||||
|
echo PHP_EOL;
|
|
@ -6,7 +6,7 @@ use Szurubooru\Helpers\MimeHelper;
|
||||||
use Szurubooru\Router;
|
use Szurubooru\Router;
|
||||||
use Szurubooru\Services\NetworkingService;
|
use Szurubooru\Services\NetworkingService;
|
||||||
use Szurubooru\Services\PostService;
|
use Szurubooru\Services\PostService;
|
||||||
use Szurubooru\Services\ThumbnailService;
|
use Szurubooru\Services\PostThumbnailService;
|
||||||
|
|
||||||
final class PostContentController extends AbstractController
|
final class PostContentController extends AbstractController
|
||||||
{
|
{
|
||||||
|
@ -14,20 +14,20 @@ final class PostContentController extends AbstractController
|
||||||
private $fileDao;
|
private $fileDao;
|
||||||
private $postService;
|
private $postService;
|
||||||
private $networkingService;
|
private $networkingService;
|
||||||
private $thumbnailService;
|
private $postThumbnailService;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
Config $config,
|
Config $config,
|
||||||
PublicFileDao $fileDao,
|
PublicFileDao $fileDao,
|
||||||
PostService $postService,
|
PostService $postService,
|
||||||
NetworkingService $networkingService,
|
NetworkingService $networkingService,
|
||||||
ThumbnailService $thumbnailService)
|
PostThumbnailService $postThumbnailService)
|
||||||
{
|
{
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->fileDao = $fileDao;
|
$this->fileDao = $fileDao;
|
||||||
$this->postService = $postService;
|
$this->postService = $postService;
|
||||||
$this->networkingService = $networkingService;
|
$this->networkingService = $networkingService;
|
||||||
$this->thumbnailService = $thumbnailService;
|
$this->postThumbnailService = $postThumbnailService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerRoutes(Router $router)
|
public function registerRoutes(Router $router)
|
||||||
|
@ -52,12 +52,7 @@ final class PostContentController extends AbstractController
|
||||||
public function getPostThumbnail($postName, $size)
|
public function getPostThumbnail($postName, $size)
|
||||||
{
|
{
|
||||||
$post = $this->postService->getByName($postName);
|
$post = $this->postService->getByName($postName);
|
||||||
|
$thumbnailName = $this->postThumbnailService->generateIfNeeded($post, $size, $size);
|
||||||
$sourceName = $post->getThumbnailSourceContentPath();
|
|
||||||
if (!$this->fileDao->exists($sourceName))
|
|
||||||
$sourceName = $post->getContentPath();
|
|
||||||
|
|
||||||
$thumbnailName = $this->thumbnailService->generateIfNeeded($sourceName, $size, $size);
|
|
||||||
$this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName));
|
$this->networkingService->serveFile($this->fileDao->getFullPath($thumbnailName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
src/Services/PostThumbnailService.php
Normal file
28
src/Services/PostThumbnailService.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
namespace Szurubooru\Services;
|
||||||
|
use Szurubooru\Dao\PublicFileDao;
|
||||||
|
use Szurubooru\Entities\Post;
|
||||||
|
use Szurubooru\Services\ThumbnailService;
|
||||||
|
|
||||||
|
class PostThumbnailService
|
||||||
|
{
|
||||||
|
private $thumbnailService;
|
||||||
|
private $fileDao;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
PublicFileDao $fileDao,
|
||||||
|
ThumbnailService $thumbnailService)
|
||||||
|
{
|
||||||
|
$this->fileDao = $fileDao;
|
||||||
|
$this->thumbnailService = $thumbnailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function generateIfNeeded(Post $post, $width, $height)
|
||||||
|
{
|
||||||
|
$sourceName = $post->getThumbnailSourceContentPath();
|
||||||
|
if (!$this->fileDao->exists($sourceName))
|
||||||
|
$sourceName = $post->getContentPath();
|
||||||
|
|
||||||
|
return $this->thumbnailService->generateIfNeeded($sourceName, $width, $height);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue