本文整理汇总了PHP中imageistruecolor函数的典型用法代码示例。如果您正苦于以下问题:PHP imageistruecolor函数的具体用法?PHP imageistruecolor怎么用?PHP imageistruecolor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imageistruecolor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: analyze
/**
* {@inheritdoc}
*/
public function analyze($filename)
{
$imageSize = @getimagesize($filename);
if ($imageSize === false) {
throw new UnsupportedFileException('File type not supported.');
}
$imageInfo = new ImageInfo();
$type = null;
$colors = null;
if ($imageSize[2] === IMAGETYPE_JPEG) {
$gd = imagecreatefromjpeg($filename);
$type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE';
$colors = imagecolorstotal($gd);
imagedestroy($gd);
} elseif ($imageSize[2] === IMAGETYPE_GIF) {
$gd = imagecreatefromgif($filename);
$type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE';
$colors = imagecolorstotal($gd);
imagedestroy($gd);
} elseif ($imageSize[2] === IMAGETYPE_PNG) {
$gd = imagecreatefrompng($filename);
$type = imageistruecolor($gd) ? 'TRUECOLOR' : 'PALETTE';
$colors = imagecolorstotal($gd);
imagedestroy($gd);
}
$imageInfo->setAnalyzer(get_class($this))->setSize($imageSize[0], $imageSize[1])->setResolution(null, null)->setUnits(null)->setFormat($this->mapFormat($imageSize[2]))->setColors($colors)->setType($type)->setColorspace(!empty($imageSize['channels']) ? $imageSize['channels'] === 4 ? 'CMYK' : 'RGB' : 'RGB')->setDepth($imageSize['bits'])->setCompression(null)->setQuality(null)->setProfiles(null);
return $imageInfo;
}
示例2: resize
public function resize($maxW = null, $maxH = null, $canEnlarge = false)
{
$src = $this->_rawImage;
if ($maxW === null && $maxH === null) {
return $src;
}
if (imageistruecolor($src)) {
imageAlphaBlending($src, true);
imageSaveAlpha($src, true);
}
$srcW = imagesx($src);
$srcH = imagesy($src);
$width = $maxW && ($canEnlarge || $maxW <= $srcW) ? $maxW : $srcW;
$height = $maxH && ($canEnlarge || $maxH <= $srcW) ? $maxH : $srcH;
$ratio_orig = $srcW / $srcH;
if ($width / $height > $ratio_orig) {
$width = $height * $ratio_orig;
} else {
$height = $width / $ratio_orig;
}
$maxW = $maxW ? $maxW : $width;
$maxH = $maxH ? $maxH : $height;
$img = imagecreatetruecolor($maxW, $maxH);
$trans_colour = imagecolorallocatealpha($img, 0, 0, 0, 127);
imagefill($img, 0, 0, $trans_colour);
$offsetX = ($maxW - $width) / 2;
$offsetY = ($maxH - $height) / 2;
imagecopyresampled($img, $src, $offsetX, $offsetY, 0, 0, $width, $height, $srcW, $srcH);
imagealphablending($img, true);
imagesavealpha($img, true);
return $img;
}
示例3: convert
/**
* Convert an image.
*
* @param img.Image image
* @return bool
* @throws img.ImagingException
*/
public function convert($image)
{
// Create temporary variable as local variable access is faster
// than member variable access.
$handle = $image->handle;
if (imageistruecolor($handle)) {
$l = [];
$h = $image->getHeight();
$w = $image->getWidth();
for ($y = 0; $y < $h; $y++) {
for ($x = 0; $x < $w; $x++) {
$rgb = imagecolorat($handle, $x, $y);
if (!isset($l[$rgb])) {
$g = 0.299 * ($rgb >> 16 & 0xff) + 0.587 * ($rgb >> 8 & 0xff) + 0.114 * ($rgb & 0xff);
$l[$rgb] = imagecolorallocate($handle, $g, $g, $g);
}
imagesetpixel($handle, $x, $y, $l[$rgb]);
}
}
unset($l);
} else {
for ($i = 0, $t = imagecolorstotal($handle); $i < $t; $i++) {
$c = imagecolorsforindex($handle, $i);
$g = 0.299 * $c['red'] + 0.587 * $c['green'] + 0.114 * $c['blue'];
imagecolorset($handle, $i, $g, $g, $g);
}
}
}
示例4: fit
/**
* Fit small image to specified bound
*
* @param string $src
* @param string $dest
* @param int $width
* @param int $height
* @return bool
*/
public function fit($src, $dest, $width, $height)
{
// Calculate
$size = getimagesize($src);
$ratio = max($width / $size[0], $height / $size[1]);
$old_width = $size[0];
$old_height = $size[1];
$new_width = intval($old_width * $ratio);
$new_height = intval($old_height * $ratio);
// Resize
@ini_set('memory_limit', apply_filters('image_memory_limit', WP_MAX_MEMORY_LIMIT));
$image = imagecreatefromstring(file_get_contents($src));
$new_image = wp_imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height);
if (IMAGETYPE_PNG == $size[2] && function_exists('imageistruecolor') && !imageistruecolor($image)) {
imagetruecolortopalette($new_image, false, imagecolorstotal($image));
}
// Destroy old image
imagedestroy($image);
// Save
switch ($size[2]) {
case IMAGETYPE_GIF:
$result = imagegif($new_image, $dest);
break;
case IMAGETYPE_PNG:
$result = imagepng($new_image, $dest);
break;
default:
$result = imagejpeg($new_image, $dest);
break;
}
imagedestroy($new_image);
return $result;
}
示例5: 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;
}
return imagetruecolortopalette($image->handle, $this->dither, $this->ncolors);
}
示例6: testGdResourceToTruecolor
public function testGdResourceToTruecolor()
{
$resource = imagecreate(10, 10);
$this->assertFalse(imageistruecolor($resource));
Helper::gdResourceToTruecolor($resource);
$this->assertTrue(imageistruecolor($resource));
}
示例7: output
/**
* Output an image. If the image is true-color, it will be converted
* to a paletted image first using imagetruecolortopalette().
*
* @param resource handle
* @return bool
*/
public function output($handle)
{
if (imageistruecolor($handle)) {
imagetruecolortopalette($handle, $this->dither, $this->ncolors);
}
return imagegif($handle);
}
示例8: load
/**
* {@inheritdoc}
*/
protected function load()
{
// Return immediately if the image file is not valid.
if (!$this->isValid()) {
return FALSE;
}
switch ($this->getType()) {
case GDToolkitWebP::IMAGETYPE_WEBP:
$function = 'imagecreatefromwebp';
break;
default:
$function = 'imagecreatefrom' . image_type_to_extension($this->getType(), FALSE);
}
if (function_exists($function) && ($resource = $function($this->getImage()->getSource()))) {
$this->setResource($resource);
if (imageistruecolor($resource)) {
return TRUE;
} else {
// Convert indexed images to true color, so that filters work
// correctly and don't result in unnecessary dither.
$new_image = $this->createTmp($this->getType(), imagesx($resource), imagesy($resource));
if ($ret = (bool) $new_image) {
imagecopy($new_image, $resource, 0, 0, 0, 0, imagesx($resource), imagesy($resource));
imagedestroy($resource);
$this->setResource($new_image);
}
return $ret;
}
}
return FALSE;
}
示例9: imageflip
function imageflip(&$image, $x = 0, $y = 0, $width = null, $height = null)
{
if ($width < 1) {
$width = imagesx($image);
}
if ($height < 1) {
$height = imagesy($image);
}
// Truecolor provides better results, if possible.
if (function_exists('imageistruecolor') && imageistruecolor($image)) {
$tmp = imagecreatetruecolor(1, $height);
} else {
$tmp = imagecreate(1, $height);
}
$x2 = $x + $width - 1;
for ($i = (int) floor(($width - 1) / 2); $i >= 0; $i--) {
// Backup right stripe.
imagecopy($tmp, $image, 0, 0, $x2 - $i, $y, 1, $height);
// Copy left stripe to the right.
imagecopy($image, $image, $x2 - $i, $y, $x + $i, $y, 1, $height);
// Copy backuped right stripe to the left.
imagecopy($image, $tmp, $x + $i, $y, 0, 0, 1, $height);
}
imagedestroy($tmp);
return true;
}
示例10: testConstructMethodAlwaysConvertResourceTrueColor
public function testConstructMethodAlwaysConvertResourceTrueColor()
{
$resource = imagecreatefromgif(__DIR__ . '/../../../data/lisbon1.gif');
$this->assertFalse(imageistruecolor($resource));
$adapter = new GdAdapter($resource);
$this->assertTrue(imageistruecolor($adapter->getResource()));
}
示例11: get_hexcolor
function get_hexcolor($im, $c)
{
if (imageistruecolor($im)) {
return $c;
}
$colors = imagecolorsforindex($im, $c);
return ($colors['red'] << 16) + ($colors['green'] << 8) + $colors['blue'];
}
示例12: dither
/**
* Convert the image to 2 colours with dithering.
*/
protected function dither()
{
if (!imageistruecolor($this->image)) {
imagepalettetotruecolor($this->image);
}
imagefilter($this->image, IMG_FILTER_GRAYSCALE);
imagetruecolortopalette($this->image, true, 2);
}
示例13: ReadSourceFile
function ReadSourceFile($image_file_name)
{
$this->DestroyImage();
$this->ImageStatsSRC = @getimagesize($image_file_name);
if ($this->ImageStatsSRC[2] == 3) {
$this->ImageStatsSRC[2] = IMG_PNG;
}
$this->ImageMimeType = $this->ImageStatsSRC['mime'];
$this->ImageTypeNo = $this->ImageStatsSRC[2];
switch ($this->ImageTypeNo) {
case IMG_GIF:
if (!(imagetypes() & $this->ImageTypeNo)) {
return false;
}
$this->ImageTypeExt = '.gif';
$image_read_func = 'imagecreatefromgif';
break;
case IMG_JPG:
if (!(imagetypes() & $this->ImageTypeNo)) {
return false;
}
if (function_exists('exif_read_data')) {
$this->exif_get_data($image_file_name);
}
$this->ImageTypeExt = '.jpg';
$image_read_func = 'imagecreatefromjpeg';
break;
case IMG_PNG:
if (!(imagetypes() & $this->ImageTypeNo)) {
return false;
}
$this->ImageTypeExt = '.png';
$image_read_func = 'imagecreatefrompng';
break;
default:
return false;
}
$this->ImageID = $image_read_func($image_file_name);
if (function_exists('imageistruecolor')) {
if (imageistruecolor($this->ImageID)) {
if (function_exists('imageantialias')) {
imageantialias($this->ImageID, true);
}
imagealphablending($this->ImageID, false);
if (function_exists('imagesavealpha')) {
$this->Alpha = true;
imagesavealpha($this->ImageID, true);
}
}
}
$this->ChangeFlag = true;
if ($this->ImageID) {
return true;
} else {
return false;
}
}
示例14: image_resize
/**
* This function is almost equal to the image_resize (native function of wordpress)
*/
function image_resize($file, $max_w, $max_h, $crop = false, $far = false, $iar = false, $dest_path = null, $jpeg_quality = 90)
{
$image = wp_load_image($file);
if (!is_resource($image)) {
return new WP_Error('error_loading_image', $image);
}
$size = @getimagesize($file);
if (!$size) {
return new WP_Error('invalid_image', __('Could not read image size'), $file);
}
list($orig_w, $orig_h, $orig_type) = $size;
$dims = mf_image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop, $far, $iar);
if (!$dims) {
$dims = array(0, 0, 0, 0, $orig_w, $orig_h, $orig_w, $orig_h);
}
list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
$newimage = imagecreatetruecolor($dst_w, $dst_h);
imagealphablending($newimage, false);
imagesavealpha($newimage, true);
$transparent = imagecolorallocatealpha($newimage, 255, 255, 255, 127);
imagefilledrectangle($newimage, 0, 0, $dst_w, $dst_h, $transparent);
imagecopyresampled($newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
// convert from full colors to index colors, like original PNG.
if (IMAGETYPE_PNG == $orig_type && !imageistruecolor($image)) {
imagetruecolortopalette($newimage, false, imagecolorstotal($image));
}
// we don't need the original in memory anymore
imagedestroy($image);
$info = pathinfo($dest_path);
$dir = $info['dirname'];
$ext = $info['extension'];
$name = basename($dest_path, ".{$ext}");
$destfilename = "{$dir}/{$name}.{$ext}";
if (IMAGETYPE_GIF == $orig_type) {
if (!imagegif($newimage, $destfilename)) {
return new WP_Error('resize_path_invalid', __('Resize path invalid'));
}
} elseif (IMAGETYPE_PNG == $orig_type) {
if (!imagepng($newimage, $destfilename)) {
return new WP_Error('resize_path_invalid', __('Resize path invalid'));
}
} else {
// all other formats are converted to jpg
//Todo: add option for use progresive JPG
//imageinterlace($newimage, true); //Progressive JPG
if (!imagejpeg($newimage, $destfilename, apply_filters('jpeg_quality', $jpeg_quality, 'image_resize'))) {
return new WP_Error('resize_path_invalid', __('Resize path invalid'));
}
}
imagedestroy($newimage);
// Set correct file permissions
$stat = stat(dirname($destfilename));
$perms = $stat['mode'] & 0666;
//same permissions as parent folder, strip off the executable bits
@chmod($destfilename, $perms);
return $destfilename;
}
示例15: _save
protected function _save($image, $filename = null, $mime_type = null)
{
global $ewww_debug;
if (!defined('EWWW_IMAGE_OPTIMIZER_DOMAIN')) {
require_once plugin_dir_path(__FILE__) . 'ewww-image-optimizer.php';
}
if (!defined('EWWW_IMAGE_OPTIMIZER_JPEGTRAN')) {
ewww_image_optimizer_init();
}
list($filename, $extension, $mime_type) = $this->get_output_format($filename, $mime_type);
if (!$filename) {
$filename = $this->generate_filename(null, null, $extension);
}
if ('image/gif' == $mime_type) {
if (!$this->make_image($filename, 'imagegif', array($image, $filename))) {
return new WP_Error('image_save_error', __('Image Editor Save Failed'));
}
} elseif ('image/png' == $mime_type) {
// convert from full colors to index colors, like original PNG.
if (function_exists('imageistruecolor') && !imageistruecolor($image)) {
imagetruecolortopalette($image, false, imagecolorstotal($image));
}
if (property_exists('WP_Image_Editor', 'quality')) {
$compression_level = floor((101 - $this->quality) * 0.09);
$ewww_debug .= "png quality = " . $this->quality . "<br>";
} else {
$compression_level = floor((101 - false) * 0.09);
}
if (!$this->make_image($filename, 'imagepng', array($image, $filename, $compression_level))) {
return new WP_Error('image_save_error', __('Image Editor Save Failed'));
}
} elseif ('image/jpeg' == $mime_type) {
if (method_exists($this, 'get_quality')) {
if (!$this->make_image($filename, 'imagejpeg', array($image, $filename, $this->get_quality()))) {
return new WP_Error('image_save_error', __('Image Editor Save Failed'));
}
} else {
if (!$this->make_image($filename, 'imagejpeg', array($image, $filename, apply_filters('jpeg_quality', $this->quality, 'image_resize')))) {
return new WP_Error('image_save_error', __('Image Editor Save Failed'));
}
}
} else {
return new WP_Error('image_save_error', __('Image Editor Save Failed'));
}
// Set correct file permissions
$stat = stat(dirname($filename));
$perms = $stat['mode'] & 0666;
//same permissions as parent folder, strip off the executable bits
@chmod($filename, $perms);
ewww_image_optimizer_aux_images_loop($filename, true);
$ewww_debug = "{$ewww_debug} image editor (gd) saved: {$filename} <br>";
$image_size = filesize($filename);
$ewww_debug = "{$ewww_debug} image editor size: {$image_size} <br>";
ewww_image_optimizer_debug_log();
return array('path' => $filename, 'file' => wp_basename(apply_filters('image_make_intermediate_size', $filename)), 'width' => $this->size['width'], 'height' => $this->size['height'], 'mime-type' => $mime_type);
}