PHP Unconference Europe 2015

Imagick::charcoalImage

(PECL imagick 2.0.0)

Imagick::charcoalImageSimulates a charcoal drawing

Descrizione

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

Simulates a charcoal drawing.

Elenco dei parametri

radius

The radius of the Gaussian, in pixels, not counting the center pixel

sigma

The standard deviation of the Gaussian, in pixels

Valori restituiti

Restituisce TRUE in caso di successo.

add a note add a note

User Contributed Notes 1 note

up
0
holdoffhunger at gmail dot com
2 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