本文整理匯總了PHP中Imagick::setImageBackgroundColor方法的典型用法代碼示例。如果您正苦於以下問題:PHP Imagick::setImageBackgroundColor方法的具體用法?PHP Imagick::setImageBackgroundColor怎麽用?PHP Imagick::setImageBackgroundColor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Imagick
的用法示例。
在下文中一共展示了Imagick::setImageBackgroundColor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: refresh
/**
* @param Thumbnail $thumbnail
* @return void
* @throws Exception\NoThumbnailAvailableException
*/
public function refresh(Thumbnail $thumbnail)
{
try {
$filenameWithoutExtension = pathinfo($thumbnail->getOriginalAsset()->getResource()->getFilename(), PATHINFO_FILENAME);
$temporaryLocalCopyFilename = $thumbnail->getOriginalAsset()->getResource()->createTemporaryLocalCopy();
$documentFile = sprintf(in_array($thumbnail->getOriginalAsset()->getResource()->getFileExtension(), $this->getOption('paginableDocuments')) ? '%s[0]' : '%s', $temporaryLocalCopyFilename);
$width = $thumbnail->getConfigurationValue('width') ?: $thumbnail->getConfigurationValue('maximumWidth');
$height = $thumbnail->getConfigurationValue('height') ?: $thumbnail->getConfigurationValue('maximumHeight');
$im = new \Imagick();
$im->setResolution($this->getOption('resolution'), $this->getOption('resolution'));
$im->readImage($documentFile);
$im->setImageFormat('png');
$im->setImageBackgroundColor('white');
$im->setImageCompose(\Imagick::COMPOSITE_OVER);
$im->setImageAlphaChannel(\Imagick::ALPHACHANNEL_RESET);
$im->thumbnailImage($width, $height, true);
$im->flattenImages();
// Replace flattenImages in imagick 3.3.0
// @see https://pecl.php.net/package/imagick/3.3.0RC2
// $im->mergeImageLayers(\Imagick::LAYERMETHOD_MERGE);
$resource = $this->resourceManager->importResourceFromContent($im->getImageBlob(), $filenameWithoutExtension . '.png');
$im->destroy();
$thumbnail->setResource($resource);
$thumbnail->setWidth($width);
$thumbnail->setHeight($height);
} catch (\Exception $exception) {
$filename = $thumbnail->getOriginalAsset()->getResource()->getFilename();
$sha1 = $thumbnail->getOriginalAsset()->getResource()->getSha1();
$message = sprintf('Unable to generate thumbnail for the given document (filename: %s, SHA1: %s)', $filename, $sha1);
throw new Exception\NoThumbnailAvailableException($message, 1433109652, $exception);
}
}
示例2: create
/**
* (non-PHPdoc)
* @see Imagine\Image\ImagineInterface::create()
*/
public function create(BoxInterface $size, Color $color = null)
{
$width = $size->getWidth();
$height = $size->getHeight();
$color = null !== $color ? $color : new Color('fff');
try {
$pixel = new \ImagickPixel((string) $color);
$pixel->setColorValue(
\Imagick::COLOR_OPACITY,
number_format(abs(round($color->getAlpha() / 100, 1)), 1)
);
$imagick = new \Imagick();
$imagick->newImage($width, $height, $pixel);
$imagick->setImageMatte(true);
$imagick->setImageBackgroundColor($pixel);
$pixel->clear();
$pixel->destroy();
return new Image($imagick);
} catch (\ImagickException $e) {
throw new RuntimeException(
'Could not create empty image', $e->getCode(), $e
);
}
}
示例3: programmatically_create_post
function programmatically_create_post()
{
$url = 'http://widgets.pinterest.com/v3/pidgets/boards/bradleyblose/my-stuff/pins/';
$json_O = json_decode(file_get_contents($url), true);
$id = $json_O['data']['pins'][0]['id'];
$titlelink = 'https://www.pinterest.com/pin/' . $id . '/';
$title = get_title($titlelink);
var_dump($title);
$original = $json_O['data']['pins'][0]['images']['237x']['url'];
$image_url = preg_replace('/237x/', '736x', $original);
$description = $json_O['data']['pins'][0]['description'];
// Initialize the page ID to -1. This indicates no action has been taken.
$post_id = -1;
// Setup the author, slug, and title for the post
$author_id = 1;
$mytitle = get_page_by_title($title, OBJECT, 'post');
var_dump($mytitle);
// If the page doesn't already exist, then create it
if (NULL == get_page_by_title($title, OBJECT, 'post')) {
// Set the post ID so that we know the post was created successfully
$post_id = wp_insert_post(array('comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => $author_id, 'post_name' => $title, 'post_title' => $title, 'post_content' => $description, 'post_status' => 'publish', 'post_type' => 'post'));
//upload featured image
$upload_dir = wp_upload_dir();
$image_data = file_get_contents($image_url);
$filename = basename($image_url);
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $filename;
$path = $upload_dir['path'] . '/';
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
$path = $upload_dir['basedir'] . '/';
}
file_put_contents($file, $image_data);
//edit featured image to correct specs to fit theme
$pngfilename = $filename . '.png';
$targetThumb = $path . '/' . $pngfilename;
$img = new Imagick($file);
$img->scaleImage(250, 250, true);
$img->setImageBackgroundColor('None');
$w = $img->getImageWidth();
$h = $img->getImageHeight();
$img->extentImage(250, 250, ($w - 250) / 2, ($h - 250) / 2);
$img->writeImage($targetThumb);
unlink($file);
//Attach featured image
$wp_filetype = wp_check_filetype($pngfilename, null);
$attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => sanitize_file_name($pngfilename), 'post_content' => '', 'post_status' => 'inherit');
$attach_id = wp_insert_attachment($attachment, $targetThumb, $post_id);
require_once ABSPATH . 'wp-admin/includes/image.php';
$attach_data = wp_generate_attachment_metadata($attach_id, $targetThumb);
wp_update_attachment_metadata($attach_id, $attach_data);
set_post_thumbnail($post_id, $attach_id);
// Otherwise, we'll stop
} else {
// Arbitrarily use -2 to indicate that the page with the title already exists
$post_id = -2;
}
// end if
}
示例4: save
public function save()
{
if (!$this->emptyAttr('id')) {
$ecatalog = R::findOne('ecatalog', 'id=?', [$this->getAttr('id')]);
$ecatalog->updated_at = date('Y-m-d H:i:s');
} else {
$ecatalog = R::dispense('ecatalog');
$ecatalog->created_at = date('Y-m-d H:i:s');
$ecatalog->updated_at = date('Y-m-d H:i:s');
$ecatalog->sort_order = (int) R::getCell("SELECT MAX(sort_order) FROM ecatalog") + 1;
}
$ecatalog->name = $this->getAttr('name');
$ecatalog->is_new = $this->getAttr('is_new');
if (!$this->emptyAttr('pdf') && is_uploaded_file($this->attr['pdf']['tmp_name'])) {
$pdf = $this->getAttr('pdf');
$pdf_path = $this->generateName('ecatalog_pdf_') . '.pdf';
$cover_path = $this->generateName('ecatalog_cover_') . '.jpeg';
$im = new \Imagick($pdf['tmp_name'] . '[0]');
$im->setImageBackgroundColor('white');
// $im = $im->flattenImages();
$im = $im->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
$im->setImageFormat('jpeg');
if ($im->getImageColorspace() == \Imagick::COLORSPACE_CMYK) {
$im->setImageColorspace(\Imagick::COLORSPACE_SRGB);
}
$im->thumbnailImage(512, 0);
$im->writeImage('upload/' . $cover_path);
$im->clear();
$im->destroy();
move_uploaded_file($pdf['tmp_name'], 'upload/' . $pdf_path);
$this->pushDeleteWhenSuccess('upload/' . $ecatalog->pdf_path);
$this->pushDeleteWhenSuccess('upload/' . $ecatalog->cover_path);
$this->pushDeleteWhenFailed('upload/' . $pdf_path);
$this->pushDeleteWhenFailed('upload/' . $cover_path);
$ecatalog->pdf_path = $pdf_path;
$ecatalog->cover_path = $cover_path;
}
$success = R::store($ecatalog);
if ($success) {
$this->handlerSuccess();
} else {
$this->handlerFailed();
}
return $success;
}
示例5: create
public function create(BoxInterface $size, ColorInterface $color = null)
{
$width = $size->getWidth();
$height = $size->getHeight();
$color = self::getColor($color);
try {
$pixel = new \ImagickPixel($color['color']);
$pixel->setColorValue(\Imagick::COLOR_OPACITY, $color['alpha']);
$magick = new \Imagick();
$magick->newImage($width, $height, $pixel);
$magick->setImageMatte(true);
$magick->setImageBackgroundColor($pixel);
$pixel->clear();
$pixel->destroy();
return new RImage($magick, $color['palette'], self::$emptyBag, array($width, $height));
} catch (\Exception $e) {
throw new \Imagine\Exception\RuntimeException("Imagick: Could not create empty image {$e->getMessage()}", $e->getCode(), $e);
}
}
示例6: createImage
/**
* Generate a derivative image with Imagick.
*/
public function createImage($sourcePath, $destPath, $type, $sizeConstraint, $mimeType)
{
$page = (int) $this->getOption('page', 0);
try {
$imagick = new Imagick($sourcePath . '[' . $page . ']');
} catch (ImagickException $e) {
_log("Imagick failed to open the file. Details:\n{$e}", Zend_Log::ERR);
return false;
}
$origX = $imagick->getImageWidth();
$origY = $imagick->getImageHeight();
$imagick->setImagePage($origX, $origY, 0, 0);
$imagick->setBackgroundColor('white');
$imagick->setImageBackgroundColor('white');
$imagick = $imagick->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
if ($type != 'square_thumbnail') {
$imagick->thumbnailImage($sizeConstraint, $sizeConstraint, true);
} else {
// We could use cropThumbnailImage here but it lacks support for
// the gravity setting
if ($origX < $origY) {
$newX = $sizeConstraint;
$newY = $origY * ($sizeConstraint / $origX);
$offsetX = 0;
$offsetY = $this->_getCropOffsetY($newY, $sizeConstraint);
} else {
$newY = $sizeConstraint;
$newX = $origX * ($sizeConstraint / $origY);
$offsetY = 0;
$offsetX = $this->_getCropOffsetX($newX, $sizeConstraint);
}
$imagick->thumbnailImage($newX, $newY);
$imagick->cropImage($sizeConstraint, $sizeConstraint, $offsetX, $offsetY);
$imagick->setImagePage($sizeConstraint, $sizeConstraint, 0, 0);
}
$imagick->writeImage($destPath);
$imagick->clear();
return true;
}
示例7: _prepare_image
/**
* Prepare the image for output, scaling and flattening as required
*
* @since 2.10
* @uses self::$image updates the image in this Imagick object
*
* @param integer zero or new width
* @param integer zero or new height
* @param boolean proportional fit (true) or exact fit (false)
* @param string output MIME type
* @param integer compression quality; 1 - 100
*
* @return void
*/
private static function _prepare_image($width, $height, $best_fit, $type, $quality)
{
if (is_callable(array(self::$image, 'scaleImage'))) {
if (0 < $width && 0 < $height) {
// Both are set; use them as-is
self::$image->scaleImage($width, $height, $best_fit);
} elseif (0 < $width || 0 < $height) {
// One is set; scale the other one proportionally if reducing
$image_size = self::$image->getImageGeometry();
if ($width && isset($image_size['width']) && $width < $image_size['width']) {
self::$image->scaleImage($width, 0);
} elseif ($height && isset($image_size['height']) && $height < $image_size['height']) {
self::$image->scaleImage(0, $height);
}
} else {
// Neither is specified, apply defaults
self::$image->scaleImage(150, 0);
}
}
if (0 < $quality && 101 > $quality) {
if ('image/jpeg' == $type) {
self::$image->setImageCompressionQuality($quality);
self::$image->setImageCompression(imagick::COMPRESSION_JPEG);
} else {
self::$image->setImageCompressionQuality($quality);
}
}
if ('image/jpeg' == $type) {
if (is_callable(array(self::$image, 'setImageBackgroundColor'))) {
self::$image->setImageBackgroundColor('white');
}
if (is_callable(array(self::$image, 'mergeImageLayers'))) {
self::$image = self::$image->mergeImageLayers(imagick::LAYERMETHOD_FLATTEN);
} elseif (is_callable(array(self::$image, 'flattenImages'))) {
self::$image = self::$image->flattenImages();
}
}
}
示例8: create
/**
* {@inheritdoc}
*/
public function create(BoxInterface $size, ColorInterface $color = null)
{
$width = $size->getWidth();
$height = $size->getHeight();
$palette = null !== $color ? $color->getPalette() : new RGB();
$color = null !== $color ? $color : $palette->color('fff');
try {
$pixel = new \ImagickPixel((string) $color);
$pixel->setColorValue(Imagick::COLOR_ALPHA, $color->getAlpha() / 100);
$imagick = new Imagick();
$imagick->newImage($width, $height, $pixel);
$imagick->setImageMatte(true);
$imagick->setImageBackgroundColor($pixel);
if (version_compare('6.3.1', $this->getVersion($imagick)) < 0) {
$imagick->setImageOpacity($pixel->getColorValue(Imagick::COLOR_ALPHA));
}
$pixel->clear();
$pixel->destroy();
return new Image($imagick, $palette, new MetadataBag());
} catch (\ImagickException $e) {
throw new RuntimeException('Could not create empty image', $e->getCode(), $e);
}
}
示例9: filter_render_type
/**
* function filter_render_type
* Returns HTML markup containing an image with a data: URI
* @param string $content The text to be rendered
* @param string $font_file The path to a font file in a format ImageMagick can handle
* @param integer $font_size The font size, in pixels (defaults to 28)
* @param string $font_color The font color (defaults to 'black')
* @param string $background_color The background color (defaults to 'transparent')
* @param string $output_format The image format to use (defaults to 'png')
* @return string HTML markup containing the rendered image
**/
public function filter_render_type($content, $font_file, $font_size, $font_color, $background_color, $output_format, $width)
{
// Preprocessing $content
// 1. Strip HTML tags. It would be better to support them, but we just strip them for now.
// 2. Decode HTML entities to UTF-8 charaaters.
$content = html_entity_decode(strip_tags($content), ENT_QUOTES, 'UTF-8');
// 3. Do word wrap when $width is specified. Not work for double-width characters.
if (is_int($width)) {
$content = wordwrap($content, floor($width / (0.3 * $font_size)));
}
$cache_group = strtolower(get_class($this));
$cache_key = $font_file . $font_size . $font_color . $background_color . $output_format . $content . $width;
if (!Cache::has(array($cache_group, md5($cache_key)))) {
$font_color = new ImagickPixel($font_color);
$background_color = new ImagickPixel($background_color);
$draw = new ImagickDraw();
$draw->setFont($font_file);
$draw->setFontSize($font_size);
$draw->setFillColor($font_color);
$draw->setTextEncoding('UTF-8');
$draw->annotation(0, $font_size * 2, $content);
$canvas = new Imagick();
$canvas->newImage(1000, $font_size * 5, $background_color);
$canvas->setImageFormat($output_format);
$canvas->drawImage($draw);
// The following line ensures that the background color is set in the PNG
// metadata, when using that format. This allows you, by specifying an RGBa
// background color (e.g. #ffffff00) to create PNGs with a transparent background
// for browsers that support it but with a "fallback" background color (the RGB
// part of the RGBa color) for IE6, which does not support alpha in PNGs.
$canvas->setImageBackgroundColor($background_color);
$canvas->trimImage(0);
Cache::set(array($cache_group, md5($cache_key)), $canvas->getImageBlob());
}
return '<img class="rendered-type" src="' . URL::get('display_rendertype', array('hash' => md5($cache_key), 'format' => $output_format)) . '" title="' . $content . '" alt="' . $content . '">';
}
示例10: createThumbnail
/**
* @desc Create a thumbnail of the picture and save it
* @param $size The size requested
*/
private function createThumbnail($width, $height = false, $format = 'jpeg')
{
if (!in_array($format, array_keys($this->_formats))) {
$format = 'jpeg';
}
if (!$height) {
$height = $width;
}
$path = $this->_path . md5($this->_key) . '_' . $width . $this->_formats[$format];
$im = new Imagick();
try {
$im->readImageBlob($this->_bin);
$im->setImageFormat($format);
if ($format == 'jpeg') {
$im->setImageCompression(Imagick::COMPRESSION_JPEG);
$im->setImageAlphaChannel(11);
// Put 11 as a value for now, see http://php.net/manual/en/imagick.flattenimages.php#116956
//$im->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
$im->setImageBackgroundColor('#ffffff');
$im = $im->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
}
//$crop = new CropEntropy;
//$crop->setImage($im);
$geo = $im->getImageGeometry();
$im->cropThumbnailImage($width, $height);
if ($width > $geo['width']) {
$factor = floor($width / $geo['width']);
$im->blurImage($factor, 10);
}
//$im = $crop->resizeAndCrop($width, $height);
$im->setImageCompressionQuality(85);
$im->setInterlaceScheme(Imagick::INTERLACE_PLANE);
$im->writeImage($path);
$im->clear();
} catch (ImagickException $e) {
error_log($e->getMessage());
}
}
示例11: setColorAndMargin
/**
* Set the fill and margins of the image.
* @param Imagick $method
* @param string $colorKey
* @param string $marginKey
* @return Imagick
* @access private
* @final
*/
private final function setColorAndMargin(Imagick $image, $colorKey = '', $marginKey = '')
{
if (isset($this->settings[$colorKey]) && empty($this->settings[$colorKey]) === false) {
$image->setImageBackgroundColor("#{$this->settings[$colorKey]}");
if (isset($this->settings[$marginKey]) && empty($this->settings[$marginKey]) === false && (int) $this->settings[$marginKey] <= 15) {
$source = $image->getImageGeometry();
$image->resizeImage($source['width'] - $this->settings[$marginKey] * 2, $source['height'] - $this->settings[$marginKey] * 2, Imagick::FILTER_CUBIC, 1);
$image->borderImage("#{$this->settings[$colorKey]}", $this->settings[$marginKey], $this->settings[$marginKey]);
}
}
return $image;
}
示例12: Imagick
<?php
$im = new Imagick("magick:logo");
$im->setImageBackgroundColor("pink");
$im->thumbnailImage(200, 200, true, true);
$color = $im->getImagePixelColor(5, 5);
if ($color->isPixelSimilar("pink", 0)) {
echo "Similar" . PHP_EOL;
} else {
var_dump($color->getColorAsString());
}
$color = $im->getImagePixelColor(199, 5);
if ($color->isPixelSimilar("pink", 0)) {
echo "Similar" . PHP_EOL;
} else {
var_dump($color->getColorAsString());
}
示例13: _background
protected function _background($r, $g, $b, $opacity)
{
$color = sprintf("rgb(%d, %d, %d)", $r, $g, $b);
$pixel1 = new \ImagickPixel($color);
$opacity = $opacity / 100;
$pixel2 = new \ImagickPixel("transparent");
$background = new \Imagick();
$this->_image->setIteratorIndex(0);
while (true) {
$background->newImage($this->_width, $this->_height, $pixel1);
if (!$background->getImageAlphaChannel()) {
$background->setImageAlphaChannel(constant("Imagick::ALPHACHANNEL_SET"));
}
$background->setImageBackgroundColor($pixel2);
$background->evaluateImage(constant("Imagick::EVALUATE_MULTIPLY"), $opacity, constant("Imagick::CHANNEL_ALPHA"));
$background->setColorspace($this->_image->getColorspace());
$background->compositeImage($this->_image, constant("Imagick::COMPOSITE_DISSOLVE"), 0, 0);
if (!$this->_image->nextImage()) {
break;
}
}
$this->_image->clear();
$this->_image->destroy();
$this->_image = $background;
}
示例14: drawShadow
/**
* Draws the shadow of the card
*/
public function drawShadow($hexColour)
{
$onlineIndicator = isset($_GET['onlineindicator']) ? $_GET['onlineindicator'] : false;
$online = $onlineIndicator == 1 || $onlineIndicator == 3 ? Utils::isUserOnline($this->user['username']) : false;
$colour = $online ? new ImagickPixel($hexColour) : new ImagickPixel('black');
$shadow = new Imagick();
$shadow->newImage($this->canvas->getImageWidth(), $this->canvas->getImageHeight(), new ImagickPixel('transparent'));
$shadow->setImageBackgroundColor($colour);
$shadowArea = new ImagickDraw();
$shadowArea->setFillColor($colour);
$shadowArea->roundRectangle(0, 0, $this->baseWidth - 1, $this->baseHeight - 2, self::SIG_ROUNDING, self::SIG_ROUNDING);
$shadow->drawImage($shadowArea);
$shadow->shadowImage($online ? 40 : 15, 1.5, 0, 0);
$this->canvas->compositeImage($shadow, Imagick::COMPOSITE_DEFAULT, 0, 1);
}
示例15: ServerError
}
// Check token
if (!ValidPost()) {
ServerError("Invalid post request.");
}
// Convert SVG string to image
if (class_exists("Imagick")) {
// Use Imagick if available
try {
$img = new Imagick();
$svg = '<?xml version="1.0" encoding="utf-8" standalone="no"?>' . ewr_StripSlashes(@$_POST["stream"]);
// Get SVG string
// Replace, for example, fill="url('#10-270-rgba_255_0_0_1_-rgba_255_255_255_1_')" by fill="rgb(255, 0, 0)"
$svg = preg_replace('/fill="url\\(\'#[\\w-]+rgba_(\\d+)_(\\d+)_(\\d+)_(\\d+)_-[\\w-]+\'\\)"/', 'fill="rgb($1, $2, $3)"', $svg);
$img->readImageBlob($svg);
$img->setImageBackgroundColor(new ImagickPixel("transparent"));
$img->setImageFormat("png24");
} catch (Exception $e) {
ServerError($e->getMessage());
}
} elseif (function_exists("curl_init")) {
// Use export.api3.fusioncharts.com and curl
$postdata = file_get_contents("php://input");
// Get POST data
$img = ewr_ClientUrl("export.api3.fusioncharts.com", $postdata, "POST");
// Get the chart from fusioncharts.com
if ($img === FALSE) {
ServerError("Failed to get chart image from export server. Make sure your web server is online.");
}
} else {
ServerError("Both Imagick and cURL not installed on this server.");