コード例 #1
0
ファイル: Image.php プロジェクト: lawondyss/imager
 /**
  * Returns options part of command
  *
  * @param mixed $width
  * @param mixed $height
  * @param null|int $quality
  * @return string
  */
 private function getCommandOptions($width, $height, $quality)
 {
     $options = [];
     if (isset($width) && (int) $width === 0) {
         $width = $this->image->getWidth() . '!';
     }
     if (isset($height) && (int) $height === 0) {
         $height = $this->image->getHeight() . '!';
     }
     if (!isset($height)) {
         $options['resize'] = '"' . $width . '"';
     } elseif (!isset($width)) {
         $options['resize'] = '"x' . $height . '"';
     } else {
         $options['resize'] = '"' . Strings::trim($width, '!') . 'x' . Strings::trim($height, '!') . '^"';
     }
     if (isset($width) && isset($height)) {
         $options['gravity'] = 'center';
         $options['crop'] = '"' . $width . 'x' . $height . '+0+0"';
     }
     if (isset($quality) && $quality !== 0) {
         $options['quality'] = $quality;
     }
     $command = [];
     foreach ($options as $opt => $value) {
         $command[] = '-' . $opt . ' ' . $value;
     }
     return implode(' ', $command);
 }