略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Imagick::setColorspace

2024-11-13

Imagick::setColorspace

(PECL imagick 3)

Imagick::setColorspaceSet colorspace

说明

public Imagick::setColorspace(int $COLORSPACE): bool

Sets the global colorspace value for the object. 此方法在Imagick基于ImageMagick 6.5.7以上版本编译时可用。

参数

COLORSPACE

One of the COLORSPACE constants

返回值

成功时返回 true

错误/异常

错误时抛出 ImagickException。

add a noteadd a note

User Contributed Notes 2 notes

up
1
simonjjarrett at gmail dot com
2 years ago
This method has to be called BEFORE any files are loaded into the Imagick object.

By default, Imagick will incorrectly read CMYK PDFs - it will read each channel as a greyscale page resulting in 4 times the number of pages. By specifying the desired colorspace (usually SRGB) before reading the file, GhostScript will automatically convert it.

<?php
$im
= new Imagick();

// set the sampling resolution
$im->setResolution(200,200);

// set the desired format
$im->SetColorspace(Imagick::COLORSPACE_SRGB);

$im->readimage($file['tmp_name']);
?>
up
-2
T
7 years ago
Right now this function doesn't appear to do anything, ref: http://stackoverflow.com/q/10739822/2685496

As mentioned in the answer, modulateImage works fine as a replacement for converting to gray scale.

<?php

$image
= new Imagick("input.jpg");

$image->modulateImage(100, 0, 100);

$image->writeImage("output.jpg");

$image->clear();

?>

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

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