-
getFile() : void
-
getWidth() : void
-
getHeight() : void
-
getType() : void
-
getMime() : void
-
Loads an image and prepares it for manipulation.
-
Loads information about the image. Will throw an exception if the image does not exist or is not an image.
-
__toString() : stringRender the current image.
-
Add a reflection to an image. The most opaque part of the reflection will be equal to the opacity setting and fade out to full transparent.
-
Set the background color of an image. This is only useful for images with alpha transparency.
-
Save the image. If the filename is omitted, the original image will be overwritten.
-
Render the image and return the binary string.
-
Execute a resize.
-
Execute a crop.
-
Execute a rotation.
-
Execute a flip.
-
Execute a sharpen.
-
Execute a reflection.
-
Execute a watermarking.
-
Execute a background.
-
Execute a save.
-
Execute a render.
-
public function getFile()
-
public function getWidth()
-
public function getHeight()
-
public function getType()
-
public function getMime()
-
public static function factory(string $file, string $driver)
Loads an image and prepares it for manipulation.$image = new Image('upload/test.jpg');
-
public function __construct(string $file)
Loads information about the image. Will throw an exception if the image does not exist or is not an image. -
public function __toString()
Render the current image.echo $image;
-
public function resize(int $width, int $height, int $master)
Resize the image to the given size. Either the width or the height can be omitted and the image will be resized proportionally.// Resize to 200 pixels on the shortest side $image->resize(200, 200); // Resize to 200x200 pixels, keeping aspect ratio $image->resize(200, 200, Image::INVERSE); // Resize to 500 pixel width, keeping aspect ratio $image->resize(500, null); // Resize to 500 pixel height, keeping aspect ratio $image->resize(null, 500); // Resize to 200x500 pixels, ignoring aspect ratio $image->resize(200, 500, Image::NONE);
-
public function crop(int $width, int $height, variable $offsetX, variable $offsetY)
Crop an image to the given size. Either the width or the height can be omitted and the current width or height will be used.If no offset is specified, the center of the axis will be used. If an offset of true is specified, the bottom of the axis will be used.// Crop the image to 200x200 pixels, from the center $image->crop(200, 200);
-
public function rotate(int $degrees)
Rotate the image by a given amount.// Rotate 45 degrees clockwise $image->rotate(45); // Rotate 90% counter-clockwise $image->rotate(-90);
-
public function flip(int $direction)
Flip the image along the horizontal or vertical axis.// Flip the image from top to bottom $image->flip(Image::HORIZONTAL); // Flip the image from left to right $image->flip(Image::VERTICAL);
-
public function sharpen(int $amount)
Sharpen the image by a given amount.// Sharpen the image by 20% $image->sharpen(20);
-
public function reflection(int $height, int $opacity, bool $fadeIn)
Add a reflection to an image. The most opaque part of the reflection will be equal to the opacity setting and fade out to full transparent.Alpha transparency is preserved.
[!!] By default, the reflection will be go from transparent at the top to opaque at the bottom.// Create a 50 pixel reflection that fades from 0-100% opacity $image->reflection(50); // Create a 50 pixel reflection that fades from 100-0% opacity $image->reflection(50, 100, true); // Create a 50 pixel reflection that fades from 0-60% opacity $image->reflection(50, 60, true);
-
public function watermark(variable $watermark, int $offsetX, int $offsetY, int $opacity)
Add a watermark to an image with a specified opacity. Alpha transparency will be preserved.If no offset is specified, the center of the axis will be used. If an offset of true is specified, the bottom of the axis will be used.// Add a watermark to the bottom right of the image $mark = new Image('upload/watermark.png'); $image->watermark($mark, true, true);
-
public function background(string $color, int $opacity)
Set the background color of an image. This is only useful for images with alpha transparency.// Make the image background black $image->background('#000'); // Make the image background black with 50% opacity $image->background('#000', 50);
-
public function save(string $file, int $quality)
Save the image. If the filename is omitted, the original image will be overwritten.
[!!] If the file exists, but is not writable, an exception will be thrown. [!!] If the file does not exist, and the directory is not writable, an exception will be thrown.// Save the image as a PNG $image->save('saved/cool.png'); // Overwrite the original image $image->save();
-
public function render(string $type, int $quality)
Render the image and return the binary string.// Render the image at 50% quality $data = image->render(null, 50); // Render the image as a PNG $data = image->render('png');
-
abstract protected function doResize(int $width, int $height)
Execute a resize. -
abstract protected function doCrop(int $width, int $height, int $offset_x, int $offset_y)
Execute a crop. -
abstract protected function doRotate(int $degrees)
Execute a rotation. -
abstract protected function doFlip(int $direction)
Execute a flip. -
abstract protected function doSharpen(int $amount)
Execute a sharpen. -
abstract protected function doReflection(int $height, int $opacity, bool $fadeIn)
Execute a reflection. -
abstract protected function doWatermark(variable $image, int $offsetX, int $offsetY, int $opacity)
Execute a watermarking. -
abstract protected function doBackground(int $r, int $g, int $b, int $opacity)
Execute a background. -
abstract protected function doSave(string $file, int $quality)
Execute a save. -
abstract protected function doRender(string $type, int $quality)
Execute a render.