略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Imagick::posterizeImage

2024-11-13

Imagick::posterizeImage

(PECL imagick 2, PECL imagick 3)

Imagick::posterizeImageReduces the image to a limited number of color level

说明

public Imagick::posterizeImage(int $levels, bool $dither): bool

Reduces the image to a limited number of color level.

参数

levels

dither

返回值

成功时返回 true

范例

示例 #1 Imagick::posterizeImage()

<?php
function posterizeImage($imagePath$posterizeType$numberLevels) {
    
$imagick = new \Imagick(realpath($imagePath));
    
$imagick->posterizeImage($numberLevels$posterizeType);
    
$imagick->setImageFormat('png');
    
header("Content-Type: image/png");
    echo 
$imagick->getImageBlob();
}

posterizeImage($imagePath, \Imagick::DITHERMETHOD_RIEMERSMA8);

?>
add a noteadd a note

User Contributed Notes 1 note

up
1
linspb at gmail dot com
4 years ago
At PHP 7.x before

$im->posterizeimage(2, FALSE);

do

$im->setImageType(imagick::IMGTYPE_COLORSEPARATION);

on PHP 5.x working without setImageType well.

Example:
$im = new Imagick();
$r = $im->readImageBlob($label);
if (!$r) {
    return FALSE;
}
$im->setImageType(imagick::IMGTYPE_COLORSEPARATION);
$im->posterizeimage(2, 0);
$bmp = $im->getImageBlob();

官方地址:https://www.php.net/manual/en/imagick.posterizeimage.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3