Imagick::setBackgroundColor


wizard apg

SETS the object's default background color of an image.



<?php

bool 
public Imagick::setBackgroundColor(mixed $background);

?>

$background


The image background color.





This function returns a TRUE on success.

Since version of Imagick 2.1.0 string representing color as a parameter is allowed.

Previous versions allow only an ImagickPixel object.



AVAILABLE "imagick" CONSTANTS
STUDIED IN THIS TUTORIAL

1690 - ImageMagick 6.9.10-6
ALPHACHANNEL
CONSTANTVALUEABOUT
imagick::ALPHACHANNEL_ACTIVATE1 ImageMagick version 6.3.8 or higher.
imagick::ALPHACHANNEL_DEACTIVATE4 ImageMagick version 6.3.8 or higher.
imagick::ALPHACHANNEL_RESET 7 ImageMagick version 6.3.8 or higher.
imagick::ALPHACHANNEL_SET8 ImageMagick version 6.3.8 or higher.
imagick::ALPHACHANNEL_UNDEFINED0 ImageMagick version 6.4.6 or higher.
imagick::ALPHACHANNEL_COPY3 ImageMagick version 6.4.6 or higher.
imagick::ALPHACHANNEL_EXTRACT5 ImageMagick version 6.4.6 or higher.
imagick::ALPHACHANNEL_OPAQUE6 ImageMagick version 6.4.6 or higher.
imagick::ALPHACHANNEL_SHAPE9 ImageMagick version 6.4.6 or higher.
imagick::ALPHACHANNEL_TRANSPARENT10 ImageMagick version 6.4.6 or higher.
imagick::ALPHACHANNEL_BACKGROUND2 ImageMagick version 6.5.3 or higher.
imagick::ALPHACHANNEL_REMOVE 12 ImageMagick version 6.7.8 or higher.
imagick::ALPHACHANNEL_ASSOCIATE 13 ImageMagick version 6.9.0 or higher.
imagick::ALPHACHANNEL_DISSOCIATE 14 ImageMagick version 6.9.0 or higher.
imagick::ALPHACHANNEL_ON ImageMagick version 7.0.0 or higher.
imagick::ALPHACHANNEL_OFF ImageMagick version 7.0.0 or higher.
imagick::ALPHACHANNEL_DISCRETE ImageMagick version 7.0.0 or higher.
ed48



PSEUDO IMAGE FORMATS

Tag Mode Description Notes
ASHLAR W Image sequence laid out in continuous irregular courses By default, a reasonable canvas size and border width is determined relative to the image collection you provide.

You can explicitedly set the canvas size and border width by appending to the filename, e.g. ashlar:canvas.png[1024x768+4+4].

By default, alignment is along the left edge. Use -define ashlar:best-fit=true to align on both the left and right edges.

You can label the image tiles with, for example, -label %f.

By default, all image tiles are rendered on a single canvas.

Use -define ashlar:tiles=50, for example, to render at most 50 tiles per canvas.
CANVAS R Canvas image of specified color Useful to create solid color canvas images.

Use -size and -depth to specify the image width, height, and depth.

Example canvas color specifications include canvas:red and canvas:#FF0000.

If no color is specified a 'white' canvas image is generated.

If no -size is specified a single pixel image of the specified color is generated.
CAPTION R Image caption Use -define caption:split=true to split text if required to fit caption on the canvas
CLIP RW Clip path of image
CLIPBOARD RW Windows Clipboard Only available under Microsoft Windows.
FRACTAL R Plasma fractal image
GRADIENT R Gradual passing from one shade to another Returns a rendered linear or radial top-to-bottom gradient image using the specified image size.
HALD R Identity Hald CLUT Image Select levels like this: hald:[8] for level 8.
HISTOGRAM W Histogram of the image The histogram includes the unique colors of the image as an image comment.

If you have no need for the unique color list, use -define histogram:unique-colors=false to forego this expensive operation.
INLINE RW Base64-encoded inline image The inline image look similar to
inline:data:;base64,/9j/4AAQSk...knrn//2Q==.

If the inline image exceeds 5000 characters, reference it from a file (e.g. inline:inline.txt).

You can also write a base64-encoded image.

Embed the mime type in the filename, for example, magick myimage inline:jpeg:myimage.txt.
LABEL R Text image format Specify the desired text as the filename (e.g. label:"This a label").
MAP RW Colormap intensities and indices Set -depth to set the sample size of the intensities; indices are 16-bit if colors > 256.
MASK RW Image mask
MATTE W MATTE format Write only.
NULL RW NULL image Useful for creating blank tiles with montage (use NULL:).

Also useful as an output format when evaluating image read performance.
PANGO R Image caption You can configure the caption layout with these defines:

