Imagick::orderedPosterizeImage

(PECL imagick 2 >= 2.2.2, PECL imagick 3)

Imagick::orderedPosterizeImage β€” ВыполняСт упорядочСнный Π΄ΠΈΠ·Π΅Ρ€ΠΈΠ½Π³

Π’Π½ΠΈΠΌΠ°Π½ΠΈΠ΅

Ѐункция объявлСна УБВАРЕВШЕЙ Π² Imagick 3.4.4. ΠŸΠΎΠ»Π°Π³Π°Ρ‚ΡŒΡΡ Π½Π° эту Ρ„ΡƒΠ½ΠΊΡ†ΠΈΡŽ ΠΊΡ€Π°ΠΉΠ½Π΅ Π½Π΅ рСкомСндуСтся.

ОписаниС

public function Imagick::orderedPosterizeImage(string $threshold_map, int $channel = Imagick::CHANNEL_DEFAULT): bool

ВыполняСт упорядочСнный Π΄ΠΈΠ·Π΅Ρ€ΠΈΠ½Π³ Π½Π° основС ряда ΠΏΡ€Π΅Π΄ΠΎΠΏΡ€Π΅Π΄Π΅Π»Ρ‘Π½Π½Ρ‹Ρ… ΠΊΠ°Ρ€Ρ‚ ΠΏΠΎΡ€ΠΎΠ³ΠΎΠ²Ρ‹Ρ… Π·Π½Π°Ρ‡Π΅Π½ΠΈΠΉ Π΄ΠΈΠ·Π΅Ρ€ΠΈΠ½Π³Π°, Π½ΠΎ с нСсколькими уровнями интСнсивности, ΠΊΠΎΡ‚ΠΎΡ€Ρ‹Π΅ ΠΌΠΎΠ³ΡƒΡ‚ Π±Ρ‹Ρ‚ΡŒ Ρ€Π°Π·Π½Ρ‹ΠΌΠΈ для Ρ€Π°Π·Π½Ρ‹Ρ… ΠΊΠ°Π½Π°Π»ΠΎΠ² Π² соотвСтствии с Π²Ρ…ΠΎΠ΄Π½Ρ‹ΠΌΠΈ Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π°ΠΌΠΈ. ΠœΠ΅Ρ‚ΠΎΠ΄ доступСн, Ссли ΠΌΠΎΠ΄ΡƒΠ»ΡŒ Imagick скомпилировали с вСрсиСй ImageMagick 6.3.1 ΠΈΠ»ΠΈ ΡΡ‚Π°Ρ€ΡˆΠ΅.

Бписок ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ²

threshold_map

Π‘Ρ‚Ρ€ΠΎΠΊΠ°, содСрТащая имя ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠ΅ΠΌΠΎΠΉ ΠΊΠ°Ρ€Ρ‚Ρ‹ ΠΏΠΎΡ€ΠΎΠ³ΠΎΠ²ΠΎΠ³ΠΎ Π΄ΠΈΠ·Π΅Ρ€ΠΈΠ½Π³Π°.

channel

Π£ΠΊΠ°ΠΆΠΈΡ‚Π΅ Π»ΡŽΠ±ΡƒΡŽ константу ΠΊΠ°Π½Π°Π»Π°, которая Π΄Π΅ΠΉΡΡ‚Π²ΠΈΡ‚Π΅Π»ΡŒΠ½Π° для вашСго Ρ€Π΅ΠΆΠΈΠΌΠ° ΠΊΠ°Π½Π°Π»Π°. Π§Ρ‚ΠΎΠ±Ρ‹ ΠΏΡ€ΠΈΠΌΠ΅Π½ΠΈΡ‚ΡŒ Π±ΠΎΠ»Π΅Π΅ Ρ‡Π΅ΠΌ ΠΊ ΠΎΠ΄Π½ΠΎΠΌΡƒ ΠΊΠ°Π½Π°Π»Ρƒ, ΠΎΠ±ΡŠΠ΅Π΄ΠΈΠ½ΠΈΡ‚Π΅ константы Ρ‚ΠΈΠΏΠ° ΠΊΠ°Π½Π°Π»Π° с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ ΠΏΠΎΠ±ΠΈΡ‚ΠΎΠ²Ρ‹Ρ… ΠΎΠΏΠ΅Ρ€Π°Ρ‚ΠΎΡ€ΠΎΠ². ΠžΠ±Ρ€Π°Ρ‚ΠΈΡ‚Π΅ΡΡŒ ΠΊ списку констант ΠΊΠ°Π½Π°Π»Π°.

Π’ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅ΠΌΡ‹Π΅ значСния

