GdThumb::rotateImageNDegrees PHP Method

rotateImageNDegrees() public method

Rotates image specified number of degrees
public rotateImageNDegrees ( integer $degrees ) : GdThumb
$degrees integer
return GdThumb
    public function rotateImageNDegrees($degrees)
    {
        if (!is_numeric($degrees)) {
            throw new InvalidArgumentException('$degrees must be numeric');
        }
        if (!function_exists('imagerotate')) {
            throw new RuntimeException('Your version of GD does not support image rotation.');
        }
        $this->workingImage = imagerotate($this->oldImage, $degrees, 0);
        $newWidth = $this->currentDimensions['height'];
        $newHeight = $this->currentDimensions['width'];
        $this->oldImage = $this->workingImage;
        $this->currentDimensions['width'] = $newWidth;
        $this->currentDimensions['height'] = $newHeight;
        return $this;
    }

Usage Example

Ejemplo n.º 1
0
 public function rotateJpg(&$that)
 {
     $this->parentInstance = $that;
     // Test if exif is installed
     if (!is_callable('exif_read_data')) {
         return $that;
     }
     // Exif couldn't do it's thing.  Suppressing errors on it cause it
     // does a non-exception error if it can't read the image.
     $exif = @exif_read_data($this->parentInstance->getFilename());
     // There is no orientation data, so exit
     if (empty($exif['Orientation'])) {
         return $that;
     }
     // Act on orientation info
     switch ($exif['Orientation']) {
         case 1:
             // nothing
             break;
         case 2:
             //code here
             break;
         case 3:
             // 180 rotate left
             $this->parentInstance->rotateImageNDegrees(180);
             break;
         case 4:
             // vertical flip
             //
             break;
         case 5:
             // vertical flip + 90 rotate right
             //
             break;
         case 6:
             // 90 rotate right
             $this->parentInstance->rotateImageNDegrees(-90);
             break;
         case 7:
             // horizontal flip + 90 rotate right
             //
             break;
         case 8:
             // 90 rotate left
             $this->parentInstance->rotateImageNDegrees(90);
             break;
     }
     return $that;
 }
All Usage Examples Of GdThumb::rotateImageNDegrees