Graphics Draw

PHP is not limited to creating just HTML output. It can also be used to create and manipulate image files in a variety of different image formats, including GIF, PNG, JPEG, WBMP, and XPM. Even more conveniently, PHP can output image streams directly to a browser. You will need to compile PHP with the GD library of image functions for this to work. GD and PHP may also require other libraries, depending on which image formats you want to work with.

You can use the image functions in PHP to get the size of JPEG, GIF, PNG, SWF, TIFF and JPEG2000 images.

$config_from_resource = [
    "image" => $image_resource
];

$gd_from_resource = new \Samy\Image\Gd($config_from_resource);

$config_from_location = [
    "location" => $image_location
];

$gd_from_location = new \Samy\Image\Gd($config_from_location);

$config_from_scratch = [
    "type" => GdImageType::WEBP,
    "width" => 250,
    "height" => 250
];

$gd_from_scratch = new \Samy\Image\Gd($config_from_scratch);

Configuration

Graphics Draw Configuration

NameTypeDefaultDescription
imageGdImagenullAttach to resource if not empty.
locationstringLoad resource from image location if not empty.
typeintGdImageType::WEBPProvide image type if create image from scratch.
widthint250Provide image width if create image from scratch.
heightint250Provide image height if create image from scratch.

Image Constants

Image Type

NameValue
GdImageType::JPEG2
GdImageType::PNG3
GdImageType::BMP6
GdImageType::WBMP15
GdImageType::XBM16
GdImageType::WEBP18

Arc Draw Style

NameValue
GdArcStyle::PIE0
GdArcStyle::CHORD1
GdArcStyle::NOFILL2
GdArcStyle::EDGED4

Blur Filter

NameValue
GdBlur::GAUSSIAN0
GdBlur::SELECTIVE1

Flip Transform

NameValue
GdFlip::HORIZONTAL1
GdFlip::VERTICAL2
GdFlip::BOTH3

Corner Side Transform

NameValue
GdCornerSide::TOP_LEFT1
GdCornerSide::TOP_RIGHT2
GdCornerSide::TOP3
GdCornerSide::BOTTOM_RIGHT4
GdCornerSide::RIGHT6
GdCornerSide::BOTTOM_LEFT8
GdCornerSide::LEFT9
GdCornerSide::BOTTOM12
GdCornerSide::ALL15

Corner Style Transform

NameValue
GdCornerStyle::FLAT0
GdCornerStyle::ROUND1