-define pango:auto-dir=true/false,
-define pango:ellipsize=start/middle/end,
-define pango:gravity-hint=natural/strong/line,
-define pango:hinting=none/auto/full,
-define pango:indent=points,
-define pango:justify=true/false,
-define pango:language=en_US/etc,
-define pango:markup=true/false,
-define pango:single-paragraph=true/false,
-define pango:wrap=word/char/word-char and
-define pango:align=left/center/right.
PLASMA R Plasma fractal image
PREVIEW W Show a preview an image enhancement, effect, or f/x Creates a preview montage of images prepared over a parametric range in order to assist with parameter selection.

Specify the desired preview type via the -preview option).
PRINT W Send image to your computer printer Linux users may set the PRINTER (for 'lpr') or LPDEST (for 'lp') environment variables to select the desired printer.
SCAN R Import image from a scanner device Requires SANE Specify the device name and path as the filename (e.g. scan:'hpaio:/usb/Officejet_6200_series?serial=CN4ATCE3G20453').
RADIAL_GRADIENT R Gradual radial passing from one shade to another Returns a rendered radial top-to-bottom gradient image using the specified image size.
SCANX R Import image from the default scanner device
SCREENSHOT R an image that shows the contents of a computer display.

Under Windows, if you have multiple monitors, it returns a screenshot for each monitor.
STEGANO R Steganographic image Use -size command line option to specify width, height, and offset of the steganographic image
TILE R Tiled image Create a tiled version of an image at by tiling a image.

Use -size to specify the tiled image size.

Tiles are composited on an image background and therefore is responsive to the -compose option.

The image is specified similar to TILE:image.miff.
UNIQUE W Write only unique pixels to the image file.
VID RW Visual Image Directory Used to create a thumbnailed directory (tiled thumbnails) of a set of images which may be used to select images to view via the display program, or saved to a MIFF or SHTML file.
WIN RW Select image from or display image to your computer screen Only supported under Microsoft Windows.
X RW Select image from or display image to your X server screen Also see the import and display programs.
XC R Canvas image of specified color An backward compatible alias for the 'canvas:' psuedo-file format, used to create a solid color canvas image.
ed48

  1 EXERCISE   

<?php

$str1img 
'img/tests/t1.png';
  
// Create a new imagick object
$im = new Imagick();
  
// Write the caption in a image
$im->newPseudoImage(800100"caption: This exercise...");
  
$c1 mt_rand(0255);
$c2 mt_rand(0255);
$c3 mt_rand(0255);
  
// Set background color
$im->setImageBackgroundColor("rgb($c1$c2$c3)");
  
// Set the ImageAlphaChannel to 14 which corresponds
// to imagick::ALPHACHANNEL_SHAPE

$i 14;
{
$im->setImageAlphaChannel($i);
}

// Display the image

$im->setformat('png');

$data $im->getImageBlob();

$im imagecreatefromstring($data);

imagepng($im$str1img);

?>
<img src="<?php echo $str1img?>"
 alt="<?php echo $str1img?>
 title="<?php echo $str1img?>">


  2 EXERCISE   

<?php

$arrps 
= [ "BRICKS""CHECKERBOARD""CIRCLES"
"CROSSHATCH""CROSSHATCH30""CROSSHATCH45"
"FISHSCALES""GRAY0""GRAY5""GRAY10"
"GRAY15""GRAY20""GRAY25""GRAY30""GRAY35",
 
"GRAY40","GRAY45""GRAY50""GRAY55""GRAY60"
 
"GRAY65""GRAY70""GRAY75""GRAY80""GRAY85"
 
"GRAY90""GRAY95""GRAY100""HEXAGONS"
 
"HORIZONTAL""HORIZONTAL2""HORIZONTAL3"
 
"HORIZONTALSAW""HS_BDIAGONAL""HS_CROSS"
 
"HS_DIAGCROSS""HS_FDIAGONAL""HS_HORIZONTAL"
 
"HS_VERTICAL""LEFT30","LEFT45""LEFTSHINGLE"
 
"OCTAGONS""RIGHT30""RIGHT45""RIGHTSHINGLE"
 
"SMALLFISHSCALES""VERTICAL""VERTICAL2"
 
"VERTICAL3""VERTICALBRICKS""VERTICALLEFTSHINGLE"
 
"VERTICALRIGHTSHINGLE""VERTICALSAW" ];

$str1img 'img/png/t2.png';
  
$im = new Imagick();

// Run this exercise several times

$p mt_rand(0count($arrps) -1);
{
$im->newPseudoImage(30050"pattern:$arrps[$p]");
}

$c1 mt_rand(0255);
$c2 mt_rand(0255);
$c3 mt_rand(0255);
 
$im->setImageBackgroundColor("rgb($c1$c2$c3)");

$i 14;
{
$im->setImageAlphaChannel($i);
}

$im->setformat('png');

$data $im->getImageBlob();

echo 
$arrps[$p] . '<br>' "rgb($c1$c2$c3)" '<br><br>';

$im imagecreatefromstring($data);

imagepng($im$str1img);

?>
<img src="<?php echo $str1img?>"
 alt="<?php echo $str1img?>
 title="<?php echo $str1img?>">