Skip to content

Commit

Permalink
Merge pull request #951 from rez1dent3/master
Browse files Browse the repository at this point in the history
added the $format parameter to the save method
  • Loading branch information
olivervogel committed Jun 24, 2019
2 parents 5f5e1c8 + dcae042 commit 39eaef7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Intervention/Image/Image.php
Expand Up @@ -126,9 +126,10 @@ public function encode($format = null, $quality = 90)
*
* @param string $path
* @param int $quality
* @param string $format
* @return \Intervention\Image\Image
*/
public function save($path = null, $quality = null)
public function save($path = null, $quality = null, $format = null)
{
$path = is_null($path) ? $this->basePath() : $path;

Expand All @@ -138,7 +139,11 @@ public function save($path = null, $quality = null)
);
}

$data = $this->encode(pathinfo($path, PATHINFO_EXTENSION), $quality);
if ($format === null) {
$format = pathinfo($path, PATHINFO_EXTENSION);
}

$data = $this->encode($format, $quality);
$saved = @file_put_contents($path, $data);

if ($saved === false) {
Expand Down
20 changes: 20 additions & 0 deletions tests/ImageTest.php
@@ -1,6 +1,7 @@
<?php

use Intervention\Image\Image;
use Intervention\Image\ImageManager;
use PHPUnit\Framework\TestCase;

class ImageTest extends TestCase
Expand Down Expand Up @@ -44,6 +45,25 @@ public function testSave()
@unlink($save_as);
}

public function testFormatSave()
{
$save_as = __DIR__.'/tmp/test';

$config = ['driver' => new Intervention\Image\Imagick\Driver()];
$manager = new ImageManager($config);

$image = $manager->make('data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7');
$this->assertInstanceOf('Intervention\Image\Image', $image);
$this->assertInstanceOf('Imagick', $image->getCore());

$gifCore = $image->getCore();
$this->assertEquals($gifCore->getImageMimeType(), 'image/gif');
$image->save($save_as, null, 'jpg');

$this->assertEquals(\mime_content_type($save_as), 'image/jpeg');
@unlink($save_as);
}

public function testIsEncoded()
{
$image = $this->getTestImage();
Expand Down

0 comments on commit 39eaef7

Please sign in to comment.