Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ public function polygon(array $points, $color, $filled = false);

/**
* Flips the image.
*
*
* @param int $flipVertical
* @param int $flipHorizontal
*
*
* @return $this
*/
public function flip($flipVertical, $flipHorizontal);
Expand Down
20 changes: 20 additions & 0 deletions Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,18 @@ public function init()
$this->getAdapter()->init();
}

/**
* Determine if image is unchanged / no operations to be performed.
*
* @param int $quality
*
* @return bool
*/
protected function isUnchanged($quality)
{
return empty($this->operations) && $quality == 100;
}

/**
* Save the file to a given output.
*/
Expand Down Expand Up @@ -647,6 +659,14 @@ public function save($file, $type = 'guess', $quality = 80)

try {
$this->init();

// If the source is a file and it's unchanged just copy it.
if ($this->source instanceof \Gregwar\Image\Source\File && $this->isUnchanged($quality)) {
copy($this->source->getFile(), $file);

return $file;
}

$this->applyOperations();

$success = false;
Expand Down
7 changes: 7 additions & 0 deletions tests/ImageTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ public function testNoCache()
$this->assertNotSame($monalisa, $image->guess());
}

public function testImageIsUnchangedWithNoOperations()
{
$imageFile = __DIR__.'/files/monalisa.jpg';
$image = $this->open('monalisa.jpg');
$this->assertSame(md5_file($imageFile), md5_file($image->guess(100)));
}

public function testActualCache()
{
$output = $this->open('monalisa.jpg')
Expand Down