PHP 8.4.0 RC2 available for testing

Imagick::charcoalImage

(PECL imagick 2, PECL imagick 3)

Imagick::charcoalImageРисование углём

Описание

public Imagick::charcoalImage(float $radius, float $sigma): bool

Рисование углём.

Список параметров

radius

Радиус Гаусса, в пикселях, не включая центральный пиксель

sigma

Стандартное отклонение Гаусса, в пикселях

Возвращаемые значения

Функция в случае успешной работы возвращает true.

Примеры

Пример #1 Пример использования Imagick::charcoalImage()

<?php
function charcoalImage($imagePath, $radius, $sigma) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->charcoalImage($radius, $sigma);
header("Content-Type: image/jpg");
echo
$imagick->getImageBlob();
}

?>

Добавить примечание

Примечания пользователей 1 note

up
4
holdoffhunger at gmail dot com
12 years ago
The parameters for this function are really scary. Radius of the Gaussian and Standard Deviation of the Gaussian? After playing with it for a little bit, I think I put it together. The Gaussian is the "brush" (in Gimp/Photoshop jargin), the radius is simply the radius of the brush, and the standard deviation is the level of variation among the sizes of the brush imprints. The $radius parameter can be anything from 0 to as high a number as you can think, but once you beyond 10, 20, or 30 pixels, depending on the image size, the whole image gets blurred beyond useful recognition. The $sigma, being the standard deviation, should be smaller than your radius to get the desired effect. Think of it as "Charcoal Brushes of $radius Pixels Size, with each brush being as much as $sigma Pixels bigger or smaller than that."

For an average 500 x 500 pixel image, you'll probably want a $radius of 3 to 5 and a $sigma of 1 to 3, but you can go as far as 10 pixels generally before the image is blurred beyond recognition. (At the moment, $radius: 5 / $sigma: 2 is the perfect blend for this 400x400 image that I'm working on right now.)

There was not too help from the official documentation site for this project, either: http://www.imagemagick.org/RMagick/doc/image1.html . The authors there note: "You can alter the intensity of the effect by changing the radius and sigma arguments." So, my description here of the functioning is based mostly on experience rather than documentation, which is difficult to find.

The following is the entire code for applying the effect to an image. This code will open the specified file, it will apply the charcoalImage effect to it, and then it will save it to another specified file. The arguments are served up through POST data, and the only functions of the ImageMagick class that are used are the readImageFile, charcoalImage, and writeImageFile, as so :

<?php

// Author: holdoffhunger@gmail.com

// Grab Inbound Data -- Function Parameters
// --------------------------------------------------

$inbound_gaussian_radius = $_POST['radius_of_gaussian'];
$inbound_standard_deviation = $_POST['standard_deviation_of_gaussian'];

// Grab Inbound Data -- Read-File and Write-File
// --------------------------------------------------

$filename_for_function = $_POST['file_target'];
$inbound_save_as_filename = $_POST['saveable_result_file'];

// Grab Image File Data
// ---------------------------------------------

$folder_location = "images/workshop/";
$file_to_grab_with_location = $folder_location . $filename_for_function;

$imagick_type = new Imagick();

// Open File
// ---------------------------------------------

$file_handle_for_viewing_image_file = fopen($file_to_grab_with_location, 'a+');

// Read File
// ---------------------------------------------

$imagick_type->readImageFile($file_handle_for_viewing_image_file);

// Perform Function
// ---------------------------------------------

$imagick_type->charcoalImage($inbound_gaussian_radius, $inbound_standard_deviation);

// Save File
// ---------------------------------------------

$folder_location = "images/workshop/";
$file_to_grab_with_location = $folder_location . $inbound_save_as_filename;

$file_handle_for_saving_image_file = fopen($file_to_grab_with_location, 'a+');

// Write File
// ---------------------------------------------

$imagick_type->writeImageFile($file_handle_for_saving_image_file);

?>
To Top