本文整理汇总了PHP中imagecolormatch函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecolormatch函数的具体用法?PHP imagecolormatch怎么用?PHP imagecolormatch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagecolormatch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convert
/**
* Convert an image. Returns TRUE when successfull, FALSE if image is
* not a truecolor image.
*
* @param img.Image image
* @return bool
* @throws img.ImagingException
*/
public function convert($image)
{
if (!imageistruecolor($image->handle)) {
return false;
}
$tmp = Image::create($image->getWidth(), $image->getHeight(), IMG_TRUECOLOR);
$tmp->copyFrom($image);
imagetruecolortopalette($image->handle, $this->dither, $this->ncolors);
imagecolormatch($tmp->handle, $image->handle);
unset($tmp);
return true;
}
示例2: asPalette
function asPalette($nColors = 255, $dither = null, $matchPalette = true)
{
$nColors = intval($nColors);
if ($nColors < 1) {
$nColors = 1;
} elseif ($nColors > 255) {
$nColors = 255;
}
if ($dither === null) {
$dither = $this->isTransparent();
}
$temp = $this->copy();
imagetruecolortopalette($temp->handle, $dither, $nColors);
if ($matchPalette == true) {
imagecolormatch($this->handle, $temp->handle);
}
if ($this->isTransparent()) {
$trgb = $this->getTransparentColorRGB();
$tci = $temp->getClosestColor($trgb);
$temp->setTransparentColor($tci);
}
$temp->releaseHandle();
return new wiPaletteImage($temp->handle);
}
示例3: imagecreatetruecolor
<?php
$ima = imagecreatetruecolor(110, 20);
$background_color = imagecolorallocate($ima, 0, 0, 0);
$imb = imagecreatetruecolor(110, 20);
$background_color = imagecolorallocate($imb, 0, 0, 100);
var_dump(imagecolormatch($ima, $imb));
示例4: image_aplatir
//.........这里部分代码省略.........
if ($creer) {
$im = @$image["fonction_imagecreatefrom"]($im);
imagepalettetotruecolor($im);
$im_ = imagecreatetruecolor($x_i, $y_i);
if ($image["format_source"] == "gif" and function_exists('ImageCopyResampled')) {
// Si un GIF est transparent,
// fabriquer un PNG transparent
// Conserver la transparence
@imagealphablending($im_, false);
@imagesavealpha($im_, true);
if (function_exists("imageAntiAlias")) {
imageAntiAlias($im_, true);
}
@ImageCopyResampled($im_, $im, 0, 0, 0, 0, $x_i, $y_i, $x_i, $y_i);
imagedestroy($im);
$im = $im_;
}
// allouer la couleur de fond
if ($transparence) {
@imagealphablending($im_, false);
@imagesavealpha($im_, true);
$color_t = imagecolorallocatealpha($im_, $dr, $dv, $db, 127);
} else {
$color_t = ImageColorAllocate($im_, $dr, $dv, $db);
}
imagefill($im_, 0, 0, $color_t);
//??
//$dist = abs($trait);
$transp_x = false;
if ($image["format_source"] == "jpg") {
$im_ =& $im;
} else {
for ($x = 0; $x < $x_i; $x++) {
for ($y = 0; $y < $y_i; $y++) {
$rgb = ImageColorAt($im, $x, $y);
$a = $rgb >> 24 & 0xff;
$r = $rgb >> 16 & 0xff;
$g = $rgb >> 8 & 0xff;
$b = $rgb & 0xff;
$a = (127 - $a) / 127;
if ($a == 1) {
// Limiter calculs
$r = $r;
$g = $g;
$b = $b;
} else {
if ($a == 0) {
// Limiter calculs
$r = $dr;
$g = $dv;
$b = $db;
$transp_x = $x;
// Memoriser un point transparent
$transp_y = $y;
} else {
$r = round($a * $r + $dr * (1 - $a));
$g = round($a * $g + $dv * (1 - $a));
$b = round($a * $b + $db * (1 - $a));
}
}
$a = (1 - $a) * 127;
$color = ImageColorAllocateAlpha($im_, $r, $g, $b, $a);
imagesetpixel($im_, $x, $y, $color);
}
}
}
// passer en palette si besoin
if ($format == 'gif' or $format == 'png' and $qualite !== 0) {
// creer l'image finale a palette
// (on recycle l'image initiale si possible, sinon on en recree une)
if ($im === $im_) {
$im = imagecreatetruecolor($x_i, $y_i);
}
@imagetruecolortopalette($im, true, $qualite);
//$im = imagecreate($x_i, $y_i);
// copier l'image true color vers la palette
imagecopy($im, $im_, 0, 0, 0, 0, $x_i, $y_i);
// matcher les couleurs au mieux par rapport a l'image initiale
// si la fonction est disponible (php>=4.3)
if (function_exists('imagecolormatch')) {
@imagecolormatch($im_, $im);
}
if ($format == 'gif' && $transparence && $transp_x) {
$color_t = ImagecolorAt($im, $transp_x, $transp_y);
if ($format == "gif" && $transparence) {
@imagecolortransparent($im, $color_t);
}
}
// produire le resultat
_image_gd_output($im, $image, $qualite);
} else {
_image_gd_output($im_, $image, $qualite);
}
if ($im !== $im_) {
imagedestroy($im);
}
imagedestroy($im_);
}
return _image_ecrire_tag($image, array('src' => $dest));
}
示例5: imagecreatetruecolor
<?php
$im = imagecreatetruecolor(5, 5);
$im2 = imagecreate(5, 5);
imagecolormatch($im, $im2);
echo "ok\n";
imagedestroy($im);
示例6: get
public function get($type = 'png', $interlace = false, $quality = NULL, $filter = PNG_ALL_FILTERS)
{
$type = strtolower($type);
if ($interlace === true) {
imageinterlace($this->image, 1);
}
ob_start();
switch ($type) {
case 'png':
$quality = $quality === NULL ? 9 : max(0, min(9, (int) $quality));
imagepng($this->image, NULL, $quality, $filter);
break;
case 'jpeg':
$quality = $quality === NULL ? 100 : max(0, min(100, (int) $quality));
imagejpeg($this->image, NULL, $quality);
break;
case 'gif':
$quality = $quality === NULL ? 255 : max(0, min(255, (int) $quality));
$temp = imagecreatetruecolor($this->width, $this->height);
imagecopy($temp, $this->image, 0, 0, 0, 0, $this->width, $this->height);
imagetruecolortopalette($temp, false, $quality);
imagecolormatch($this->image, $temp);
imagegif($temp);
break;
}
return trim(ob_get_clean());
}
示例7: match
public function match($sourceImage = '')
{
if (!is_resource($sourceImage)) {
return Error::set(lang('Error', 'resourceParameter', '1.(sourceImage)'));
}
imagecolormatch($this->canvas, $sourceImage);
return $this;
}
示例8: asPalette
/**
* @see WideImage_Image#asPalette($nColors, $dither, $matchPalette)
*/
function asPalette($nColors = 255, $dither = null, $matchPalette = true)
{
$nColors = intval($nColors);
if ($nColors < 1) {
$nColors = 1;
} elseif ($nColors > 255) {
$nColors = 255;
}
if ($dither === null) {
$dither = $this->isTransparent();
}
$temp = $this->copy();
imagetruecolortopalette($temp->handle, $dither, $nColors);
if ($matchPalette == true && function_exists('imagecolormatch')) {
imagecolormatch($this->handle, $temp->handle);
}
// The code below isn't working properly; it corrupts transparency on some palette->tc->palette conversions.
// Why is this code here?
/*
if ($this->isTransparent())
{
$trgb = $this->getTransparentColorRGB();
$tci = $temp->getClosestColor($trgb);
$temp->setTransparentColor($tci);
}
/**/
$temp->releaseHandle();
return new WideImage_PaletteImage($temp->handle);
}
示例9: ImageTrueColorToPalette2
public function ImageTrueColorToPalette2(&$image, $dither, $ncolors)
{
// http://www.php.net/manual/en/function.imagetruecolortopalette.php
// zmorris at zsculpt dot com (17-Aug-2004 06:58)
$width = imagesx($image);
$height = imagesy($image);
$image_copy = imagecreatetruecolor($width, $height);
//imagecopymerge($image_copy, $image, 0, 0, 0, 0, $width, $height, 100);
imagecopy($image_copy, $image, 0, 0, 0, 0, $width, $height);
imagetruecolortopalette($image, $dither, $ncolors);
imagecolormatch($image_copy, $image);
imagedestroy($image_copy);
return true;
}
示例10: generate_thumbnails
function generate_thumbnails($source, $targets_and_constraints, $target_format, $thumbnail_quality)
{
$files_created_in_operation = array();
list($width, $height) = getimagesize($source);
$ok = false;
if ($width > 0) {
$pixel_size_buffer = 1.25;
$max_bytes = $comicpress_manager->convert_short_size_string_to_bytes(ini_get('memory_limit'));
if ($max_bytes > 0) {
$max_thumb_size = 0;
foreach ($targets_and_constraints as $target_and_constraint) {
list($target, $constraint) = $target_and_constraint;
$width_to_use = $constraint['width'];
$archive_comic_height = (int) ($width_to_use * $height / $width);
$max_thumb_size = max($width_to_use * $archive_comic_height * 4, $max_thumb_size);
}
$input_image_size = $width * $height * 4;
if (strtolower(pathinfo($input, PATHINFO_EXTENSION)) == "gif") {
$input_image_size *= 2;
}
$recommended_size = ($input_image_size + $max_thumb_size) * $pixel_size_buffer;
if (function_exists('memory_get_usage')) {
$recommended_size += memory_get_usage();
}
if ($recommended_size > $max_bytes) {
$comicpress_manager->warnings[] = sprintf(__("<strong>You don't have enough memory available to PHP and GD to process this file.</strong> You should <strong>set your PHP <tt>memory_size</tt></strong> to at least <strong><tt>%sM</tt></strong> and try again. For more information, read the ComicPress Manager FAQ.", 'comicpress-manager'), (int) ($recommended_size / (1024 * 1024)));
return false;
}
}
foreach ($targets_and_constraints as $target_and_constraint) {
list($target, $constraint) = $target_and_constraint;
$width_to_use = $constraint['width'];
$archive_comic_height = (int) ($width_to_use * $height / $width);
$pathinfo = pathinfo($source);
$thumb_image = imagecreatetruecolor($width_to_use, $archive_comic_height);
imagealphablending($thumb_image, true);
switch (strtolower($pathinfo['extension'])) {
case "jpg":
case "jpeg":
$comic_image = imagecreatefromjpeg($source);
break;
case "gif":
$is_gif = true;
$temp_comic_image = imagecreatefromgif($source);
list($width, $height) = getimagesize($input);
$comic_image = imagecreatetruecolor($width, $height);
imagecopy($comic_image, $temp_comic_image, 0, 0, 0, 0, $width, $height);
imagedestroy($temp_comic_image);
break;
case "png":
$comic_image = imagecreatefrompng($source);
break;
default:
return false;
}
imagealphablending($comic_image, true);
if ($is_palette = !imageistruecolor($comic_image)) {
$number_of_colors = imagecolorstotal($comic_image);
}
imagecopyresampled($thumb_image, $comic_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, $width, $height);
$ok = true;
@touch($target);
if (file_exists($target)) {
@unlink($target);
switch (strtolower($target_format)) {
case "jpg":
case "jpeg":
if (imagetypes() & IMG_JPG) {
@imagejpeg($thumb_image, $target, $comicpress_manager->get_cpm_option("cpm-thumbnail-quality"));
} else {
return false;
}
break;
case "gif":
if (imagetypes() & IMG_GIF) {
if (function_exists('imagecolormatch')) {
$temp_comic_image = imagecreate($width_to_use, $archive_comic_height);
imagecopymerge($temp_comic_image, $thumb_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, 100);
imagecolormatch($thumb_image, $temp_comic_image);
@imagegif($temp_comic_image, $target);
imagedestroy($temp_comic_image);
} else {
@imagegif($thumb_image, $target);
}
} else {
return false;
}
break;
case "png":
if (imagetypes() & IMG_PNG) {
if ($is_palette) {
imagetruecolortopalette($thumb_image, true, $number_of_colors);
}
@imagepng($thumb_image, $target, 9);
} else {
return false;
}
break;
default:
return false;
//.........这里部分代码省略.........
示例11: match
public function match($sourceImage) : InternalGD
{
if (!is_resource($sourceImage)) {
throw new InvalidArgumentException('Error', 'resourceParameter', '1.($sourceImage)');
}
imagecolormatch($this->canvas, $sourceImage);
return $this;
}
示例12: asPalette
/**
* @see GDImage_Image#asPalette($nColors, $dither, $matchPalette)
*/
function asPalette($nColors = 255, $dither = null, $matchPalette = true)
{
$nColors = intval($nColors);
if ($nColors < 1) {
$nColors = 1;
} elseif ($nColors > 255) {
$nColors = 255;
}
if ($dither === null) {
$dither = $this->isTransparent();
}
$temp = $this->copy();
imagetruecolortopalette($temp->handle, $dither, $nColors);
if ($matchPalette == true && function_exists('imagecolormatch')) {
imagecolormatch($this->handle, $temp->handle);
}
$temp->releaseHandle();
return new GDImage_PaletteImage($temp->handle);
}
示例13: imagecreatetruecolor
<?php
$ima = imagecreatetruecolor(110, 20);
$background_color = imagecolorallocate($ima, 0, 0, 0);
var_dump(imagecolormatch($ima));
示例14: cpm_write_thumbnail
//.........这里部分代码省略.........
}
if ($recommended_size > $max_bytes) {
$cpm_config->warnings[] = sprintf(__("<strong>You don't have enough memory available to PHP and GD to process this file.</strong> You should <strong>set your PHP <tt>memory_size</tt></strong> to at least <strong><tt>%sM</tt></strong> and try again. For more information, read the ComicPress Manager FAQ.", 'comicpress-manager'), (int) ($recommended_size / (1024 * 1024)));
return false;
}
}
foreach ($write_targets as $type => $target) {
$width_to_use = isset($cpm_config->properties["{$type}_comic_width"]) ? $cpm_config->properties["{$type}_comic_width"] : $cpm_config->properties['archive_comic_width'];
if ($width_to_use < $width) {
$archive_comic_height = (int) ($width_to_use * $height / $width);
$pathinfo = pathinfo($input);
$thumb_image = imagecreatetruecolor($width_to_use, $archive_comic_height);
imagealphablending($thumb_image, true);
switch (strtolower($pathinfo['extension'])) {
case "jpg":
case "jpeg":
$comic_image = imagecreatefromjpeg($input);
break;
case "gif":
$is_gif = true;
$temp_comic_image = imagecreatefromgif($input);
list($width, $height) = getimagesize($input);
$comic_image = imagecreatetruecolor($width, $height);
imagecopy($comic_image, $temp_comic_image, 0, 0, 0, 0, $width, $height);
imagedestroy($temp_comic_image);
break;
case "png":
$comic_image = imagecreatefrompng($input);
break;
default:
return false;
}
imagealphablending($comic_image, true);
if ($is_palette = !imageistruecolor($comic_image)) {
$number_of_colors = imagecolorstotal($comic_image);
}
imagecopyresampled($thumb_image, $comic_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, $width, $height);
$ok = true;
@touch($target);
if (file_exists($target)) {
@unlink($target);
switch (strtolower($target_format)) {
case "jpg":
case "jpeg":
if (imagetypes() & IMG_JPG) {
@imagejpeg($thumb_image, $target, cpm_option("cpm-thumbnail-quality"));
} else {
return false;
}
break;
case "gif":
if (imagetypes() & IMG_GIF) {
if (function_exists('imagecolormatch')) {
$temp_comic_image = imagecreate($width_to_use, $archive_comic_height);
imagecopymerge($temp_comic_image, $thumb_image, 0, 0, 0, 0, $width_to_use, $archive_comic_height, 100);
imagecolormatch($thumb_image, $temp_comic_image);
@imagegif($temp_comic_image, $target);
imagedestroy($temp_comic_image);
} else {
@imagegif($thumb_image, $target);
}
} else {
return false;
}
break;
case "png":
if (imagetypes() & IMG_PNG) {
if ($is_palette) {
imagetruecolortopalette($thumb_image, true, $number_of_colors);
}
@imagepng($thumb_image, $target, 9);
} else {
return false;
}
break;
default:
return false;
}
}
} else {
copy($input, $target);
}
if (!file_exists($target)) {
$ok = false;
} else {
@chmod($target, CPM_FILE_UPLOAD_CHMOD);
$files_created_in_operation[] = $target;
}
imagedestroy($comic_image);
imagedestroy($thumb_image);
}
} else {
$ok = false;
}
return $ok ? $files_created_in_operation : false;
}
}
}
return null;
}
示例15: getImage
//.........这里部分代码省略.........
} elseif ($intWidth) {
$intHeight = ceil($objFile->height * $width / $objFile->width);
$strNewImage = imagecreatetruecolor($intWidth, $intHeight);
} elseif ($intHeight) {
$intWidth = ceil($objFile->width * $height / $objFile->height);
$strNewImage = imagecreatetruecolor($intWidth, $intHeight);
}
$arrGdinfo = gd_info();
$strGdVersion = preg_replace('/[^0-9\\.]+/', '', $arrGdinfo['GD Version']);
switch ($objFile->extension) {
case 'gif':
if ($arrGdinfo['GIF Read Support']) {
$strSourceImage = imagecreatefromgif(TL_ROOT . '/' . $image);
$intTranspIndex = imagecolortransparent($strSourceImage);
// Handle transparency
if ($intTranspIndex >= 0 && $intTranspIndex < imagecolorstotal($strSourceImage)) {
$arrColor = imagecolorsforindex($strSourceImage, $intTranspIndex);
$intTranspIndex = imagecolorallocate($strNewImage, $arrColor['red'], $arrColor['green'], $arrColor['blue']);
imagefill($strNewImage, 0, 0, $intTranspIndex);
imagecolortransparent($strNewImage, $intTranspIndex);
}
}
break;
case 'jpg':
case 'jpeg':
if ($arrGdinfo['JPG Support'] || $arrGdinfo['JPEG Support']) {
$strSourceImage = imagecreatefromjpeg(TL_ROOT . '/' . $image);
}
break;
case 'png':
if ($arrGdinfo['PNG Support']) {
$strSourceImage = imagecreatefrompng(TL_ROOT . '/' . $image);
// Handle transparency (GDlib >= 2.0 required)
if (version_compare($strGdVersion, '2.0', '>=')) {
imagealphablending($strNewImage, false);
$intTranspIndex = imagecolorallocatealpha($strNewImage, 0, 0, 0, 127);
imagefill($strNewImage, 0, 0, $intTranspIndex);
imagesavealpha($strNewImage, true);
}
}
break;
}
// The new image could not be created
if (!$strSourceImage) {
$this->log('Image "' . $image . '" could not be processed', 'Controller getImage()', TL_ERROR);
return null;
}
imagecopyresampled($strNewImage, $strSourceImage, $intPositionX, $intPositionY, 0, 0, $intWidth, $intHeight, $objFile->width, $objFile->height);
// Fallback to PNG if GIF ist not supported
if ($objFile->extension == 'gif' && !$arrGdinfo['GIF Create Support']) {
$objFile->extension = 'png';
}
// Create the new image
switch ($objFile->extension) {
case 'gif':
imagegif($strNewImage, TL_ROOT . '/' . $strCacheName);
break;
case 'jpg':
case 'jpeg':
imagejpeg($strNewImage, TL_ROOT . '/' . $strCacheName, !$GLOBALS['TL_CONFIG']['jpgQuality'] ? 80 : $GLOBALS['TL_CONFIG']['jpgQuality']);
break;
case 'png':
// Optimize non-truecolor images (see #2426)
if (version_compare($strGdVersion, '2.0', '>=') && function_exists('imagecolormatch') && !imageistruecolor($strSourceImage)) {
// TODO: make it work with transparent images, too
if (imagecolortransparent($strSourceImage) == -1) {
$intColors = imagecolorstotal($strSourceImage);
// Convert to a palette image
// @see http://www.php.net/manual/de/function.imagetruecolortopalette.php#44803
if ($intColors > 0 && $intColors < 256) {
$wi = imagesx($strNewImage);
$he = imagesy($strNewImage);
$ch = imagecreatetruecolor($wi, $he);
imagecopymerge($ch, $strNewImage, 0, 0, 0, 0, $wi, $he, 100);
imagetruecolortopalette($strNewImage, false, $intColors);
imagecolormatch($ch, $strNewImage);
imagedestroy($ch);
}
}
}
imagepng($strNewImage, TL_ROOT . '/' . $strCacheName);
break;
}
// Destroy the temporary images
imagedestroy($strSourceImage);
imagedestroy($strNewImage);
// Resize the original image
if ($target) {
$this->import('Files');
$this->Files->rename($strCacheName, $target);
return $target;
}
// Set the file permissions when the Safe Mode Hack is used
if ($GLOBALS['TL_CONFIG']['useFTP']) {
$this->import('Files');
$this->Files->chmod($strCacheName, 0644);
}
// Return the path to new image
return $strCacheName;
}