Skip to content

Commit

Permalink
1.2.0
Browse files Browse the repository at this point in the history
* [+] метод `GDImageInfo::setFilename()`
* [+] метод `GDImageInfo::getWH()`
* [+] метод `GDImageInfo::getError()`
* [*] BMP всегда сохраняется с RLE-сжатием
  • Loading branch information
KarelWintersky committed May 28, 2022
1 parent 946d7f2 commit faae511
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
45 changes: 40 additions & 5 deletions sources/GDImageInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ class GDImageInfo implements GDImageInfoInterface
*/
public $filename;

/**
* @var string
*/
public $extension = '';



/**
* Целевая степень сжатия
* @var int|null
Expand Down Expand Up @@ -200,19 +201,22 @@ public function setCompressionQuality($image_quality = null):GDImageInfo
}

/**
* Сохраняет файл (все-таки удобнее иметь quality аргументом)
* Сохраняет файл.
* Если quality не передан - используется quality из параметров класса
* BMP всегда сохраняются с RLE-сжатием
* PNG всегда сохраняются с ZLib compression default
*/
public function store($quality = null): GDImageInfo
{
$target_extension = $this->extension;

switch ($target_extension) {
case 'bmp': {
$this->valid = imagebmp($this->data, $this->filename, (bool)$quality);
$this->valid = imagebmp($this->data, $this->filename, true);
break;
}
case 'png': {
$this->quality = $q = 100;
// $this->quality = $q = 100;
// quality setting not used for PNG
// $this->quality = is_null($quality) ? $this->quality : $quality;
// $q = round((100-$this->quality)/10, 0, PHP_ROUND_HALF_DOWN);
Expand Down Expand Up @@ -246,6 +250,16 @@ public function store($quality = null): GDImageInfo
return $this;
}

/**
* @param string $filename
* @return GDImageInfo
*/
public function setFilename(string $filename): GDImageInfo
{
$this->filename = $filename;
return $this;
}

public function changeExtension($target_extension):GDImageInfo
{
$info = pathinfo($this->filename);
Expand All @@ -257,4 +271,25 @@ public function changeExtension($target_extension):GDImageInfo
return $this;
}

/**
* @param string $format
* @return string
*/
public function getWH(string $format = "%sx%s"):string
{
if (empty($format)) {
return '';
}

return sprintf($format, $this->width, $this->height);
}

/**
* @return string
*/
public function getError():string
{
return $this->error_message;
}

}
4 changes: 4 additions & 0 deletions sources/GDImageInfoInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ public function setCompressionQuality($image_quality = null):GDImageInfo;
public function store($quality = null): GDImageInfo;

public function changeExtension($target_extension):GDImageInfo;
public function setFilename(string $filename): GDImageInfo;

public function getWH(string $format = "%sx%s"):string;
public function getError():string;
}

# -eof-

0 comments on commit faae511

Please sign in to comment.