本文整理汇总了PHP中imagetruecolortopalette函数的典型用法代码示例。如果您正苦于以下问题:PHP imagetruecolortopalette函数的具体用法?PHP imagetruecolortopalette怎么用?PHP imagetruecolortopalette使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imagetruecolortopalette函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: changeBackground
function changeBackground($im, $red, $green, $blue)
{
imagetruecolortopalette($im, false, 255);
$ig = imagecolorat($im, 0, 0);
imagecolorset($im, $ig, $red, $green, $blue);
return $im;
}
示例2: 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;
}
示例3: execute
function execute()
{
$img =& $this->image->getImage();
if (!($t = imagecolorstotal($img))) {
$t = 256;
imagetruecolortopalette($img, true, $t);
}
$total = imagecolorstotal($img);
for ($i = 0; $i < $total; $i++) {
$index = imagecolorsforindex($img, $i);
$red = $index["red"] * 0.393 + $index["green"] * 0.769 + $index["blue"] * 0.189;
$green = $index["red"] * 0.349 + $index["green"] * 0.6860000000000001 + $index["blue"] * 0.168;
$blue = $index["red"] * 0.272 + $index["green"] * 0.534 + $index["blue"] * 0.131;
if ($red > 255) {
$red = 255;
}
if ($green > 255) {
$green = 255;
}
if ($blue > 255) {
$blue = 255;
}
imagecolorset($img, $i, $red, $green, $blue);
}
}
示例4: execute
/**
* Reduces colors of a given image
*
* @param \Intervention\Image\Image $image
* @return boolean
*/
public function execute($image)
{
$count = $this->argument(0)->value();
$matte = $this->argument(1)->value();
// get current image size
$size = $image->getSize();
// create empty canvas
$resource = imagecreatetruecolor($size->width, $size->height);
// define matte
if (is_null($matte)) {
$matte = imagecolorallocatealpha($resource, 255, 255, 255, 127);
} else {
$matte = $image->getDriver()->parseColor($matte)->getInt();
}
// fill with matte and copy original image
imagefill($resource, 0, 0, $matte);
// set transparency
imagecolortransparent($resource, $matte);
// copy original image
imagecopy($resource, $image->getCore(), 0, 0, 0, 0, $size->width, $size->height);
if (is_numeric($count) && $count <= 256) {
// decrease colors
imagetruecolortopalette($resource, true, $count);
}
// set new resource
$image->setCore($resource);
return true;
}
示例5: create_new_rsrc
private function create_new_rsrc($mimetype, $width, $height)
{
switch ($mimetype) {
case 'image/jpeg':
$_rsrc = imagecreatetruecolor($width, $height);
return $_rsrc;
case 'image/png':
// from supersizer
$_rsrc = imagecreatetruecolor($width, $height);
$color = imagecolorallocatealpha($_rsrc, 0, 0, 0, 127);
imagecolortransparent($_rsrc, $color);
$this->_transparent = $color;
return $_rsrc;
case 'image/gif':
$_rsrc = imagecreatetruecolor($width, $height);
imagetruecolortopalette($_rsrc, true, 256);
imagealphablending($_rsrc, false);
imagesavealpha($_rsrc, true);
$transparent = imagecolorallocatealpha($_rsrc, 255, 255, 255, 127);
imagefilledrectangle($_rsrc, 0, 0, $width, $height, $transparent);
imagecolortransparent($_rsrc, $transparent);
return $_rsrc;
default:
throw new Exception('Cannot create new image of type ' . $mimetype);
}
}
示例6: 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);
}
示例7: execute
public function execute()
{
$this->media->asImage();
$img = $this->media->getImage();
if (!($t = imagecolorstotal($img))) {
$t = 256;
imagetruecolortopalette($img, true, $t);
}
$total = imagecolorstotal($img);
for ($i = 0; $i < $total; ++$i) {
$index = imagecolorsforindex($img, $i);
$red = $index['red'] * 0.393 + $index['green'] * 0.769 + $index['blue'] * 0.189;
$green = $index['red'] * 0.349 + $index['green'] * 0.6860000000000001 + $index['blue'] * 0.168;
$blue = $index['red'] * 0.272 + $index['green'] * 0.534 + $index['blue'] * 0.131;
if ($red > 255) {
$red = 255;
}
if ($green > 255) {
$green = 255;
}
if ($blue > 255) {
$blue = 255;
}
imagecolorset($img, $i, $red, $green, $blue);
}
$this->media->setImage($img);
}
示例8: 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);
}
示例9: run
public function run($file)
{
$res = $this->open_image($file);
if ($res != TRUE) {
return FALSE;
}
$this->image_progressive = isset($this->settings['field_settings']['progressive_jpeg']) === TRUE && $this->settings['field_settings']['progressive_jpeg'] == 'yes' ? TRUE : FALSE;
$this->Ageimage = array(1, 0, 60);
imagetruecolortopalette($this->EE->channel_images->image, 1, 256);
for ($c = 0; $c < 256; $c++) {
$col = imagecolorsforindex($this->EE->channel_images->image, $c);
$new_col = floor($col['red'] * 0.2125 + $col['green'] * 0.7154 + $col['blue'] * 0.0721);
$noise = rand(-$this->Ageimage[1], $this->Ageimage[1]);
if ($this->Ageimage[2] > 0) {
$r = $new_col + $this->Ageimage[2] + $noise;
$g = floor($new_col + $this->Ageimage[2] / 1.86 + $noise);
$b = floor($new_col + $this->Ageimage[2] / -3.48 + $noise);
} else {
$r = $new_col + $noise;
$g = $new_col + $noise;
$b = $new_col + $noise;
}
imagecolorset($this->EE->channel_images->image, $c, max(0, min(255, $r)), max(0, min(255, $g)), max(0, min(255, $b)));
}
$this->save_image($file);
return TRUE;
}
示例10: render
/**
* @return ZipInterface
*/
public function render()
{
$pathThumbnail = $this->getPresentation()->getPresentationProperties()->getThumbnailPath();
if ($pathThumbnail) {
// Size : 128x128 pixel
// PNG : 8bit, non-interlaced with full alpha transparency
$gdImage = imagecreatefromstring(file_get_contents($pathThumbnail));
if ($gdImage) {
list($width, $height) = getimagesize($pathThumbnail);
$gdRender = imagecreatetruecolor(128, 128);
$colorBgAlpha = imagecolorallocatealpha($gdRender, 0, 0, 0, 127);
imagecolortransparent($gdRender, $colorBgAlpha);
imagefill($gdRender, 0, 0, $colorBgAlpha);
imagecopyresampled($gdRender, $gdImage, 0, 0, 0, 0, 128, 128, $width, $height);
imagetruecolortopalette($gdRender, false, 255);
imagesavealpha($gdRender, true);
ob_start();
imagepng($gdRender);
$imageContents = ob_get_contents();
ob_end_clean();
imagedestroy($gdRender);
imagedestroy($gdImage);
$this->getZip()->addFromString('Thumbnails/thumbnail.png', $imageContents);
}
}
return $this->getZip();
}
示例11: 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);
}
示例12: getPalettizedGdResource
/**
* @param resource $resource
* @return resource
*/
public function getPalettizedGdResource($resource)
{
imagetruecolortopalette($resource, true, 255);
if (-1 == ($trans = imagecolortransparent($resource))) {
$trans = imagecolorallocate($resource, 255, 255, 255);
imagecolortransparent($resource, $trans);
}
return $resource;
}
示例13: 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;
}
示例14: _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);
}
示例15: build_ycon
function build_ycon($filename, $seed = '', $size = '')
{
$hash = md5($seed);
$image = ycon($hash, $size, 255, 255, 255);
imagetruecolortopalette($image, false, 64);
// header('Content-type: image/png');
imagepng($image, $filename);
imagedestroy($image);
return true;
}