diff --git a/app/Jobs/ProcessPosterImage.php b/app/Jobs/ProcessPosterImage.php index 742c4d9..e82ea46 100644 --- a/app/Jobs/ProcessPosterImage.php +++ b/app/Jobs/ProcessPosterImage.php @@ -3,7 +3,9 @@ namespace App\Jobs; use Illuminate\Bus\Queueable; +use Intervention\Image\Facades\Image; use Illuminate\Queue\SerializesModels; +use Illuminate\Support\Facades\Storage; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; @@ -21,6 +23,9 @@ class ProcessPosterImage implements ShouldQueue public function handle() { - // + $imageContents = Storage::disk('public')->get($this->concert->poster_image_path); + $image = Image::make($imageContents); + $image->resize(600)->encode(); + Storage::disk('public')->put($this->concert->poster_image_path, (string) $image); } } diff --git a/composer.json b/composer.json index ce1667e..e319fd1 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "stripe/stripe-php": "^4.3", "guzzlehttp/guzzle": "^6.2", "hashids/hashids": "^2.0", - "laravel/dusk": "^1.1" + "laravel/dusk": "^1.1", + "intervention/image": "^2.4" }, "require-dev": { "fzaninotto/faker": "~1.4", diff --git a/composer.lock b/composer.lock index 156f60a..95f16ee 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "a503f9147c24fb95300877d6d2f3f0bc", + "content-hash": "02c9d4c5e1e6a691a3b64c3a732aee1d", "packages": [ { "name": "doctrine/inflector", @@ -522,6 +522,76 @@ ], "time": "2017-01-01T13:33:33+00:00" }, + { + "name": "intervention/image", + "version": "2.4.1", + "source": { + "type": "git", + "url": "https://github.com/Intervention/image.git", + "reference": "3603dbcc9a17d307533473246a6c58c31cf17919" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Intervention/image/zipball/3603dbcc9a17d307533473246a6c58c31cf17919", + "reference": "3603dbcc9a17d307533473246a6c58c31cf17919", + "shasum": "" + }, + "require": { + "ext-fileinfo": "*", + "guzzlehttp/psr7": "~1.1", + "php": ">=5.4.0" + }, + "require-dev": { + "mockery/mockery": "~0.9.2", + "phpunit/phpunit": "^4.8 || ^5.7" + }, + "suggest": { + "ext-gd": "to use GD library based image processing.", + "ext-imagick": "to use Imagick based image processing.", + "intervention/imagecache": "Caching extension for the Intervention Image library" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3-dev" + }, + "laravel": { + "providers": [ + "Intervention\\Image\\ImageServiceProvider" + ], + "aliases": { + "Image": "Intervention\\Image\\Facades\\Image" + } + } + }, + "autoload": { + "psr-4": { + "Intervention\\Image\\": "src/Intervention/Image" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Oliver Vogel", + "email": "oliver@olivervogel.com", + "homepage": "http://olivervogel.com/" + } + ], + "description": "Image handling and manipulation library with support for Laravel integration", + "homepage": "http://image.intervention.io/", + "keywords": [ + "gd", + "image", + "imagick", + "laravel", + "thumbnail", + "watermark" + ], + "time": "2017-09-21T16:29:17+00:00" + }, { "name": "laravel/dusk", "version": "v1.1.0", diff --git a/tests/Unit/Jobs/ProcessPosterImageTest.php b/tests/Unit/Jobs/ProcessPosterImageTest.php new file mode 100644 index 0000000..ddeb38f --- /dev/null +++ b/tests/Unit/Jobs/ProcessPosterImageTest.php @@ -0,0 +1,33 @@ +put( + 'posters/example-poster.png', + file_get_contents(base_path('tests/__fixtures__/full-size-poster.png')) + ); + $concert = \ConcertFactory::createUnpublished([ + 'poster_image_path' => 'posters/example-poster.png', + ]); + + ProcessPosterImage::dispatch($concert); + + $resizedImage = Storage::disk('public')->get('posters/example-poster.png'); + list($width) = getimagesizefromstring($resizedImage); + $this->assertEquals(600, $width); + + } +} diff --git a/tests/__fixtures__/full-size-poster.png b/tests/__fixtures__/full-size-poster.png new file mode 100644 index 0000000..6d22e1c Binary files /dev/null and b/tests/__fixtures__/full-size-poster.png differ