Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jun 29, 2017
2 parents d255f30 + 526374f commit 66f3b53
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 4 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

All notable changes to `image` will be documented in this file

## 1.1.2 - 2017-06-29
## 1.2.1 - 2017-06-29

- add methods to determine emptyness to `Manipulations` and `ManipuliationSequence`.

## 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

## 1.1.2 - 2017-04-04

- remove conversion directory after converting image
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/GlideConversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
43 changes: 42 additions & 1 deletion src/Manipulations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -555,6 +561,41 @@ 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);
Expand Down
59 changes: 59 additions & 0 deletions tests/ManipulationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 66f3b53

Please sign in to comment.