Javatpoint Logo
Javatpoint Logo

Imagick::charcoalImage() PHP

The Imagick::charcoalImage() method is a PHP built-in function for simulating a charcoal drawing of an image. This function will create a charcoal image of the parameter image which is passed as an input, the image which we will pass as an input to this function the output generated by this particular function is the charcoal copy of that particular image.

The following parameters are accepted by this function, as mentioned above and described below:

  • $radius: The value of the Gaussian's radius in pixels is stored in this parameter.
  • $sigma: This parameter stores the value of the Gaussian's standard deviation in pixels.

Return Value

The return value is a Boolean value depending upon the success and failure of the function. The return type of this function will be a true value if the conversion of the input image to the charcoal image is successful. On the other hand, if the conversion of the input image to the charcoal image is unsuccessful the return type of this function will be changed to false.

Now let us look at a sample code of how we can use this function to actually convert the image to its charcoal substitute.

Sample Code:

Output:

Imagick::charcoalImage() PHP

The code that is written above will successfully convert the image into its charcoal substitute. To specify which image, we want to convert to the charcoal image we need to pass the file path so the file path will be the actual part of the file on which we want to apply this operation.

Additional Note

This function's parameters are somewhat frightening. I think I put it together after toying with it for a little while. The Gaussian is the "brush," the radius is the brush's radius, and the standard deviation is the degree of variance among the brush impression sizes (in Gimp/Photoshop lingo). The $radius parameter can be set to any value between 0 and as high as your imagination allows, but once you go past 10, 20, or 30 pixels, depending on the image size, the image becomes too blurry to recognize. To achieve the intended effect, the $sigma, or standard deviation, should be less than the radius. Consider it like this: "Charcoal Brushes of $radius Pixels Size, each brush being $sigma Pixels bigger or less than that."

You'll probably require a $radius of 3 to 5 and a $sigma of 1 to 3 for an ordinary 500 x 500-pixel image, but you can generally go as far as 10 pixels before the image is blurred beyond recognition. (For the time being, $radius: 5 / $sigma: 2 is the ideal blend for this 400x400 image). This code opens the supplied file, applies the charcoal image effect to it, and then saves it to another specified file. The arguments are delivered via POST data, and the only ImageMagick functions used are read an image file, charcoal images, and write image file, as follows:

Code:

Output:

Imagick::charcoalImage() PHP

Thus, this article gives a brief idea about how we can use this particular PHP inbuilt function to convert a simple image to its charcoal counterpart. Apart from Imagick::charcoalImage() Function, we have used some other functions also we will be looking into those functions in some other articles.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA