Skip to content

Commit

Permalink
updated parameters of save and show functions
Browse files Browse the repository at this point in the history
  • Loading branch information
antonlukin committed Nov 1, 2021
1 parent a201ea1 commit aaa476d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,17 @@ By default black canvas.
$image->show(string $format = null, int $quality = 90)
```
Sends HTTP response with current image in given format and quality.
Format is a file image extension. By default used type from `make` or `insert` function.
Format is a file image extension. By default the response data will be encoded in the type of the current image. If no image type is defined yet, method will return jpeg encoded data.
Quality is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file).
The default value is 90. PNG format is losless and the quality affects only image size and compression speed.

### save
```
$image->save(string $format = null, int $quality = 90)
$image->save(string $path, int $quality = 90, string $format = null)
```
Save the image. Optional format and quality params same as for `show` method.
Save the current state of the image object in filesystem. Define optionally a certain path where the image should be saved. The image type will be defined by file extension. If there is no extension available, the response data will be encoded in the type of the current image. If no image type is defined yet, method will return jpeg encoded data. Optionally you can override this with the format parameter.
Quality is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file).
The default value is 90. PNG format is losless and the quality affects only image size and compression speed.

### destroy
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "antonlukin/poster-editor",
"version": "5.3",
"version": "5.4",
"description": "Wrapper for PHP's GD Library for easy image manipulation",
"keywords": ["php", "image", "text", "gd"],
"homepage": "https://github.com/antonlukin/poster-editor",
Expand Down
2 changes: 1 addition & 1 deletion example/insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
)
);

$image->show(100);
$image->show();

} catch(Exception $e) {
echo $e->getMessage();
Expand Down
18 changes: 7 additions & 11 deletions src/PosterEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @package PosterEditor
* @author Anton Lukin <[email protected]>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @version Release: 5.3
* @version Release: 5.4
* @link https://github.com/antonlukin/poster-editor
*/
class PosterEditor
Expand Down Expand Up @@ -214,10 +214,6 @@ public function canvas($width, $height, $options = array())
*/
public function show($format = null, $quality = 90)
{
if (empty($format)) {
$format = pathinfo($path, PATHINFO_EXTENSION);
}

$this->setType($format);

$quality = $this->getParam($quality, 0, 100);
Expand Down Expand Up @@ -249,12 +245,12 @@ public function show($format = null, $quality = 90)
* Save the image.
*
* @param string $path Path to the file where to write the image data.
* @param string $format Optional. File image extension. By default use from path.
* @param integer $quality Optional. Define optionally the quality of the image. From 0 to 100. Default: 90.
* @param string $format Optional. File image extension. By default use from path.
*
* @return $this
*/
public function save($path, $format = null, $quality = 90)
public function save($path, $quality = 90, $format = null)
{
$folder = dirname($path);

Expand Down Expand Up @@ -1009,17 +1005,17 @@ protected function setType($format)
$this->type = IMAGETYPE_GIF;
break;

case 'jpg':
$this->type = IMAGETYPE_JPEG;
break;

case 'png':
$this->type = IMAGETYPE_PNG;
break;

case 'webp':
$this->type = IMAGETYPE_WEBP;
break;

case 'jpg':
$this->type = IMAGETYPE_JPEG;
break;
}
}

Expand Down

0 comments on commit aaa476d

Please sign in to comment.