示例#1
0
 /**
  * Rotates the specified image by the specified angles and returns a new
  * object of the same type holding the rotated image.
  *
  * @param \Fine47\ImageMan\Prototype $image to rotate
  * @param int $angles value for rotation
  * @return \Fine47\ImageMan\Prototype rotated image
  */
 public static function rotate(ImageMan\Prototype $image, $angles = 90)
 {
     // Get the transparent color of the attached image.
     $color = $image->getTransparentColor();
     // Ensure that we have a fill color.
     Assert::that(['condition' => $color, 'message' => 'Unable to allocate a fill color for rotation', 'type' => Error::TYPE_IMAGE]);
     // Rotate the image and use transparent color as filler (when available).
     $rotated = Util\Image::getInfo(imagerotate($image->getResource(), $color, $image->supportsTransparency() ? 0 : 1));
     // Ensure that we have a new image.
     Assert::that(['condition' => $rotated, 'message' => 'Unable to rotate the image by [%d] degrees', 'args' => [$angles], 'type' => Error::TYPE_IMAGE]);
     // Return as a new instance of the same image type.
     return self::fromResource($image, $rotated);
 }
示例#2
0
 public static function fromResource($resource)
 {
     $info = Util\Image::getInfo($resource);
     Assert::that(['condition' => is_array($info), 'message' => 'The passed argument is not a resource', 'type' => Error::TYPE_ARGUMENT, 'magic' => 0xab4d]);
     return new self($info['image'], $info['width'], $info['height']);
 }