Deprecated: Function WP_User_Query was called with an argument that is deprecated since version 5.9.0! who is deprecated. Use capability instead. in /var/www/wp-includes/functions.php on line 6078
Web Development

How to Use Wide Image Library in PHP?

February 23, 2016

How to Use Wide Image Library in PHP?

Wide image is an object oriented library that is used for image manipulation. It offers a simple way of loading, editing and saving images in the widely used common image formats. It needs PHP 5.2 + along with GD2 extension.

It supports all the formats such as GIF, PNG, JPG, GD, GD2, WBMP, XBM and XPM. It supports BMP and TGA.

How to load an image?

Before we carry out various operations on the image with the help of Wide Image Library, first of all we must load the image and to do so, we use load() method which is used to load the image from any existing file, URL, HTML, input file field as well as valid image handle.

This method comes with following syntax:

“static WideImage_Image load( mixed $source)”

Image URLs
This wide image supports cross format conversion.

Implementing Smart Coordinates:

These coordinates are applied for various procedures that include coordinates, dimensions and positioning easier. These can be used with every operation which requires various coordinates like as parameters such as resize and crop.

The numerical coordinates include: $resized = $image->resize (200, 100);

How to Re-size an image?

To resize an image with the help of Wide Image Library; one can use resize() method that has following syntax:

WideImage_Image resize( [mixed $width = null], [mixed $height = null], [string $fit = ‘inside’], [string $scale = ‘any’])-

Cropping an Image:

At times, there’s a need to crop the images. This can be done easily using Wide Image Library. The crop() method can be used here with the following syntax:

WideImage_Image crop( [mixed $left = 0], [mixed $top = 0], [mixed $width = ‘100%’], [mixed $height = ‘100%’])

Combining two images:

In order to merge two images with WideImage Library, the merge() method is to be used with the following syntax;

WideImage_Image merge( WideImage_Image $overlay, [mixed $left = 0], [mixed $top = 0], [int $pct = 100])- This method lays the overlay (watermark) on the image.

How to add shapes and text to an image:

Many times, we need to add shapes or text to an image so as to meet our needs. With Wide Image Library; one can easily draw or insert text as well as shapes in the image with the use of Canvas object that is returned by getCanvas() method.

Wide Image Library

How to rotate or mirror the images:

In order to rotate, mirror or flip the images; one needs to use any of these methods:

WideImage_Image rotate( int $angle, [int $bgColor = null], [bool $ignoreTransparent = true]) – Rotate the image for angle $angle clockwise.
WideImage_Image mirror( ) – Returns a mirrored copy of the image
WideImage_Image flip( ) – Returns a flipped (mirrored over horizontal line) copy of the image

Rounding Image Corners:

Using roundCorners() method, it is easy to provide rounded corners to an image. Apart from round corners, we can also give diagonal corners, right corners, deep and coloured corners etc.

Take Away:

Like this, we can add images in PHP with the help of WideImage Library. We can also give different effects to the image as mentioned in the entire blog post.

Hope this blog post will be useful to you. For more such tips and techniques, stay connected with Softqube Technologies; well known PHP web development Company offering web development services at affordable costs.

Share on

Hari Patel

I am the Managing Director of Softqube Technologies Pvt. Ltd., a modern-day digital transformation, design and development service provider. We provide services to businesses of all verticals across the globe. I believe and live by a mission that I help more entrepreneurs to build, launch and grow profitable businesses.

Let’s Work together!

"*" indicates required fields

Drop files here or
Max. file size: 5 MB, Max. files: 2.
    This field is for validation purposes and should be left unchanged.