Contents

Gmagick Functions

Basic Gmagick Functions

The Gmagick class provides a wrapper to the GraphicsMagick library, which is used to create, edit, and manipulate images.

Gmagick::addImage()
Description: Adds a new image to the Gmagick object image list.
Example:

				
					$image->addImage($newImage);  
// Output: (adds a new image to the current Gmagick image list)

				
			

Gmagick::blurImage()
Description: Applies a blur filter to the image.
Example:

				
					$image->blurImage(5, 3);  
// Output: (applies a blur with radius 5 and sigma 3 to the image)

				
			

Gmagick::cropImage()
Description: Extracts a specific region from the image.
Example:

				
					$image->cropImage(100, 100, 50, 50);  
// Output: (crops a 100x100 region starting at coordinates (50, 50))

				
			

Gmagick::flipImage()
Description: Creates a mirror image by reflecting the pixels along the x-axis.
Example:

				
					$image->flipImage();  
// Output: (creates a flipped version of the image along the x-axis)

				
			

Gmagick::rotateImage()
Description: Rotates the image by the specified number of degrees.
Example:

				
					$image->rotateImage('#FFFFFF', 90);  
// Output: (rotates the image by 90° with a white background)

				
			

Gmagick::resizeImage()
Description: Scales the image to specified dimensions using a filter.
Example:

				
					$image->resizeImage(200, 150, Gmagick::FILTER_LANCZOS, 1);  
// Output: (resizes the image to 200x150 pixels using Lanczos filter)

				
			

Gmagick::oilPaintImage()
Description: Applies a special effect filter that simulates an oil painting.
Example:

				
					$image->oilPaintImage(3);  
// Output: (applies an oil-paint effect to the image with radius 3)

				
			

Gmagick::addNoiseImage()
Description: Adds noise to the image.
Example:

				
					$image->addNoiseImage(Gmagick::NOISE_POISSON);  
// Output: (adds Poisson noise to the image)

				
			

Gmagick::annotateImage()
Description: Annotates an image with text.
Example:

				
					$image->annotateImage($draw, 10, 50, 0, 'Sample Text');  
// Output: (adds the text "Sample Text" to the image at coordinates (10, 50))

				
			

Gmagick::borderImage()
Description: Draws a border around the image.
Example:

				
					$image->borderImage('#000000', 10, 10);  
// Output: (adds a black border of 10px width to the image)

				
			

Gmagick::charcoalImage()
Description: Simulates a charcoal sketch effect.
Example:

				
					$image->charcoalImage(2, 1);  
// Output: (applies a charcoal effect to the image with radius 2 and sigma 1)

				
			

Gmagick::chopImage()
Description: Removes a region from the image and trims it.
Example:

				
					$image->chopImage(100, 100, 50, 50);  
// Output: (removes a 100x100 region starting at coordinates (50, 50))

				
			

Gmagick::clear()
Description: Clears all resources associated with the Gmagick object.
Example:

				
					$image->clear();  
// Output: (releases memory and clears all resources)

				
			

Gmagick::commentImage()
Description: Adds a comment to the image.
Example:

				
					$image->commentImage('This is a sample comment.');  
// Output: (attaches the comment "This is a sample comment" to the image)

				
			

Gmagick::cropThumbnailImage()
Description: Creates a fixed-size thumbnail by scaling and cropping the image.
Example:

				
					$image->cropThumbnailImage(150, 150);  
// Output: (creates a 150x150 thumbnail of the image)

				
			

Gmagick::drawImage()
Description: Renders a GmagickDraw object onto the image.
Example:

				
					$image->drawImage($draw);  
// Output: (draws the specified shapes or text on the image)

				
			

Gmagick::edgeImage()
Description: Enhances the edges of the image using a convolution filter.
Example:

				
					$image->edgeImage(1);  
// Output: (enhances the edges of the image with radius 1)

				
			

Gmagick::embossImage()
Description: Applies a three-dimensional grayscale emboss effect.
Example:

				
					$image->embossImage(2, 1);  
// Output: (applies an emboss effect with radius 2 and sigma 1)

				
			

Gmagick::enhanceImage()
Description: Applies a digital filter to improve image quality.
Example:

				
					$image->enhanceImage();  
// Output: (improves the quality of the image)

				
			

Gmagick::equalizeImage()
Description: Equalizes the histogram of the image.
Example:

				
					$image->equalizeImage();  
// Output: (adjusts image contrast by equalizing its histogram)

				
			

Gmagick::flopImage()
Description: Creates a mirror image along the y-axis.
Example:

				
					$image->flopImage();  
// Output: (creates a mirrored version of the image along the y-axis)

				
			

Gmagick::gammaImage()
Description: Applies gamma correction to the image.
Example:

				
					$image->gammaImage(1.5);  
// Output: (applies a gamma correction with a factor of 1.5)

				
			

Gmagick::implodeImage()
Description: Creates an implosion effect on the image.
Example:

				
					$image->implodeImage(0.5);  
// Output: (creates an imploded version of the image with a factor of 0.5)

				
			

Gmagick::medianFilterImage()
Description: Reduces noise in the image using a median filter.
Example:

				
					$image->medianFilterImage(2);  
// Output: (reduces image noise with a radius of 2)

				
			

Gmagick::motionBlurImage()
Description: Simulates motion blur in the image.
Example:

				
					$image->motionBlurImage(5, 3, 45);  
