GdThumb::resize PHP Méthode

resize() public méthode

If either param is set to zero, then that dimension will not be considered as a part of the resize. Additionally, if $this->options['resizeUp'] is set to true (false by default), then this function will also scale the image up to the maximum dimensions provided.
public resize ( integer $maxWidth, integer $maxHeight ) : GdThumb
$maxWidth integer The maximum width of the image in pixels
$maxHeight integer The maximum height of the image in pixels
Résultat GdThumb
    public function resize($maxWidth = 0, $maxHeight = 0)
    {
        // make sure our arguments are valid
        if (!is_numeric($maxWidth)) {
            throw new InvalidArgumentException('$maxWidth must be numeric');
        }
        if (!is_numeric($maxHeight)) {
            throw new InvalidArgumentException('$maxHeight must be numeric');
        }
        // make sure we're not exceeding our image size if we're not supposed to
        if ($this->options['resizeUp'] === false) {
            $this->maxHeight = intval($maxHeight) > $this->currentDimensions['height'] ? $this->currentDimensions['height'] : $maxHeight;
            $this->maxWidth = intval($maxWidth) > $this->currentDimensions['width'] ? $this->currentDimensions['width'] : $maxWidth;
        } else {
            $this->maxHeight = intval($maxHeight);
            $this->maxWidth = intval($maxWidth);
        }
        // get the new dimensions...
        $this->calcImageSize($this->currentDimensions['width'], $this->currentDimensions['height']);
        // create the working image
        if (function_exists('imagecreatetruecolor')) {
            $this->workingImage = imagecreatetruecolor($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
        } else {
            $this->workingImage = imagecreate($this->newDimensions['newWidth'], $this->newDimensions['newHeight']);
        }
        $this->preserveAlpha();
        // and create the newly sized image
        imagecopyresampled($this->workingImage, $this->oldImage, 0, 0, 0, 0, $this->newDimensions['newWidth'], $this->newDimensions['newHeight'], $this->currentDimensions['width'], $this->currentDimensions['height']);
        // update all the variables and resources to be correct
        $this->oldImage = $this->workingImage;
        $this->currentDimensions['width'] = $this->newDimensions['newWidth'];
        $this->currentDimensions['height'] = $this->newDimensions['newHeight'];
        return $this;
    }

Usage Example

Exemple #1
0
 /**
  * Pad an image to desired dimensions. Moves the image into the center and fills the rest with given color.
  *
  * @param integer $width
  * @param integer $height
  * @param array $options
  * @return $this
  */
 public function pad($width, $height, $options)
 {
     if (!$height || !$width) {
         throw new Exception('Croppa: Pad option needs width and height');
     }
     $color = $options['pad'] ?: [255, 255, 255];
     $this->thumb->resize($width, $height)->pad($width, $height, $color);
     return $this;
 }
All Usage Examples Of GdThumb::resize