Skip to content

Commit

Permalink
Set compression
Browse files Browse the repository at this point in the history
  • Loading branch information
notesz committed Nov 9, 2016
1 parent b8993e9 commit ced8080
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ Would you like to use retina sizes? Add this one: (It is optional)
$image->setRetina(true); //optional
```

Would you like to set compression? Add this one: (It is optional)

```php
$image->setCompression(75); //optional
```

If you don't want to save the original image you can disable it. Add this one: (It is optional)

```php
Expand Down
37 changes: 33 additions & 4 deletions src/ImageResize.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class ImageResize

const RETINA_POSTFIX = '@2x';

const COMPRESSION_QUALITY = 75;

/**
* Types of the image.
*
Expand All @@ -74,6 +76,8 @@ class ImageResize

private $progressive;

private $compression;

private $retina;

public function __construct()
Expand All @@ -96,6 +100,8 @@ public function __construct()

$this->progressive = true;

$this->compression = self::COMPRESSION_QUALITY;

$this->retina = false;
}

Expand Down Expand Up @@ -269,10 +275,10 @@ public function getSaveOriginal()
}

/**
* @param $progressive|bool
*
* @return bool
*/
* @param $progressive|bool
*
* @return bool
*/
public function setProgressive($progressive)
{
$this->progressive = $progressive;
Expand All @@ -288,6 +294,26 @@ public function getProgressive()
return $this->progressive;
}

/**
* @param $compression|int
*
* @return int
*/
public function setCompression($compression)
{
$this->compression = $compression;

return $this->compression;
}

/**
* @return int
*/
public function getCompression()
{
return $this->compression;
}

/**
* @param $retina|bool
*
Expand Down Expand Up @@ -430,6 +456,9 @@ public function resize()
$img->setInterlaceScheme(\Imagick::INTERLACE_PLANE);
}

// Set compression quality
$img->setCompressionQuality($this->compression);

// Save
$outFileName = (empty($this->prefix) ? '' : $this->prefix . self::SEPARATOR) . $fileName . self::SEPARATOR . $key . '.' . $fileNameExtension;
@\unlink($this->target . '/' . $outFileName);
Expand Down

0 comments on commit ced8080

Please sign in to comment.