Ѐункция Π² случаС ΡƒΡΠΏΠ΅ΡˆΠ½ΠΎΠΉ Ρ€Π°Π±ΠΎΡ‚Ρ‹ Π²ΠΎΠ·Π²Ρ€Π°Ρ‰Π°Π΅Ρ‚ true.

Ошибки

Ѐункция выбрасываСт ΠΈΡΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ ImagickException, Ссли Π²ΠΎΠ·Π½ΠΈΠΊΠ»Π° ошибка.

ΠŸΡ€ΠΈΠΌΠ΅Ρ€Ρ‹

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ #1 ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования Imagick::orderedPosterizeImage()

<?php
function orderedPosterizeImage($imagePath, $orderedPosterizeType) {
$imagick = new \Imagick(realpath($imagePath));

$imagick->orderedPosterizeImage($orderedPosterizeType);
$imagick->setImageFormat('png');

header("Content-Type: image/png");
echo
$imagick->getImageBlob();
}

//orderedPosterizeImage($imagePath, 'o4x4,3,3');
//orderedPosterizeImage($imagePath, 'o8x8,6,6');
orderedPosterizeImage($imagePath, 'h8x8a');
?>
οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 1 note

up
0
holdoffhunger at gmail dot com ΒΆ
14 years ago
Originally, I thought this function would be similar to the Posterize function, or at least, any one of the Imagick class functions that produces an artistic effect (like the oilPaintImage function).  This function can be used for those purposes, but it is mostly geared toward print production.  The OrderedPosterize is simply a highly flexible dithering tool.  The intention essentially is to produce high-resolution imagery by means of using constant dots across a medium that vary in size according to the detail of the imagery.  Everyone has seen a dithered photograph inside of a newspaper, but the wiki page provides better examples: http://en.wikipedia.org/wiki/Dither .

The two parameters are unusual to someone who simply wants to get the use of this function without fussing too much about the Imagick class.

First parameter: The threshold_map is a set of "brushes" predefined by a very simple xml file.  They are: threshold, checks, o2x2, o3x3, o4x4, o8x8, h4x4a, h6x6a, h8x8a, h4x4o, h6x6o, h8x8o, h16x16o, c5x5b, c5x5w, c6x6b, c6x6w, c7x7b, and c7x7w.  These are the values you are expected to input as parameters for the Thershold_Map value.  Much better descriptions of these brush shapes available at the Imagick site: http://www.imagemagick.org/Usage/quantize/tmaps_list.txt .

Second parameter: The channel is any of the constants as predefined by the Imagick class.  In the code, the value looks like "imagick::CHANNEL_RED", but you have the "_value" options of: red, undefined, gray, cyan, green, magenta, blue, yellow, alpha, opacity, matte, black, index, all, and default.  More info here: http://www.php.net/manual/en/imagick.constants.php#imagick.constants.channel .

Finally, don't forget you can use bitwise operators on the second parameter.  That means you can use & to AND them, | to OR them, & to XOR them, and ~ to NEGATE them.  A valid parameter for the second parameter would be: "((~imagick::CHANNEL_GREEN) ^ imagick::CHANNEL_YELLOW) | imagick::CHANNEL_MAGENTA)".  You can get extremely creative in this particular parameter.  And if you want to define your own brushes using simple XML, then that's also true of the first parameter, too.

Note:  You can use this function artistically.  How?  Use the orderedPosterizeImage to give the image some texture (a photo of a vase, for instance), and then use your OilPoint, Sketch, or Standard Posterize to give the image a cool effect.  Alone, though, seems pretty boring.

And now, a very simple demonstration :

<?php

            // Author: holdoffhunger@gmail.com
    
        // Filename
        // ---------------------------------------------

    $file_to_grab_with_location = "graphics_engine/image_workshop_directory/ordered_posterize_source.bmp"
    
    $imagick_type = new Imagick();
    
        // Open File
        // ---------------------------------------------
    
    $file_handle_for_viewing_image_file = fopen($file_to_grab_with_location, 'a+');
    
    $imagick_type->readImageFile($file_handle_for_viewing_image_file);
    
        // Perform Function
        // ---------------------------------------------
    
    $imagick_type->orderedPosterizeImage("o2x2", imagick::CHANNEL_GREEN);
    
        // Save File
        // ---------------------------------------------

    $file_to_save_with_location = "graphics_engine/image_workshop_directory/ordered_posterize_result.bmp"
    
    $file_handle_for_saving_image_file = fopen($file_to_save_with_location, 'a+');
    
    $imagick_type->writeImageFile($file_handle_for_saving_image_file);

?>