Download the PHP package antonlukin/poster-editor without Composer
On this page you can find all versions of the php package antonlukin/poster-editor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download antonlukin/poster-editor
More information about antonlukin/poster-editor
Files in antonlukin/poster-editor
Package poster-editor
Short Description Wrapper for PHP's GD Library for easy image manipulation
License MIT
Homepage https://github.com/antonlukin/poster-editor
Informations about the package poster-editor
Poster Editor
This class is an alternative to the package Intervention Image for more flexible work with text on the image. Use it if you need to fit text in a given area, automatically calculate font size and change line height. The text drawing method also knows how to return the actual size of the inscriptions, which will allow, for example, to place blocks under each other.
In addition to flexible work with text, the class provides an Image API similar to the Intervention package. Including smart poster resizing, filters, drawing shapes, and overlaying other images.
If you are not using composer in your work, you may also be interested in the simplicity of the class and the absence of any dependencies. Note that this class supports PHP-GD driver only. You can also easily inherit your class — all methods of the parent can be overridden.
Installation
The best way to install Poster Editor is quickly and easily with Composer.
However, you can require the class directly without using a loader - this will not affect performance in any way.
php composer.phar require antonlukin/poster-editor
Usage
In case of an error, the class methods return an exception.
Therefore, it is best to call them inside a block try..catch
.
Example
Availible methods
get
Get image resource to use raw gd commands.
set
Set image resource after using raw gd commands.
make
Make new image instance from file or binary data.
insert
Paste a given image source over the current image with an optional position. First param can be binary data or path to file or another class instance. Options is an array of x/y relative offset coords from top left corner and opacity from 0 to 100, where 0 is no transparency. By default image will be centered.
canvas
Intialise the canvas by width and height. Background color options is in array of color/opacity settings. By default black canvas without opacity.
show
Sends HTTP response with current image in given format and quality. Format is a file image extension. By default the response data will be encoded in the type of the current image. If no image type is defined yet, method will return jpeg encoded data. Quality is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file). The default value is 90. PNG format is losless and the quality affects only image size and compression speed.
save
Save the current state of the image object in filesystem. Define optionally a certain path where the image should be saved. The image type will be defined by file extension. If there is no extension available, the response data will be encoded in the type of the current image. If no image type is defined yet, method will return jpeg encoded data. Optionally you can override this with the format parameter. Quality is normalized for all file types to a range from 0 (poor quality, small file) to 100 (best quality, big file). The default value is 90. PNG format is losless and the quality affects only image size and compression speed.
destroy
Frees memory associated with the current image instance before the PHP script ends. Normally resources are destroyed automatically after the script is finished.
width
Returns the height in pixels of the current image.
height
Returns the height in pixels of the current image.
resize
Resizes current image based on given width and height.
Does not pay attention to the aspect ratio. In order to resize proportionally, use upsize
and downsize
methods.
upsize
Upsize image on the largest side. Calculated by ratio for nulled width or height.
downsize
Downsize image on the largest side. Calculated by ratio for nulled width or height.
crop
Cut out a rectangular part of the current image with given width and height. Define optional x,y coordinates to move the top-left corner of the cutout to a certain position.
fit
Combine cropping and resizing to format image in a smart way.
The method will find the best fitting aspect ratio on the current image automatically,
cut it out and resize it to the given dimension.
Possible positions top-left
, top
, top-right
, bottom-left
, bottom
, bottom-right
, right
, left
and center
by default.
line
Draw a line from x,y point 1 to x,y point 2 on current image. Use options param to set color, opacity and width values.
rectangle
Draw a colored rectangle on current image. Use options param to set color, opacity, thickness and outline values.
ellipse
Draw an ellipse. Use options param to set color, opacity and outline values.
brightness
Change the brightness of the current image by the given level. Use values between -100 for min brightness 0 for no change and +100 for max.
contrast
Change the contrast of the current image by the given level. Use values between -100 for min contrast 0 for no change and +100 for max.
grayscale
Turn an image into a grayscale version.
blur
Apply a blur image effect.
invert
Invert colors of an image.
blackout
Draw black opactity rectangle on image.
rotate
Rotate image. Set an angle in degrees and optional color of the uncovered zone after the rotation.
text
Draw text on image. Possible options:
- x: X-Coordinate of text box starting point.
- y: Y-Coordinate of text box starting point.
- width: Width of text box. Calculated from image size for nulled values.
- height: Height of text box. Calculated from image size for nulled values.
- fontsize: Maximum font size. Will be scaled down if the text doesn't fit box.
- color: Color of text. Can be rgb-array or '#ffffff' format.
- lineheight: Line height of text.
- opacity: Text opacity from 0 to 100. Where 0 is no transparency.
- horizontal: Horizontal alignment. Can be left/right/center/justify.
- vertical: Vertical alginment. Can be top/center/bottom/justify.
- fontpath: Path to .ttf or .otf font file.
- debug: Draws text box rectangle if true.
Use boundary to get actual dimensions of the drawn text box. See detailed examples below.
Examples
Append downsized image to blackout background
Result
Draw and center multiline text
Result
Draw and justify multiline text
Result
Use boundaries to draw one title right after another
Result
Draw shapes
Result
Contribution
All project code is stored on Github. The best way to help the project is to report a bug or add some new functionality. You can also open here an issue or send a pull reguest.