本文整理匯總了PHP中Imagick::getImageColorspace方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::getImageColorspace方法的具體用法?PHP Imagick::getImageColorspace怎麽用?PHP Imagick::getImageColorspace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::getImageColorspace方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: applyColorProfiles
/**
* this is to force RGB and to apply custom icc color profiles
*/
protected function applyColorProfiles()
{
if ($this->resource->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
$profiles = $this->resource->getImageProfiles('*', false);
// we're only interested if ICC profile(s) exist
$has_icc_profile = array_search('icc', $profiles) !== false;
// if it doesn't have a CMYK ICC profile, we add one
if ($has_icc_profile === false) {
$this->resource->profileImage('icc', self::getCMYKColorProfile());
}
// then we add an RGB profile
$this->resource->profileImage('icc', self::getRGBColorProfile());
$this->resource->setImageColorspace(Imagick::COLORSPACE_RGB);
}
}
// this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
// thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
// problem is described here: http://imagemagick.org/Usage/basics/#type
// and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
if ($this->resource->getimagetype() == Imagick::IMGTYPE_GRAYSCALE) {
$draw = new ImagickDraw();
$draw->setFillColor("red");
$draw->setfillopacity(0.001);
$draw->point(0, 0);
$this->resource->drawImage($draw);
}
}
示例2: makeThumb
public function makeThumb($path, $W = NULL, $H = NULL)
{
$image = new Imagick();
$image->readImage($ImgSrc);
// Trasformo in RGB solo se e` il CMYK
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
$image->transformImageColorspace(Imagick::COLORSPACE_RGB);
}
$image->profileImage('*', NULL);
$image->stripImage();
$imgWidth = $image->getImageWidth();
$imgHeight = $image->getImageHeight();
if ((!$H || $H == null || $H == 0) && (!$W || $W == null || $W == 0)) {
$W = $imgWidth;
$H = $imgHeight;
} elseif (!$H || $H == null || $H == 0) {
$H = $W * $imgHeight / $imgWidth;
} elseif (!$W || $W == null || $W == 0) {
$W = $H * $imgWidth / $imgHeight;
}
$image->resizeImage($W, $H, Imagick::FILTER_LANCZOS, 1);
/** Scrivo l'immagine */
$image->writeImage($path);
/** IMAGE OUT */
header('X-MHZ-FLY: Nice job!');
header(sprintf('Content-type: image/%s', strtolower($image->getImageFormat())));
echo $image->getImageBlob();
$image->destroy();
die;
}
示例3: overlay
public function overlay($layer, $x = 0, $y = 0)
{
$layerCs = $layer->image->getImageColorspace();
$layer->image->setImageColorspace($this->image->getImageColorspace());
$this->image->compositeImage($layer->image(), $this->compositionMode, $x, $y);
$layer->image->setImageColorspace($layerCs);
return $this;
}
示例4: setColorspaceToRGB
/**
* @return $this
*/
public function setColorspaceToRGB()
{
$imageColorspace = $this->resource->getImageColorspace();
if ($imageColorspace == \Imagick::COLORSPACE_CMYK) {
if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
$profiles = $this->resource->getImageProfiles('*', false);
// we're only interested if ICC profile(s) exist
$has_icc_profile = array_search('icc', $profiles) !== false;
// if it doesn't have a CMYK ICC profile, we add one
if ($has_icc_profile === false) {
$this->resource->profileImage('icc', self::getCMYKColorProfile());
}
// then we add an RGB profile
$this->resource->profileImage('icc', self::getRGBColorProfile());
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
// we have to use SRGB here, no clue why but it works
} else {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
}
} else {
if ($imageColorspace == \Imagick::COLORSPACE_GRAY) {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
} else {
if (!in_array($imageColorspace, array(\Imagick::COLORSPACE_RGB, \Imagick::COLORSPACE_SRGB))) {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
} else {
// this is to handle embedded icc profiles in the RGB/sRGB colorspace
$profiles = $this->resource->getImageProfiles('*', false);
$has_icc_profile = array_search('icc', $profiles) !== false;
if ($has_icc_profile) {
try {
// if getImageColorspace() says SRGB but the embedded icc profile is CMYK profileImage() will throw an exception
$this->resource->profileImage('icc', self::getRGBColorProfile());
} catch (\Exception $e) {
\Logger::warn($e);
}
}
}
}
}
// this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
// thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
// problem is described here: http://imagemagick.org/Usage/basics/#type
// and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
$currentLocale = setlocale(LC_ALL, "0");
// this locale hack thing is also a hack for imagick
setlocale(LC_ALL, "");
// details see https://www.pimcore.org/issues/browse/PIMCORE-2728
$draw = new \ImagickDraw();
$draw->setFillColor("#ff0000");
$draw->setfillopacity(0.01);
$draw->point(floor($this->getWidth() / 2), floor($this->getHeight() / 2));
// place it in the middle of the image
$this->resource->drawImage($draw);
setlocale(LC_ALL, $currentLocale);
// see setlocale() above, for details ;-)
return $this;
}
示例5: __construct
/**
* Constructor of the class
*
* @param \Imagick $image The Imagick instance
*/
public function __construct(\Imagick $image)
{
//Convert CMYK to RGB
if ($image->getImageColorspace() === \Imagick::COLORSPACE_CMYK) {
$profiles = $image->getImageProfiles('*', false);
if (array_search('icc', $profiles) === false) {
$image->profileImage('icc', file_get_contents(__DIR__ . '/icc/us_web_uncoated.icc'));
}
$image->profileImage('icm', file_get_contents(__DIR__ . '/icc/srgb.icm'));
$image->transformImageColorspace(\Imagick::COLORSPACE_SRGB);
}
$this->image = $image;
}
示例6: getColorSpace
/**
* {@inheritdoc}
*/
public function getColorSpace()
{
switch ($this->imagick->getImageColorspace()) {
case \Imagick::COLORSPACE_RGB:
case \Imagick::COLORSPACE_SRGB:
return ColorSpace::COLOR_SPACE_RGB;
case \Imagick::COLORSPACE_CMYK:
return ColorSpace::COLOR_SPACE_CMYK;
case \Imagick::COLORSPACE_GRAY:
return ColorSpace::COLOR_SPACE_GRAYSCALE;
default:
throw new RuntimeException('Only RGB, grayscale and CMYK color space are currently supported');
}
}
示例7: setColorspaceToRGB
/**
* @return $this
*/
public function setColorspaceToRGB()
{
$imageColorspace = $this->resource->getImageColorspace();
if ($imageColorspace == \Imagick::COLORSPACE_CMYK) {
if (self::getCMYKColorProfile() && self::getRGBColorProfile()) {
$profiles = $this->resource->getImageProfiles('*', false);
// we're only interested if ICC profile(s) exist
$has_icc_profile = array_search('icc', $profiles) !== false;
// if it doesn't have a CMYK ICC profile, we add one
if ($has_icc_profile === false) {
$this->resource->profileImage('icc', self::getCMYKColorProfile());
}
// then we add an RGB profile
$this->resource->profileImage('icc', self::getRGBColorProfile());
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
// we have to use SRGB here, no clue why but it works
} else {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
}
} else {
if ($imageColorspace == \Imagick::COLORSPACE_GRAY) {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
} else {
if (!in_array($imageColorspace, array(\Imagick::COLORSPACE_RGB, \Imagick::COLORSPACE_SRGB))) {
$this->resource->setImageColorspace(\Imagick::COLORSPACE_SRGB);
} else {
// this is to handle embedded icc profiles in the RGB/sRGB colorspace
$profiles = $this->resource->getImageProfiles('*', false);
$has_icc_profile = array_search('icc', $profiles) !== false;
if ($has_icc_profile) {
$this->resource->profileImage('icc', self::getRGBColorProfile());
}
}
}
}
// this is a HACK to force grayscale images to be real RGB - truecolor, this is important if you want to use
// thumbnails in PDF's because they do not support "real" grayscale JPEGs or PNGs
// problem is described here: http://imagemagick.org/Usage/basics/#type
// and here: http://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=6888#p31891
$draw = new \ImagickDraw();
$draw->setFillColor("#ff0000");
$draw->setfillopacity(0.01);
$draw->point(floor($this->getWidth() / 2), floor($this->getHeight() / 2));
// place it in the middle of the image
$this->resource->drawImage($draw);
return $this;
}
示例8: overlay
public function overlay($layer, $x = 0, $y = 0)
{
//$layer_cs = $layer->image->getImageColorspace();
$layer->image->setImageColorspace($this->image->getImageColorspace());
if ($this->multiframe()) {
$this->image = $this->image->coalesceImages();
$width = $this->image->getImageWidth();
$height = $this->image->getImageHeight();
foreach ($this->image as $frame) {
$over = clone $layer->image;
$frame->setImagePage($width, $height, 0, 0);
$frame->compositeImage($over, $this->composition_mode, $x, $y);
}
// It's magic but it work
$this->image->getImagesBlob();
$this->image->deconstructImages();
} else {
$this->image->compositeImage($layer->image, $this->composition_mode, $x, $y);
}
//$layer->image->setImageColorspace($layer_cs);
return $this;
}
示例9: array
} else {
Logger::debug('main', '(client/applications) No Session id nor public_webservices_access');
echo return_error(7, 'No Session id nor public_webservices_access');
die;
}
$applicationDB = ApplicationDB::getInstance();
$applications = $applicationDB->getApplicationsWithMimetype($_GET['id']);
$apps = array();
foreach ($applications as $application) {
if (!$application->haveIcon()) {
continue;
}
$score = count($application->groups());
if ($application->getAttribute('type') == 'windows') {
$score += 10;
}
$apps[$score] = $application;
}
header('Content-Type: image/png');
$first = new Imagick(realpath(dirname(__FILE__) . '/../admin/media/image/empty.png'));
if (!is_array($apps) || count($apps) == 0) {
echo $first;
die;
}
arsort($apps);
$application = array_shift($apps);
$second = new Imagick(realpath($application->getIconPath()));
$second->scaleImage(16, 16);
$first->setImageColorspace($second->getImageColorspace());
$first->compositeImage($second, $second->getImageCompose(), 6, 10);
echo $first;
示例10: createPalette
/**
* Returns the palette corresponding to an Imagick resource colorspace
*
* @param Imagick $imagick
*
* @return CMYK|Grayscale|RGB
*
* @throws NotSupportedException
*/
private function createPalette(Imagick $imagick)
{
switch ($imagick->getImageColorspace()) {
case Imagick::COLORSPACE_RGB:
case Imagick::COLORSPACE_SRGB:
return new RGB();
case Imagick::COLORSPACE_CMYK:
return new CMYK();
case Imagick::COLORSPACE_GRAY:
return new Grayscale();
default:
throw new NotSupportedException('Only RGB and CMYK colorspace are currently supported');
}
}
示例11: Imagick
/**
* Takes an image filename and returns an Imagick image object
*
* @param string $imgfile the full path and filename of the image to load
* @return Imagick
*/
function zp_imageGet($imgfile)
{
global $_lib_Imagick_info;
if (array_key_exists(strtoupper(getSuffix($imgfile)), $_lib_Imagick_info)) {
$image = new Imagick();
$maxHeight = getOption('magick_max_height');
$maxWidth = getOption('magick_max_width');
if ($maxHeight > lib_Imagick_Options::$ignore_size && $maxWidth > lib_Imagick_Options::$ignore_size) {
$image->setOption('jpeg:size', $maxWidth . 'x' . $maxHeight);
}
$image->readImage(imgSrcURI($imgfile));
//Generic CMYK to RGB conversion
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
$image->transformimagecolorspace(Imagick::COLORSPACE_SRGB);
}
return $image;
}
return false;
}
示例12: sprintf
$imgOut = sprintf('spool/%s_w%s_%sx.%s', $matches[1], $matches[2], $M, $matches[3]);
$W = $matches[2];
$H = null;
if (!file_exists($imgSrc)) {
include 'error404.php';
return;
}
} else {
return;
}
// Moltiplico la dimensione
$W = $W * $M;
$image = new Imagick();
$image->readImage($imgSrc);
// Trasformo in RGB solo se e` il CMYK
if ($image->getImageColorspace() == Imagick::COLORSPACE_CMYK) {
$image->transformImageColorspace(Imagick::COLORSPACE_RGB);
}
$image->profileImage('*', NULL);
$image->stripImage();
$imgWidth = $image->getImageWidth();
$imgHeight = $image->getImageHeight();
if ((!$H || $H == null || $H == 0) && (!$W || $W == null || $W == 0)) {
$W = $imgWidth;
$H = $imgHeight;
} elseif (!$H || $H == null || $H == 0) {
$H = $W * $imgHeight / $imgWidth;
} elseif (!$W || $W == null || $W == 0) {
$W = $H * $imgWidth / $imgHeight;
}
$image->resizeImage($W, $H, Imagick::FILTER_LANCZOS, 1);
示例13: abs
}
//calculate the position from the source image if we need to crop and where
//we need to put into the target image.
$dst_x = $src_x = $dst_y = $src_y = 0;
if ($_POST["imageX"] > 0) {
$dst_x = abs($_POST["imageX"]);
} else {
$src_x = abs($_POST["imageX"]);
}
if ($_POST["imageY"] > 0) {
$dst_y = abs($_POST["imageY"]);
} else {
$src_y = abs($_POST["imageY"]);
}
//This fix the page of the image so it crops fine!
$img->setimagepage(0, 0, 0, 0);
//crop the image with the viewed into the viewport
$img->cropImage($viewPortW, $viewPortH, $src_x, $src_y);
//create the viewport to put the cropped image
$viewport = new Imagick();
$viewport->newImage($viewPortW, $viewPortH, '#' . $colorHEX);
$viewport->setImageFormat($ext);
$viewport->setImageColorspace($img->getImageColorspace());
$viewport->compositeImage($img, $img->getImageCompose(), $dst_x, $dst_y);
//crop the selection from the viewport
$viewport->setImagePage(0, 0, 0, 0);
$viewport->cropImage($_POST["selectorW"], $_POST["selectorH"], $selectorX, $selectorY);
$targetFile = 'tmp/test_' . time() . "." . $ext;
//save the image into the disk
$viewport->writeImage($targetFile);
echo $targetFile;
示例14: convert2sRGBColorSpace
public function convert2sRGBColorSpace($src, $dir, $cache, $iccFile, $useCache = true)
{
if ($this->verbose) {
$this->log("# Converting image to sRGB colorspace.");
}
if (!class_exists("Imagick")) {
$this->log(" Ignoring since Imagemagick is not installed.");
return false;
}
$this->setSaveFolder($cache)->setSource($src, $dir)->generateFilename(null, false, 'srgb_');
if ($useCache && is_readable($this->cacheFileName)) {
$fileTime = filemtime($this->pathToImage);
$cacheTime = filemtime($this->cacheFileName);
if ($fileTime <= $cacheTime) {
$this->log(" Using cached version: " . $this->cacheFileName);
return $this->cacheFileName;
}
}
if (is_writable($this->saveFolder)) {
$image = new Imagick($this->pathToImage);
$colorspace = $image->getImageColorspace();
$this->log(" Current colorspace: " . $colorspace);
$profiles = $image->getImageProfiles('*', false);
$hasICCProfile = array_search('icc', $profiles) !== false;
$this->log(" Has ICC color profile: " . ($hasICCProfile ? "YES" : "NO"));
if ($colorspace != Imagick::COLORSPACE_SRGB || $hasICCProfile) {
$this->log(" Converting to sRGB.");
$sRGBicc = file_get_contents($iccFile);
$image->profileImage('icc', $sRGBicc);
$image->transformImageColorspace(Imagick::COLORSPACE_SRGB);
$image->writeImage($this->cacheFileName);
return $this->cacheFileName;
}
}
return false;
}
示例15: load
protected function load($size = null)
{
try {
$magick = new \Imagick();
if ($this->format === IMG_JPG && $size !== null) {
$magick->setOption('jpeg:size', $size[0] . 'x' . $size[1]);
// some versions of Imagick only respond to this...
$magick->setSize($size[0], $size[1]);
// ...and others to this
}
$magick->readImage($this->filename);
} catch (\Exception $e) {
throw new \Imagine\Exception\RuntimeException("Imagick: Unable to open image {$this->filename}. {$e->getMessage()}", $e->getCode(), $e);
}
if ($this->format === IMG_JPG && $size !== null) {
$newWidth = $magick->getImageWidth();
if ($newWidth !== $this->size[0]) {
$this->size = $this->prescalesize = array($newWidth, $magick->getImageHeight());
}
}
$cs = $magick->getImageColorspace();
$this->image = new Image($magick, RImagine::createPalette($cs), $this->metadata);
if ($cs === \Imagick::COLORSPACE_CMYK) {
// convert CMYK > RGB
try {
$this->image->usePalette(new RGB());
} catch (\Exception $e) {
$this->image->getImagick()->stripimage();
// make sure all profiles are removed
}
}
}