ImagickPixel::__construct

(PECL imagick 2, PECL imagick 3)

ImagickPixel::__constructThe ImagickPixel constructor

Description

public ImagickPixel::__construct(string $color = ?)
Warning

This function is currently not documented; only its argument list is available.

Constructs an ImagickPixel object. If a color is specified, the object is constructed and then initialised with that color before being returned.

Parameters

color

The optional color string to use as the initial value of this object.

Return Values

Returns an ImagickPixel object on success, throwing ImagickPixelException on failure.

Examples

Example #1 ImagickPixel::construct()

<?php
function construct() {

    
$columns 4;
    
    
$exampleColors = array(
        
"rgba(100%, 0%, 0%, 0.5)",
        
"hsb(33.3333%, 100%,  75%)"// medium green
        
"hsl(120, 255,   191.25)"//medium green
        
"graya(50%, 0.5)"//  semi-transparent mid gray
        
"LightCoral""none"//"cmyk(0.9, 0.48, 0.83, 0.50)",
        
"#f00"//  #rgb
        
"#ff0000"//  #rrggbb
        
"#ff0000ff"//  #rrggbbaa
        
"#ffff00000000"//  #rrrrggggbbbb
        
"#ffff00000000ffff"//  #rrrrggggbbbbaaaa
        
"rgb(255, 0, 0)"//  an integer in the range 0—255 for each component
        
"rgb(100.0%, 0.0%, 0.0%)"//  a float in the range 0—100% for each component
        
"rgb(255, 0, 0)"//  range 0 - 255
        
"rgba(255, 0, 0, 1.0)"//  the same, with an explicit alpha value
        
"rgb(100%, 0%, 0%)"//  range 0.0% - 100.0%
        
"rgba(100%, 0%, 0%, 1.0)"//  the same, with an explicit alpha value
    
);

    
$draw = new \ImagickDraw();
    
$count 0;
    
$black = new \ImagickPixel('rgb(0, 0, 0)');

    foreach (
$exampleColors as $exampleColor) {
        
$color = new \ImagickPixel($exampleColor);

        
$draw->setstrokewidth(1.0);
        
$draw->setStrokeColor($black);
        
$draw->setFillColor($color);
        
$offsetX = ($count $columns) * 50 5;
        
$offsetY intval($count $columns) * 50 5;
        
$draw->rectangle($offsetX$offsetY40 $offsetX40 $offsetY);
        
$count++;
    }

    
$image = new \Imagick();
    
$image->newImage(350350"blue");
    
$image->setImageFormat("png");
    
$image->drawImage($draw);
    
header("Content-Type: image/png");
    echo 
$image->getImageBlob();
}

?>

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial