From 6ee426241a45f3d3d078af16df01073b8f509d25 Mon Sep 17 00:00:00 2001 From: Spyros Kalaitzis Date: Sat, 8 Apr 2017 00:44:44 +0300 Subject: [PATCH 1/6] Use copy() & unlink() instead of rename() (#18) Using `copy()` & `unlink()` instead of `rename()` as the latter will produce warnings and `GlideConversion` will throw an `ErrorException` if it is used across different volumes/disks. See Changelog notes in http://php.net/manual/en/function.rename.php --- src/GlideConversion.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/GlideConversion.php b/src/GlideConversion.php index ad395044..5d732820 100644 --- a/src/GlideConversion.php +++ b/src/GlideConversion.php @@ -98,7 +98,8 @@ public function save(string $outputFile) $conversionResultDirectory = pathinfo($this->conversionResult, PATHINFO_DIRNAME); - rename($this->conversionResult, $outputFile); + copy($this->conversionResult, $outputFile); + unlink($this->conversionResult); if ($this->directoryIsEmpty($conversionResultDirectory)) { rmdir($conversionResultDirectory); From bfd578d3051007f6b55f69734c1bfa6325d42024 Mon Sep 17 00:00:00 2001 From: freek Date: Sat, 8 Apr 2017 00:12:26 +0200 Subject: [PATCH 2/6] edit readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aac152d7..38d21307 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it mak Our address is: Spatie, Samberstraat 69D, 2060 Antwerp, Belgium. -The best postcards will get published on the open source page on our website. +All postcards are published [on our website](https://spatie.be/en/opensource/postcards). ## Installation From 057a8874a28ff6e6197f6cc254c6b049f3032cea Mon Sep 17 00:00:00 2001 From: freek Date: Sat, 8 Apr 2017 00:15:42 +0200 Subject: [PATCH 3/6] edit changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04d5115f..4f25e170 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `image` will be documented in this file +## 1.1.3 - 2017-04-07 + +- improve support for multi-volume systems + ## 1.1.2 - 2017-04-04 - remove conversion directory after converting image From 370f08c5f4554f6ce4843b9abbdf0dc02efa6184 Mon Sep 17 00:00:00 2001 From: Eric Lagarda Date: Mon, 17 Apr 2017 10:16:32 +0200 Subject: [PATCH 4/6] Update Manipulations.php to let manipulations arrays also (#16) * Update Manipulations.php to let manipulations arrays also WIth this fix you can send a normal manipulation: ```php $media->manipulations = [ 'resized' =>['width' => 123, 'height' => 123], ]; ``` And also this kind of manipulations: ```php $resizedConversion = Manipulations::create() ->width(123) ->apply() ->manualCrop(20, 20, 10, 10); $media->manipulations = [ 'resized' => $resizedConversion->toArray() ]; ``` * Manipulations code clean - Updated tests * Return array type * Fix tests --- src/Manipulations.php | 42 +++++++++++++++++++++++++- tests/ManipulationsTest.php | 59 +++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 1 deletion(-) diff --git a/src/Manipulations.php b/src/Manipulations.php index 5a15b85b..03d3ee55 100644 --- a/src/Manipulations.php +++ b/src/Manipulations.php @@ -59,7 +59,13 @@ class Manipulations public function __construct(array $manipulations = []) { - $this->manipulationSequence = new ManipulationSequence($manipulations); + if (! $this->hasMultipleConversions($manipulations)) { + $manipulations = [$manipulations]; + } + + foreach ($manipulations as $manipulation) { + $this->manipulationSequence = new ManipulationSequence($manipulation); + } } /** @@ -555,6 +561,40 @@ public function apply() return $this; } + /** + * Create new manipulations class. + * + * @param array $manipulations + * + * @return self + */ + public static function create(array $manipulations = []) + { + return new self($manipulations); + } + + public function toArray() : array + { + return $this->manipulationSequence->toArray(); + } + + /** + * Checks if the given manipulations has arrays inside or not. + * + * @param array $manipulations + * + * @return bool + */ + private function hasMultipleConversions(array $manipulations) : bool + { + foreach ($manipulations as $manipulation) { + if (isset($manipulation[0]) && is_array($manipulation[0])) { + return true; + } + } + return false; + } + public function removeManipulation(string $name) { $this->manipulationSequence->removeManipulation($name); diff --git a/tests/ManipulationsTest.php b/tests/ManipulationsTest.php index 2a633dff..0e55d2c1 100644 --- a/tests/ManipulationsTest.php +++ b/tests/ManipulationsTest.php @@ -43,6 +43,65 @@ public function it_can_be_constructed_with_a_sequence_array() $this->assertEquals($sequenceArray, $manipulations->getManipulationSequence()->toArray()); } + /** @test */ + public function it_can_be_constructed_with_a_single_sequence() + { + $sequenceArray = [ + [ + 'filter' => 'greyscale', + 'width' => 50, + ], + ]; + + $manipulations = (new Manipulations($sequenceArray)); + + $this->assertEquals($sequenceArray, $manipulations->getManipulationSequence()->toArray()); + } + + /** @test */ + public function it_can_return_an_array_of_manipulations() + { + $sequenceArray = [ + ['width' => '123'], + ['manualCrop' => '20,10,10,10'], + ]; + + $manipulations = Manipulations::create() + ->width(123) + ->apply() + ->manualCrop(20, 10, 10, 10); + + $this->assertEquals($sequenceArray, $manipulations->toArray()); + } + + /** @test */ + public function it_can_create_from_sequence_array() + { + $sequenceArray = [ + ['width' => '123'], + ['manualCrop' => '20,10,10,10'], + ]; + + $manipulations = Manipulations::create($sequenceArray); + + $this->assertEquals($sequenceArray, $manipulations->toArray()); + } + + /** @test */ + public function it_can_create_from_single_sequence() + { + $sequence = [ + [ + 'manualCrop' => '20,10,10,10', + 'width' => '123', + ] + ]; + + $manipulations = Manipulations::create($sequence); + + $this->assertEquals($sequence, $manipulations->toArray()); + } + /** @test */ public function it_can_merge_itself_with_another_instance() { From 9c71c6ebf564699b24e069ce8193d71b902063e5 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Mon, 17 Apr 2017 10:17:49 +0200 Subject: [PATCH 5/6] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f25e170..720b3fa2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to `image` will be documented in this file +## 1.2.0 - 2017-04-17 + +- allow `Manipulations` to be constructed with an array of arrays + ## 1.1.3 - 2017-04-07 - improve support for multi-volume systems From 526374fade44ae494a5286554afa30e6d8121b8a Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Mon, 17 Apr 2017 10:18:27 +0200 Subject: [PATCH 6/6] Apply fixes from StyleCI (#19) --- src/Manipulations.php | 1 + tests/ManipulationsTest.php | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Manipulations.php b/src/Manipulations.php index 03d3ee55..07fe9e1e 100644 --- a/src/Manipulations.php +++ b/src/Manipulations.php @@ -592,6 +592,7 @@ private function hasMultipleConversions(array $manipulations) : bool return true; } } + return false; } diff --git a/tests/ManipulationsTest.php b/tests/ManipulationsTest.php index 0e55d2c1..1db85703 100644 --- a/tests/ManipulationsTest.php +++ b/tests/ManipulationsTest.php @@ -81,7 +81,7 @@ public function it_can_create_from_sequence_array() ['width' => '123'], ['manualCrop' => '20,10,10,10'], ]; - + $manipulations = Manipulations::create($sequenceArray); $this->assertEquals($sequenceArray, $manipulations->toArray()); @@ -94,7 +94,7 @@ public function it_can_create_from_single_sequence() [ 'manualCrop' => '20,10,10,10', 'width' => '123', - ] + ], ]; $manipulations = Manipulations::create($sequence);