\PixelCraft
PixelCraft is a lightweight PHP library designed for easy image processing using the GD lib.
With PixelCraft, you can perform basic image operations such as resizing, cropping, drawing of watermarks, and format conversion.
The library is characterized by its user-friendly interface and minimal code footprint,
allowing for quick and efficient image processing in PHP projects.
- Author: Rostyslav Haitkulov <info@ubilling.net.ua>
- License: MIT
Synopsis
class PixelCraft
{
- // members
- protected GDimage $image = '';
- protected integer $quality = 1;
- protected string $imageType = '';
- protected integer $imageWidth = 0;
- protected integer $imageHeight = 0;
- protected array $colorPalette = ;
- protected array $colorsAllocated = ;
- protected string $font = 'skins/OpenSans-Regular.ttf';
- protected integer $fontSize = 10;
- protected integer $lineWidth = 1;
- protected GDimage $watermark = '';
- protected GDimage $brush = '';
- // methods
- public void __construct()
- protected void setDefaultColors()
- public void setQuality()
- public void setFont()
- public void setFontSize()
- public int getImageWidth()
- public int getImageHeight()
- public string getImageType()
- protected array getImageParams()
- public void addColor()
- public bool isImageValid()
- protected string detectImageType()
- protected bool loadImageFile()
- public bool loadImage()
- public bool loadBaseImage()
- public bool loadWatermark()
- public bool saveImage()
- public void getImageBase()
- public void renderImage()
- public void createImage()
- public void scale()
- public void resize()
- public void crop()
- public void cropRegion()
- protected int allocateColor()
- public void fill()
- public void drawPixel()
- public void drawString()
- public void drawText()
- protected int guessFontSize()
- public void drawTextAutoSize()
- public void setLineWidth()
- public void drawRectangle()
- public void drawLine()
- public void drawLineBrush()
- public void drawWatermark()
- public void pixelate()
- public void imageFilters()
- public array getPixelColor()
- public string rgbToHex()
- public array hexToRgb()
- public int rgbToBrightness()
- public array getColorMap()
- public int getPixelBrightness()
- public void rotate()
- public bool setBrush()
- public void drawArc()
Members
protected
- $brush
—
GDimage
Contains currently loaded brush image - $colorPalette
—
array
Contains array of custom RGB colors palette as name=>color - $colorsAllocated
—
array
Contains already allocated image colors as name=>colorInt - $font
—
string
TTF font path - $fontSize
—
int
Font size in pt. - $image
—
GDimage
Contains image copy to perform some magic on it - $imageHeight
—
int
Contains loaded image original height - $imageType
—
string
Contains loaded image mime type - $imageWidth
—
int
Contains loaded image original width - $lineWidth
—
int
Drawing line width in px - $quality
—
int
Contains image rendering quality - $watermark
—
GDimage
Contains watermark image copy
Methods
protected
- allocateColor() — Allocates and returns some image color by its name
- detectImageType() — Returns image type name
- getImageParams() — Returns specified image
- guessFontSize() — Returns font size that fits into image width
- loadImageFile() — Loads some image into protected property from file
- setDefaultColors() — Sets few default colors to palette
public
- __construct() — Schweigen im wald
- addColor() — Creates or replaces RGB color in palette
- createImage() — Creates new empty true-color image
- crop() — Crops image to new dimensions starting from 0x0
- cropRegion() — Crops image to selected region by coords
- drawArc() — Draw a partial arc and fill it
- drawLine() — Draws a line using some color
- drawLineBrush() — Draws a line using preloaded brush
- drawPixel() — Draws pixel on X/Y coords with some color from palette
- drawRectangle() — Draws filled rectangle
- drawString() — Prints some text string at specified X/Y coords with default font
- drawText() — Write text to the image using TrueType fonts
- drawTextAutoSize() — Write single text to the image using TrueType font with auto size selection
- drawWatermark() — Puts preloaded watermark on base image
- fill() — Fills image with some color from palette
- getColorMap() — Returns color map for current intance image as array(y,x)=>color
- getImageBase() — Returns current instance image as base64 encoded text
- getImageHeight() — Returns current image height
- getImageType() — Returns loaded image type
- getImageWidth() — Returns current image width
- getPixelBrightness() — Calculates the brightness of a pixel at the specified coordinates.
- getPixelColor() — Returns RGB values for some specified image pixel as r/g/b/a(lpha)
- hexToRgb() — Converts hex color string to RGB components array
- imageFilters() — Applies image filters set to current instance base image
- isImageValid() — Checks is some image valid?
- loadBaseImage() — Loads a instance image from an base64 encoded image string.
- loadImage() — Loads some image into protected property from file
- loadWatermark() — Loads some watermark image into protected property from file
- pixelate() — Applies pixelation filter
- renderImage() — Renders current instance image into browser
- resize() — Resizes image to some new dimensions
- rgbToBrightness() — Calculates the brightness value of an RGB color.
- rgbToHex() — Converts RGB components array into hex string
- rotate() — Rotates the image by the specified angle clockwise
- saveImage() — Renders current instance image into browser or specified file path
- scale() — Scales image to some scale
- setBrush() — Sets the brush for the image using the specified file path.
- setFont() — Set TTF font path
- setFontSize() — Set font size in pt.
- setLineWidth() — Set the thickness for line drawing in px
- setQuality() — Sets current instance image save/render quality