Skip to content

Commit

Permalink
Check if preview path is writeable (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerrennkadse committed Jun 16, 2018
1 parent 6f7ca17 commit 167325c
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

namespace App\Controller;

use App\Kernel;
use App\Services\TweetService;
use Psr\Log\LoggerInterface;
use Smalot\Github\Webhook\Webhook;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -23,13 +22,19 @@ class IndexController extends Controller
*/
private $tweetService;

/**
* @var \Psr\Log\LoggerInterface
*/
private $logger;

/**
* IndexController constructor.
* @param TweetService $tweetService
*/
public function __construct(TweetService $tweetService)
public function __construct(TweetService $tweetService, LoggerInterface $logger)
{
$this->tweetService = $tweetService;
$this->logger = $logger;
}

/**
Expand Down Expand Up @@ -147,15 +152,23 @@ public function update(Request $request)

private function resizeImage(SplFileInfo $file, $destinationName)
{
$imagick = new \Imagick($file->getRealPath());
try {
$imagick = new \Imagick($file->getRealPath());

$imagick->resizeImage(453,640, 0, 1, true);
$imagick->resizeImage(453,640, 0, 1, true);

$imageWidth = $imagick->getImageWidth();
if($imagick->getImageHeight() > $imageWidth * 1.5) {
$imagick->cropImage($imageWidth,$imageWidth * 1.5,0,0);
$imageWidth = $imagick->getImageWidth();
if($imagick->getImageHeight() > $imageWidth * 1.5) {
$imagick->cropImage($imageWidth,$imageWidth * 1.5,0,0);
}

if(is_writable(dirname($destinationName))) {
return $imagick->writeImage($destinationName);
}
} catch (\ImagickException $e) {
$this->logger->error($e->getMessage(), [$file, $destinationName]);
}

return $imagick->writeImage($destinationName);
return false;
}
}

0 comments on commit 167325c

Please sign in to comment.