Skip to content

Commit

Permalink
Check for animated webp
Browse files Browse the repository at this point in the history
  • Loading branch information
RikudouSage committed Feb 18, 2024
1 parent d97e08b commit 37d3a08
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 30 deletions.
20 changes: 8 additions & 12 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

try {
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
return function (array $context) {
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);

return new Application($kernel);
};
} catch (\Symfony\Component\ErrorHandler\Error\FatalError) {
// ignore that piece of crap
}
return new Application($kernel);
};
14 changes: 5 additions & 9 deletions bin/consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@
use Bref\Symfony\Messenger\Service\Sqs\SqsConsumer;
use Symfony\Component\Dotenv\Dotenv;

try {
require dirname(__DIR__).'/vendor/autoload.php';
require dirname(__DIR__).'/vendor/autoload.php';

(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');

$kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
$kernel->boot();
$kernel = new Kernel($_SERVER['APP_ENV'], (bool)$_SERVER['APP_DEBUG']);
$kernel->boot();

// Return the Bref consumer service
return $kernel->getContainer()->get(SqsConsumer::class);
} catch (\Symfony\Component\ErrorHandler\Error\FatalError) {
// ignore that piece of crap
}
return $kernel->getContainer()->get(SqsConsumer::class);
12 changes: 4 additions & 8 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

use App\Kernel;

try {
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
} catch (\Symfony\Component\ErrorHandler\Error\FatalError) {
// ignore that piece of crap
}
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};
17 changes: 16 additions & 1 deletion src/Service/ImageFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public function getImageHash(string $url): ?string
$contentType = $response->getHeaders(false)['content-type'][0] ?? '';
if (str_starts_with($contentType, 'image/')) {
try {
$image = @imagecreatefromstring($response->getContent());
if ($this->isAnimatedWebP($response->getContent())) {
$image = false;
} else {
$image = imagecreatefromstring($response->getContent());
}
} catch (Throwable) {
$image = false;
}
Expand All @@ -59,4 +63,15 @@ public function getImageHash(string $url): ?string

return $cacheItem->get();
}

private function isAnimatedWebP(string $fileData): bool
{
if (
stripos($fileData, 'WEBPVP8X') !== false ||
stripos($fileData, 'ANIM') !== false
) {
return true;
}
return false;
}
}

0 comments on commit 37d3a08

Please sign in to comment.