Contents
PHP Imagick Functions Complete Reference
PHP Imagick Functions Complete Reference
PHP Overview: A Beginner’s Guide to Syntax
PHP is a versatile server-side language widely used in web development. Its straightforward syntax makes it suitable for both beginners and advanced developers. In this guide, we will explore the basic syntax of PHP. PHP scripts can be embedded within HTML using special PHP tags.
Basic PHP Syntax
PHP code is executed between PHP tags. The most commonly used tags are <?php ... ?>
, which mark the beginning and end of PHP code. This is known as Escaping to PHP.
These tags, also known as Canonical PHP tags, indicate to the PHP parser which parts of the document to process. Everything outside these tags is treated as plain HTML. Each PHP command must end with a semicolon (;
).
PHP Syntax Example
Output:
Greetings from PHP!
Imagick::adaptiveBlurImage()
Description: Add an adaptive blur filter to the image.
Example:
$image->adaptiveBlurImage(5, 3);
// Output: (applies an adaptive blur with specified radius and sigma)
Imagick::adaptiveResizeImage()
Description: Resize the image according to specific dimensions.
Example:
$image->adaptiveResizeImage(200, 300);
// Output: (resizes image to 200x300 pixels)
Imagick::adaptiveSharpenImage()
Description: Sharpen an image adaptively based on intensity.
Example:
$image->adaptiveThresholdImage(3, 3, 1);
// Output: (applies adaptive threshold for localized pixel intensity control)
Imagick::adaptiveThresholdImage()
Description: Applies a threshold based on local intensity values.
Example:
$image->adaptiveThresholdImage(3, 3, 1);
// Output: (applies adaptive threshold for localized pixel intensity control)
Imagick::addImage()
Description: Add a new image to the Imagick object image list.
Example:
$image->addImage($newImage);
// Output: (adds $newImage to the Imagick list)
Imagick::addNoiseImage()
Description: Add noise to the image for texture or effect.
Example:
$image->addNoiseImage(Imagick::NOISE_IMPULSE);
// Output: (applies impulse noise effect)
Imagick::annotateImage()
Description: Add text annotation to the image.
Example:
$combinedImage = $image->appendImages(true);
// Output: (appends images vertically)
Imagick::appendImages()
Description: Append multiple images vertically or horizontally.
Example:
Single-line comment example!
Imagick::autoLevelImage()
Description: Automatically adjust image levels.
Example:
$image->autoLevelImage();
// Output: (adjusts levels for better brightness and contrast)
Imagick::blackThresholdImage()
Description: Convert pixels below a threshold to black.
Example:
$image->blackThresholdImage('#222222');
// Output: (sets pixels darker than the color threshold to black)
Imagick::blueShiftImage()
Description: Applies a moonlit or nighttime effect.
Example:
$image->blueShiftImage(1.5);
// Output: (adds a blue shift effect with specified intensity)
Imagick::blurImage()
Description: Apply a basic blur effect to the image.
Example:
$image->blurImage(5, 3);
// Output: (adds blur with specified radius and sigma)
Imagick::borderImage()
Description: Add a border to the image.
Example:
$image->borderImage('black', 5, 5);
// Output: (adds a 5-pixel black border)
Imagick::brightnessContrastImage()
Description: Adjust brightness and contrast of the image.
Example:
$image->brightnessContrastImage(20, 30);
// Output: (adjusts brightness by 20 and contrast by 30)
Imagick::charcoalImage()
Description: Simulate a charcoal sketch effect.
Example:
$image->charcoalImage(1, 2);
// Output: (applies charcoal effect)
Imagick::chopImage()
Description: Crop and trim a specific region of the image.
Example:
$image->chopImage(100, 100, 50, 50);
// Output: (removes 100x100 area at specified position)
Imagick::commentImage()
Description: Add a comment to the image.
Example:
$image->commentImage("Sample Comment");
// Output: (adds 'Sample Comment' metadata to the image)
Imagick::convolveImage()
Description: Apply a custom convolution kernel to the image.
Example:
$image->convolveImage(array(1, 2, 1, 2, 4, 2, 1, 2, 1));
// Output: (applies the specified convolution filter)
Imagick::cropImage()
Description: Crop the image to a specified region.
Example:
$image->cropImage(100, 100, 10, 10);
// Output: (crops 100x100 pixels starting from (10, 10))
Imagick::despeckleImage()
Description: Reduce speckle noise in the image.
Example:
$image->despeckleImage();
// Output: (applies despeckle filter to reduce noise)
Imagick::displayImage()
Description: Display the image object.
Example:
$image->displayImage();
// Output: (opens image in default viewer, if available)
Imagick::distortImage()
Description: Distort an image using specific distortion methods.
Example:
$image->distortImage(Imagick::DISTORTION_PERSPECTIVE, array(0,0, 30,60, 120,60, 150,120), true);
// Output: (applies perspective distortion)
Imagick::edgeImage()
Description: Enhance the edges within the image.
Example:
$image->edgeImage(1);
// Output: (enhances edges with specified radius)
Imagick::embossImage()
Description: Apply a grayscale emboss effect.
Example:
$image->embossImage(1, 1);
// Output: (adds emboss effect)
Imagick::enhanceImage()
Description: Improve the quality of a noisy image.
Example:
$image->enhanceImage();
// Output: (enhances image by reducing noise)
Imagick::equalizeImage()
Description: Equalize the histogram of the image.
Example:
$image->equalizeImage();
// Output: (equalizes the image contrast)
Imagick::extentImage()
Description: Set the size and origin of the image.
Example:
$image->extentImage(200, 200, -10, -10);
// Output: (resizes image with new origin offset)
Imagick::flattenImages()
Description: Merge the sequence of images into one.
Example:
$flattenedImage = $image->flattenImages();
// Output: (flattens multiple layers into a single image)
Imagick::flipImage()
Description: Create a vertically flipped image.
Example:
$image->flipImage();
// Output: (flips the image vertically)
Imagick::flopImage()
Description: Create a horizontally flipped image
Example:
$image->flopImage();
// Output: (flips the image horizontally)
Imagick::gammaImage()
Description: Apply gamma correction to the image.
Example:
$image->gammaImage(1.2);
// Output: (adjusts gamma to 1.2)
Imagick::getCopyright()
Description: Return ImageMagick API copyright.
Example:
echo $image->getCopyright();
// Output: (displays ImageMagick copyright)
Imagick::getImageBluePrimary()
Description: Get the chromaticity blue primary point.
Example:
print_r($image->getImageBluePrimary());
// Output: (displays x, y values for blue primary)
Imagick::getImageColors()
Description: Get the number of unique colors in the image.
Example:
echo $image->getImageColors();
// Output: (number of unique colors)
Imagick::getImageColorspace()
Description: Get the colorspace of the image.
Example:
echo $image->getImageColorspace();
// Output: (colorspace type)
Imagick::getImageChannelDepth()
Description: Get the depth of a specific image channel.
Example:
echo $image->getImageChannelDepth(Imagick::CHANNEL_RED);
// Output: (depth of the red channel)
Imagick::getImageDepth()
Description: Get the image depth.
Example:
echo $image->getImageDepth();
// Output: (bit-depth of the image)
Imagick::getImageFormat()
Description: Get the format of the image.
Example:
echo $image->getImageFormat();
// Output: (file format, e.g., PNG)
Imagick::getImageGeometry()
Description: Get width and height of the image.
Example:
print_r($image->getImageGeometry());
// Output: (width and height as an associative array)
Imagick::getImageHeight()
Description: Get the height of the image.
Example:
echo $image->getImageHeight();
// Output: (height in pixels)
Imagick::getImageWidth()
Description: Get the width of the image.
Example:
echo $image->getImageWidth();
// Output: (width in pixels)
Imagick::haldClutImage()
Description: Replace colors in the image using a Hald lookup table.
Example:
$image->haldClutImage($clutImage);
// Output: (replaces colors based on Hald lookup table)
Imagick::identifyImage()
Description: Identify an image and return its attributes.
Example:
print_r($image->identifyImage());
// Output: (image metadata and attributes)
Imagick::magnifyImage()
Description: Scale the image up by 2x.
Example:
$image->magnifyImage();
// Output: (image size increased by 2x)
Imagick::modulateImage()
Description: Adjust brightness, saturation, and hue.
Example:
$image->modulateImage(100, 150, 100);
// Output: (adjusts brightness, saturation, and hue)
Imagick::motionBlurImage()
Description: Simulate motion blur in the image.
Example:
$image->motionBlurImage(5, 10, 45);
// Output: (applies motion blur with specified angle)
Imagick::negateImage()
Description: Invert the colors of the image.
Example:
$image->negateImage(false);
// Output: (inverts colors)
Imagick::newImage()
Description: Create a new image.
Example:
$image->newImage(200, 200, new ImagickPixel('red'));
// Output: (creates a 200x200 red image)
Imagick::normalizeImage()
Description: Enhance the contrast by adjusting colors to span the full color range.
Example:
$image->normalizeImage();
// Output: (adjusts contrast across colors)
Imagick::oilPaintImage()
Description: Simulate an oil painting effect.
Example:
$image->oilPaintImage(3);
// Output: (applies oil paint effect with radius 3)
Imagick::orderedPosterizeImage()
Description: Apply ordered dithering for posterization.
Example:
$image->orderedPosterizeImage("o8x8");
// Output: (reduces colors using dithering)
Imagick::posterizeImage()
Description: Reduce image colors to limited levels.
Example:
$image->posterizeImage(4, false);
// Output: (reduces color levels to 4)
Imagick::queryFonts()
Description: Get the list of available fonts.
Example:
print_r($image->queryFonts());
// Output: (array of font names)
Imagick::radialBlurImage()
Description: Apply radial blur to the image.
Example:
$image->radialBlurImage(5);
// Output: (adds radial blur with 5 degrees)
Imagick::raiseImage()
Description: Create a 3D button effect by lightening edges.
Example:
$image->raiseImage(10, 10, 5, 5, true);
// Output: (creates raised edge effect)
Imagick::randomThresholdImage()
Description: Change pixel values based on intensity.
Example:
$image->randomThresholdImage(0.4 * Imagick::getQuantum(), 0.8 * Imagick::getQuantum());
// Output: (adjusts pixel values based on intensity threshold)
Imagick::readImageBlob()
Description: Read an image from a binary string.
Example:
$image->readImageBlob(file_get_contents("path/to/image.png"));
// Output: (loads image from binary data)
Imagick::recolorImage()
Description: Apply color transformations.
Example:
$image->recolorImage(array(
1.5, 0, 0,
0, 1.2, 0,
0, 0, 1.3
));
// Output: (adjusts RGB color intensities)
Imagick::reduceNoiseImage()
Description: Reduce noise in an image.
Example:
$image->reduceNoiseImage(1);
// Output: (smooths contours and reduces noise)
Imagick::resampleImage()
Description: Resample the image to a desired resolution.
Example:
$image->resampleImage(150, 150, Imagick::FILTER_LANCZOS, 1);
// Output: (resamples to 150x150 dpi)
Imagick::rollImage()
Description: Roll image pixels horizontally and vertically.
Example:
$image->rollImage(10, 10);
// Output: (shifts image by 10 pixels horizontally and vertically)
Imagick::rotationalBlurImage()
Description: Apply rotational blur at a given angle.
Example:
$image->rotationalBlurImage(10);
// Output: (applies 10-degree rotational blur)
Imagick::rotateImage()
Description: Rotate the image by a specified angle.
Example:
$image->rotateImage(new ImagickPixel('white'), 45);
// Output: (rotates image by 45 degrees, filling gaps with white)
Imagick::textureImage()
Description: Tile a texture over the image.
Example:
$image->textureImage($textureImage);
// Output: (tiles $textureImage as a background)
Imagick::thumbnailImage()
Description: Resize the image to thumbnail dimensions.
Example:
$image->thumbnailImage(100, 100);
// Output: (creates 100x100 thumbnail)
Imagick::thresholdImage()
Description: Change pixel values based on threshold.
Example:
$image->thresholdImage(0.5 * Imagick::getQuantum());
// Output: (pixels below threshold set to black, others white)
Imagick::transformImage()
Description: Crop and resize the image according to geometry.
Example:
$image->transformImage("100x100", "200x200");
// Output: (crops to 100x100 and resizes to 200x200)
Imagick::transformImageColorspace()
Description: Convert the image to a different colorspace.
Example:
$image->transformImageColorspace(Imagick::COLORSPACE_GRAY);
// Output: (converts image to grayscale)
Imagick::transposeImage()
Description: Create a vertically mirrored image.
Example:
$image->transposeImage();
// Output: (vertical mirror effect)
Imagick::transverseImage()
Description: Create a horizontally mirrored image.
Example:
$image->transverseImage();
// Output: (horizontal mirror effect)
Imagick::trimImage()
Description: Trim edges of the image.
Example:
$image->trimImage(0);
// Output: (trims edges with matching colors)
Imagick::setImageChannelDepth()
Description: Set channel depth for a specific channel.
Example:
$image->setImageChannelDepth(Imagick::CHANNEL_RED, 16);
// Output: (sets red channel depth to 16 bits)
Imagick::setImageOpacity()
Description: Set the opacity level of the image.
Example:
$image->setImageOpacity(0.5);
// Output: (sets opacity to 50%)
Imagick::sharpenImage()
Description: Sharpen the image with a radius and sigma.
Example:
$image->sharpenImage(2, 1);
// Output: (sharpens with 2 radius and 1 sigma)
Imagick::shaveImage()
Description: Shave pixels off edges of the image.
Example:
$image->shaveImage(10, 10);
// Output: (removes 10 pixels from each edge)
Imagick::shearImage()
Description: Apply a shear transformation to the image.
Example:
$image->shearImage(new ImagickPixel('white'), 20, 30);
// Output: (shears image by 20x30 degrees)
Imagick::sketchImage()
Description: Simulate a pencil sketch effect.
Example:
$image->sketchImage(10, 1, 45);
// Output: (applies sketch effect with given radius, sigma, and angle)
Imagick::solarizeImage()
Description: Apply a solarizing effect.
Example:
$image->solarizeImage(128);
// Output: (solarizes using a threshold of 128)
Imagick::spliceImage()
Description: Splice a solid color into the image.
Example:
$image->spliceImage(10, 10, 5, 5);
// Output: (adds a 10x10 section at coordinates 5,5)
Imagick::spreadImage()
Description: Randomly displace each pixel in a block.
Example:
$image->spreadImage(5);
// Output: (randomly displaces pixels with a 5-pixel radius)
Imagick::unsharpMaskImage()
Description: Apply an unsharp mask filter.
Example:
$image->unsharpMaskImage(1, 0.5, 1, 0.05);
// Output: (sharpens image with unsharp mask)
Imagick::uniqueImageColors()
Description: Discard duplicate colors in the image.
Example:
$image->uniqueImageColors();
// Output: (removes duplicated colors)
Imagick::vignetteImage()
Description: Add a vignette effect to the image.
Example:
$image->vignetteImage(10, 20, 5, 5);
// Output: (adds vignette with given parameters)
Imagick::waveImage()
Description: Apply a wave filter to the image.
Example:
$image->waveImage(5, 50);
// Output: (creates a wave effect with amplitude 5, wavelength 50)
Imagick::whiteThresholdImage()
Description: Set pixels above threshold to white.
Example:
$image->whiteThresholdImage(new ImagickPixel('rgb(200, 200, 200)'));
// Output: (pixels above threshold become white)
Imagick::whiteThresholdImage()
Description: Set pixels above threshold to white.
Example:
$image->whiteThresholdImage(new ImagickPixel('rgb(200, 200, 200)'));
// Output: (pixels above threshold become white)
Imagick::waveImage()
Description: Apply a wave filter to the image.
Example:
$image->waveImage(5, 50);
// Output: (creates a wave effect with amplitude 5, wavelength 50)
Imagick::writeImage()
Description: Write the image to a file.
Example:
$image->writeImage("output.png");
// Output: (saves image to output.png)
Imagick::getImageWidth()
Description: Retrieve the width of the image.
Example:
echo $image->getImageWidth();
// Output: (width of $image)
Imagick::getImageHeight()
Description: Retrieve the height of the image.
Example:
echo $image->getImageHeight();
// Output: (height of $image)
Imagick::getImageFormat()
Description: Retrieve the format of the image.
Example:
echo $image->getImageFormat();
// Output: (format of $image, e.g., PNG, JPEG)
Imagick::getImageResolution()
Description: Get the resolution of the image.
Example:
print_r($image->getImageResolution());
// Output: (image resolution as [x, y] array)
Imagick::setImageUnits()
Description: Set the units of resolution for the image.
Example:
$image->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
// Output: (sets resolution units to pixels per inch)
Imagick::shadeImage()
Description: Apply a 3D effect to the image by shading.
Example:
$image->shadeImage(true, 30, 30);
// Output: (adds 3D shading effect)