Download the PHP package popphp/pop-image without Composer
On this page you can find all versions of the php package popphp/pop-image. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download popphp/pop-image
More information about popphp/pop-image
Files in popphp/pop-image
Package pop-image
Short Description PHP Image library for generating, editing and effecting images. A component of the Pop PHP Framework
License BSD-3-Clause
Homepage http://github.com/popphp/pop-image
Informations about the package pop-image
pop-image
- Overview
- Install
- Quickstart
- Load an Image
- Create an Image
- Convert an Image
- Output an Image
- Destroy an Image
- Image Adapters
- GD
- Imagick
- Advanced Editing
- CAPTCHA
Overview
pop-image
is a powerful and robust image processing component that's simple to use.
It supports the GD and Imagick extensions. The API is similar to the more
popular image editing application on the market, with calls to editing objects
that can be extended with additional image processing functionality if needed.
pop-image
is a component of the Pop PHP Framework.
Top
Install
Install pop-image
using Composer.
composer require popphp/pop-image
Or, require it in your composer.json file
"require": {
"popphp/pop-image" : "^4.0.0"
}
Top
Quickstart
Resizing an image
Crop the image
Crop the image to a square thumbnail
Top
Load an Image
There are a couple of ways to load an image into an image adapter:
Load from a file on disk:
Load from a stream of content:
Top
Create an Image
There are a couple of ways to create a new image and load it into an image adapter:
Create an RGB-based image
Create an index-based image
Top
Convert an Image
You can simply convert an image to another format by calling the convert()
method:
NOTE: the GD adapter is limited to JPG, PNG and GIF formats. The Imagick adapter can work with
a large number of formats, depending on your environment. The Imagick section in the phpinfo()
result screen will display the list of formats available for Imagick in your environment.
Top
Output an Image
Once you have an image adapter and have finished editing the image, you have two options to output the image.
Save to disk
Use the writeToFile()
method and pass it a filename and an optional image quality parameter:
Output to HTTP
Use the outputToHttp()
method to send the image content directly an HTTP client like a browser:
This method has several optional parameters to assist with the delivery over HTTP:
$quality
- set the quality of the image output$to
- give it a filename for a potential download$download
- boolean to set theContent-Disposition
to inline (false
) or attachment (true
)$sendHeaders
- boolean to send the headers or just the raw payload$headers
- array of additional headers to send
Top
Destroy an Image
Destroying an image will clear the image contents from memory to assist with memory management and prevent possibly exceeding any memory limits when working with a large number of files.
If you wish to clear the current image file from disk, you can pass a true
boolean to the method:
Top
Image Adapters
The two image adapters available are GD and Imagick and they share a basic core API:
load(?string $name = null)
loadFromString(string $data, ?string $name = null)
create(?int $width = null, ?int $height = null, ?string $name = null)
createIndex(?int $width = null, ?int $height = null, ?string $name = null)
resizeToWidth(int $w)
resizeToHeight(int $h)
resize(int $px)
scale(float $scale)
crop(int $w, int $h, int $x = 0, int $y = 0)
cropThumb(int $px, ?int $offset = null)
rotate(int $degrees, ?Color\ColorInterface $bgColor = null, int $alpha = null)
flip()
flop()
Top
GD
To work with the GD adapter, you can load it from the main image class in a few different ways:
Top
Imagick
To work with the Imagick adapter, you can load it from the main image class in a few different ways:
The Imagick adapter API extends the functionality with additional Imagick-specific methods:
addImage(mixed $image, ?int $delay = null)
hasImages()
getImages()
rebuildImages(\Imagick $images)
setResolution(int $x, ?int $y = null)
setImageColorspace(int $colorspace)
setCompression(int $compression)
setImageFilter(int $filter)
setImageBlur(float $blur)
getNumberOfImages()
getCompression()
getImageFilter()
getImageBlur()
Top
Advanced Editing
Using the editing objects
There are 6 available editing objects for advanced editing and adjusting of images:
- Adjust - Make image adjustments like brightness, contrast and desaturate.
- Draw - Draw basic shapes on the image and apply strokes and fills.
- Effect - Apply effects to the image, such as gradients.
- Filter - Apply filters to the image, such as blur, sharpen and negate.
- Layer - Create overlays and new layers over the image.
- Type - Add text over the image.
Examples
Here are some example use cases:
Top
CAPTCHA
The pop-image
component comes with a CAPTCHA tool to create a CAPTCHA image and store
the token value in session to validate the user's CAPTCHA input.
The script above will generate the following image:
And with it, the $_SESSION
variable will store a pop_captcha
key with a serialized
value in it. When you unserialized the $_SESSION['pop_captcha']
value, it will give you
this array:
You can use the captcha
value to display the image in an HTML page and the answer
value
to validate the user's CAPTCHA input.
Top