// Output: (applies a motion blur with radius 5, sigma 3, and angle 45°)

				
			

Gmagick::normalizeImage()
Description: Enhances the contrast of the image by adjusting pixel colors to span the entire color range.
Example:

				
					$image->normalizeImage();  
// Output: (enhances the image contrast by normalizing its pixel colors)

				
			

Gmagick::raiseImage()
Description: Adds a simulated three-dimensional effect by raising the edges of the image.
Example:

				
					$image->raiseImage(10, 10, 5, 5, true);  
// Output: (creates a raised edge effect with a 10x10 rectangle inset by 5 pixels)

				
			

Gmagick::reduceNoiseImage()
Description: Smooths contours of the image while preserving edges.
Example:

				
					$image->reduceNoiseImage(3);  
// Output: (reduces noise in the image with a threshold of 3)

				
			

Gmagick::resampleImage()
Description: Resamples the image to the desired resolution.
Example:

				
					$image->resampleImage(300, 300, Gmagick::FILTER_LANCZOS, 1);  
// Output: (resamples the image to 300 DPI with Lanczos filter)

				
			

Gmagick::rollImage()
Description: Rolls the image horizontally and vertically.
Example:

				
					$image->rollImage(50, 25);  
// Output: (shifts the image 50 pixels horizontally and 25 pixels vertically)

				
			

Gmagick::scaleImage()
Description: Scales the image to the specified dimensions.
Example:

				
					$image->scaleImage(300, 200);  
// Output: (resizes the image to 300x200 pixels)

				
			

Gmagick::setImageDepth()
Description: Sets the bit depth for the image.
Example:

				
					$image->setImageDepth(16);  
// Output: (sets the image depth to 16 bits)

				
			

Gmagick::setImageResolution()
Description: Sets the resolution of the image.
Example:

				
					$image->setImageResolution(300, 300);  
// Output: (sets the image resolution to 300 DPI)

				
			

Gmagick::shearImage()
Description: Slides the edges of an image to create a parallelogram effect.
Example:

				
					$image->shearImage('#FFFFFF', 30, 0);  
// Output: (applies a shear transformation with a 30° x-axis slope and a white background)

				
			

Gmagick::solarizeImage()
Description: Applies a solarize effect to the image.
Example:

				
					$image->solarizeImage(128);  
// Output: (creates a solarized version of the image with a threshold of 128)

				
			

Gmagick::spreadImage()
Description: Randomly displaces pixels in the image.
Example:

				
					$image->spreadImage(5);  
// Output: (displaces pixels randomly within a 5-pixel block)

				
			

Gmagick::stripImage()
Description: Removes all profiles and comments from the image.
Example:

				
					$image->stripImage();  
// Output: (removes metadata such as profiles and comments from the image)

				
			

Gmagick::swirlImage()
Description: Swirls the pixels around the center of the image.
Example:

				
					$image->swirlImage(90);  
// Output: (creates a swirl effect with a 90° rotation)

				
			

Gmagick::magnifyImage()
Description: Scales the image to twice its original size.
Example:

				
					$image->magnifyImage();  
// Output: (enlarges the image to 2x its original size)

				
			

Gmagick::minifyImage()
Description: Scales the image to half its original size.
Example:

				
					$image->minifyImage();  
// Output: (reduces the image size to 50% of its original dimensions)

				
			

Gmagick::modulateImage()
Description: Adjusts brightness, saturation, and hue of the image.
Example:

				
					$image->modulateImage(100, 50, 120);  
// Output: (adjusts brightness to 100%, saturation to 50%, and hue to 120%)

				
			

Gmagick::motionBlurImage()
Description: Simulates motion blur in the image.
Example:

				
					$image->motionBlurImage(10, 5, 45);  
// Output: (adds a motion blur effect with radius 10, sigma 5, and angle 45°)

				
			

Gmagick::implodeImage()
Description:
Creates an implosion effect on the image.
Example:

				
					$image->implodeImage(-1);  
// Output: (creates an exploded effect on the image)

				
			

Gmagick::oilPaintImage()
Description: Applies an oil painting effect to the image.
Example:

				
					$image->oilPaintImage(3);  
// Output: (applies an oil painting effect with radius 3)

				
			

Gmagick::rotateImage()
Description: Rotates the image by the specified degrees.
Example:

				
					$image->rotateImage('#FFFFFF', 45);  
// Output: (rotates the image by 45° with a white background fill)

				
			

Gmagick::resizeImage()
Description: Resizes the image to the given dimensions using a specific filter.
Example:

				
					$image->resizeImage(200, 100, Gmagick::FILTER_LANCZOS, 1);  
// Output: (resizes the image to 200x100 pixels with the Lanczos filter)

				
			

Gmagick::setImageChannelDepth()
Description: Sets the depth of a specific image channel.
Example:

				
					$image->setImageChannelDepth(Gmagick::CHANNEL_RED, 8);  
// Output: (sets the red channel depth to 8 bits)

				
			

Gmagick::implodeImage()
Description: Creates an implosion effect on the image.
Example:

				
					$image->implodeImage(0.5);  
// Output: (applies an implosion effect with a factor of 0.5)

				
			

Gmagick::spreadImage()
Description: Randomly displaces pixels within a defined block size.
Example:

				
					$image->spreadImage(5);  
// Output: (applies a random pixel displacement with a block size of 5)