Exemplo n.º 1
0
 /**
  * @param \PHPThumb\GD $phpthumb
  * @return \PHPThumb\GD
  */
 public function execute($phpthumb)
 {
     $currentImage = $phpthumb->getOldImage();
     $currentDimensions = $phpthumb->getCurrentDimensions();
     $borderTop = 0;
     $borderBottom = 0;
     $borderLeft = 0;
     $borderRight = 0;
     if (in_array('T', $this->sides)) {
         for (; $borderTop < $currentDimensions['height']; ++$borderTop) {
             for ($x = 0; $x < $currentDimensions['width']; ++$x) {
                 if (imagecolorat($currentImage, $x, $borderTop) != $this->rgb2int($this->color)) {
                     break 2;
                 }
             }
         }
     }
     if (in_array('B', $this->sides)) {
         for (; $borderBottom < $currentDimensions['height']; ++$borderBottom) {
             for ($x = 0; $x < $currentDimensions['width']; ++$x) {
                 if (imagecolorat($currentImage, $x, $currentDimensions['height'] - $borderBottom - 1) != $this->rgb2int($this->color)) {
                     break 2;
                 }
             }
         }
     }
     if (in_array('L', $this->sides)) {
         for (; $borderLeft < $currentDimensions['width']; ++$borderLeft) {
             for ($y = 0; $y < $currentDimensions['height']; ++$y) {
                 if (imagecolorat($currentImage, $borderLeft, $y) != $this->rgb2int($this->color)) {
                     break 2;
                 }
             }
         }
     }
     if (in_array('R', $this->sides)) {
         for (; $borderRight < $currentDimensions['width']; ++$borderRight) {
             for ($y = 0; $y < $currentDimensions['height']; ++$y) {
                 if (imagecolorat($currentImage, $currentDimensions['width'] - $borderRight - 1, $y) != $this->rgb2int($this->color)) {
                     break 2;
                 }
             }
         }
     }
     $newWidth = $currentDimensions['width'] - ($borderLeft + $borderRight);
     $newHeight = $currentDimensions['height'] - ($borderTop + $borderBottom);
     $newImage = imagecreatetruecolor($newWidth, $newHeight);
     imagecopy($newImage, $currentImage, 0, 0, $borderLeft, $borderTop, $currentDimensions['width'], $currentDimensions['height']);
     $phpthumb->setOldImage($newImage);
     $phpthumb->setCurrentDimensions(array('width' => $newWidth, 'height' => $newHeight));
     return $phpthumb;
 }