Example #1
0
 function render()
 {
     //Example ImagickPixel::setHSL
     $output = "This example creates a red color, rotates the hue by 180 degrees and sets the new color.<br/>";
     //Create an almost pure red color
     $color = new \ImagickPixel('rgb(90%, 10%, 10%)');
     $originalColor = clone $color;
     //Get it's HSL values
     $colorInfo = $color->getHSL();
     //Rotate the hue by 180 degrees
     $newHue = $colorInfo['hue'] + 0.5;
     if ($newHue > 1) {
         $newHue = $newHue - 1;
     }
     //Set the ImagickPixel to the new color
     $color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']);
     $output .= "<h3>Original color</h3>";
     $colorInfo = $originalColor->getcolor();
     foreach ($colorInfo as $key => $value) {
         $output .= "{$key} : {$value} <br/>";
     }
     $output .= "<h3>Rotated color</h3>";
     //Check that the new color is blue/green
     $colorInfo = $color->getcolor();
     foreach ($colorInfo as $key => $value) {
         $output .= "{$key} : {$value} <br/>";
     }
     return $output;
     //Example end
 }
Example #2
0
 private function createImage()
 {
     /* Create Imagick object */
     $this->Imagick = new \Imagick();
     /* Create the ImagickPixel object (used to set the background color on image) */
     $bg = new \ImagickPixel();
     /* Set the pixel color to white */
     $bg->setColor($this->bg_color);
     /* Create a drawing object and set the font size */
     $ImagickDraw = new \ImagickDraw();
     /* Set font and font size. You can also specify /path/to/font.ttf */
     if ($this->font) {
         $ImagickDraw->setFont($this->font);
     }
     $ImagickDraw->setFontSize($this->font_size);
     /* Create new empty image */
     $this->Imagick->newImage($this->image_width, $this->image_height, $bg);
     /* Write the text on the image */
     $this->Imagick->annotateImage($ImagickDraw, $this->text_position_left, $this->text_position_top, 0, $this->getCaptchaText());
     /* Add some swirl */
     $this->Imagick->swirlImage(20);
     /* Create a few random lines */
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     $ImagickDraw->line(rand(0, $this->image_width), rand(0, $this->image_height), rand(0, $this->image_width), rand(0, $this->image_height));
     /* Draw the ImagickDraw object contents to the image. */
     $this->Imagick->drawImage($ImagickDraw);
     /* Give the image a format */
     $this->Imagick->setImageFormat($this->image_format);
 }
Example #3
0
    /**
     * (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
            );
        }
    }
Example #4
0
 public function render()
 {
     //Example ImagickPixel::isSimilar
     // The tests below are written with the maximum distance expressed as 255
     // so we need to scale them by the square root of 3 - the diagonal length
     // of a unit cube.
     $root3 = 1.732050807568877;
     $tests = array(['rgb(245, 0, 0)', 'rgb(255, 0, 0)', 9 / $root3, false], ['rgb(245, 0, 0)', 'rgb(255, 0, 0)', 10 / $root3, true], ['rgb(0, 0, 0)', 'rgb(7, 7, 0)', 9 / $root3, false], ['rgb(0, 0, 0)', 'rgb(7, 7, 0)', 10 / $root3, true], ['rgba(0, 0, 0, 1)', 'rgba(7, 7, 0, 1)', 9 / $root3, false], ['rgba(0, 0, 0, 1)', 'rgba(7, 7, 0, 1)', 10 / $root3, true], ['rgb(128, 128, 128)', 'rgb(128, 128, 120)', 7 / $root3, false], ['rgb(128, 128, 128)', 'rgb(128, 128, 120)', 8 / $root3, true], ['rgb(0, 0, 0)', 'rgb(255, 255, 255)', 254.9, false], ['rgb(0, 0, 0)', 'rgb(255, 255, 255)', 255, true], ['rgb(255, 0, 0)', 'rgb(0, 255, 255)', 254.9, false], ['rgb(255, 0, 0)', 'rgb(0, 255, 255)', 255, true], ['black', 'rgba(0, 0, 0)', 0.0, true], ['black', 'rgba(10, 0, 0, 1.0)', 10.0 / $root3, true]);
     $output = "<table width='100%' class='infoTable'><thead>\n                <tr>\n                <th>\n                Color 1\n                </th>\n                <th>\n                Color 2\n                </th>\n                <th>\n                    Test distance * 255\n                </th>\n                <th>\n                    Is within distance\n                </th>\n                </tr>\n        </thead>";
     $output .= "<tbody>";
     foreach ($tests as $testInfo) {
         $color1 = $testInfo[0];
         $color2 = $testInfo[1];
         $distance = $testInfo[2];
         $expectation = $testInfo[3];
         $testDistance = $distance / 255.0;
         $color1Pixel = new \ImagickPixel($color1);
         $color2Pixel = new \ImagickPixel($color2);
         $isSimilar = $color1Pixel->isPixelSimilar($color2Pixel, $testDistance);
         if ($isSimilar !== $expectation) {
             echo "Test distance failed. Color [{$color1}] compared to color [{$color2}] is not within distance {$testDistance} FAILED." . NL;
         }
         $layout = "<tr>\n                <td>%s</td>\n                <td>%s</td>\n                <td>%s</td>\n                <td style='text-align: center;'>%s</td>\n            </tr>";
         $output .= sprintf($layout, $color1, $color2, $distance, $isSimilar ? 'yes' : 'no');
     }
     $output .= "</tbody></table>";
     return $output;
     //Example end
 }
Example #5
0
 public function render()
 {
     //Example ImagickPixel::getColorAsString
     $output = "Create an ImagickPixel with the predefined color 'brown' and output the result of `getColorAsString`. <br/>";
     $color = new \ImagickPixel('brown');
     $color->setColorValue(\Imagick::COLOR_ALPHA, 64 / 256.0);
     $output .= $color->getColorAsString();
     return $output;
     //Example end
 }
 function render()
 {
     //Example ImagickPixel::getColorCount
     $output = "I have pretty much no idea what this function is meant " . "to do...if you know I'd love to hear.<br/>";
     $color = new \ImagickPixel('red');
     $colorInfo = $color->getColorCount();
     $output .= var_export($colorInfo, true);
     return $output;
     //Example end
 }
 /**
  * Add a Block to a pixel to a given coordinate depending
  * on a pixels color
  *
  * @param \ImagickPixel $pixel
  * @param Structure     $structure
  * @param               $x
  * @param               $y
  * @param               $z
  */
 protected function addBlockForPixel(\ImagickPixel $pixel, Structure $structure, $x, $y, $z)
 {
     $color = $pixel->getColor();
     $type = $this->blockTypeColorMapping->getBlockTypeForRgbColor($color['r'], $color['g'], $color['b']);
     if (null === $type) {
         return;
     }
     // if meta is null it becomes 0
     $meta = (int) $type->getMeta();
     $structure->createBlock($type->getName(), array('x' => $x, 'y' => $y, 'z' => $z), $meta);
 }
 function render()
 {
     //Example ImagickPixel::getColorValueQuantum
     $color = new \ImagickPixel('rgb(128, 5, 255)');
     $colorRed = $color->getColorValueQuantum(\Imagick::COLOR_RED);
     $colorGreen = $color->getColorValueQuantum(\Imagick::COLOR_GREEN);
     $colorBlue = $color->getColorValueQuantum(\Imagick::COLOR_BLUE);
     $colorAlpha = $color->getColorValueQuantum(\Imagick::COLOR_ALPHA);
     printf("Red: %s Green: %s  Blue %s Alpha: %s", $colorRed, $colorGreen, $colorBlue, $colorAlpha);
     //Example end
 }
Example #9
0
 public function renderFormElement()
 {
     $sValue = safeText($this->value);
     $fillPixel = new \ImagickPixel($this->value);
     $fillColor = $fillPixel->getcolor();
     $fillString = sprintf("rgb(%d, %d, %d)", $fillColor['r'], $fillColor['g'], $fillColor['b']);
     $fillStringHex = sprintf("%02x%02x%02x", $fillColor['r'], $fillColor['g'], $fillColor['b']);
     $input = "<input type='text' class='inputValue' id='" . $this->getVariableName() . "' name='" . $this->getVariableName() . "' value='{$sValue}'  />";
     $color = "<span id='" . $this->getVariableName() . "Selector' data-color='0x{$fillStringHex}' style='display: inline-block; border: 1px solid #000; padding: 0px;'>\n                        <span style='background-color: {$fillString}; margin: 2px; width: 20px; display: inline-block;'>\n                            &nbsp;\n                        </span>\n                    </span>";
     $text = "<div class='row controlRow'>\n    <div class='col-sm-" . (self::FIRST_ELEMENT_SIZE - 1) . " " . self::FIRST_ELEMENT_CLASS . " controlCell'>\n        %s\n    </div>\n    <div class='col-sm-1 controlCell'>\n        %s\n    </div>\n    <div class='col-sm-" . self::MIDDLE_ELEMENT_SIZE . " " . self::MIDDLE_ELEMENT_CLASS . " controlCell'>\n        %s\n    </div>\n    \n</div>";
     return sprintf($text, $this->getDisplayName(), $color, $input);
 }
Example #10
0
 public function render()
 {
     //Example ImagickPixel::getHSL
     $colorString = 'rgb(90%, 10%, 10%)';
     $output = "The result of getHSL for the color '{$colorString}' is:<br/>";
     $color = new \ImagickPixel($colorString);
     $colorInfo = $color->getHSL();
     foreach ($colorInfo as $key => $value) {
         $output .= "{$key} : {$value} <br/>";
     }
     return $output;
     //Example end
 }
Example #11
0
 public function render()
 {
     echo "Create an ImagickPixel with the predefined color 'brown' and set the color to have an alpha of 25% <br/>";
     //Example ImagickPixel::getColor
     $color = new \ImagickPixel('brown');
     $color->setColorValue(\Imagick::COLOR_ALPHA, 0.25);
     echo "<h4>Standard values</h4>" . PHP_EOL;
     foreach ($color->getColor() as $key => $value) {
         echo "{$key} : {$value} <br/>";
     }
     echo "<br/>";
     echo "<h4>Normalized values</h4>" . PHP_EOL;
     foreach ($color->getColor(true) as $key => $value) {
         echo "{$key} : {$value} <br/>";
     }
     //Example end
 }
Example #12
0
 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);
     }
 }
 public function render()
 {
     //Example ImagickPixel::getColorValue
     $color = new \ImagickPixel('rgba(90%, 20%, 20%, 0.75)');
     echo "Alpha value is " . $color->getColorValue(\Imagick::COLOR_ALPHA) . "<br/>";
     echo "" . "<br/>";
     echo "Red value is " . $color->getColorValue(\Imagick::COLOR_RED) . "<br/>";
     echo "Green value is " . $color->getColorValue(\Imagick::COLOR_GREEN) . "<br/>";
     echo "Blue value is " . $color->getColorValue(\Imagick::COLOR_BLUE) . "<br/>";
     echo "" . "<br/>";
     echo "Cyan value is " . $color->getColorValue(\Imagick::COLOR_CYAN) . "<br/>";
     echo "Magenta value is " . $color->getColorValue(\Imagick::COLOR_MAGENTA) . "<br/>";
     echo "Yellow value is " . $color->getColorValue(\Imagick::COLOR_YELLOW) . "<br/>";
     echo "Black value is " . $color->getColorValue(\Imagick::COLOR_BLACK) . "<br/>";
     //Example end
 }
Example #14
0
 public function rotate($angle, \Imagine\Image\Palette\Color\ColorInterface $background = null)
 {
     if ($this->image === null) {
         $this->load();
     }
     $color = RImagine::getColor($background);
     try {
         $pixel = new \ImagickPixel($color['color']);
         $pixel->setColorValue(\Imagick::COLOR_OPACITY, $color['alpha']);
         $magick = $this->image->getImagick();
         $magick->rotateimage($pixel, $angle);
         $pixel->clear();
         $pixel->destroy();
         $magick->setImagePage(0, 0, 0, 0);
         // reset canvas position
     } catch (\ImagickException $e) {
         throw new \Imagine\Exception\RuntimeException('Imagick: Rotate operation failed. ' . $e->getMessage(), $e->getCode(), $e);
     }
     $this->size = array($magick->getImageWidth(), $magick->getImageHeight());
     return $this;
 }
Example #15
0
 function render()
 {
     $output = "<table class='smallPadding' width='100%'>";
     $output .= "<tbody>";
     foreach ($this->listOfColors as $color) {
         $pixelColor = new \ImagickPixel($color);
         $colorArray = $pixelColor->getColor();
         if ($color == 'transparent' || $color == 'none') {
             $rgbaString = sprintf("rgb(%d, %d, %d, %d)", $colorArray['r'], $colorArray['g'], $colorArray['b'], $colorArray['a']);
             $hexString = sprintf("#%02x%02x%02x%02x", $colorArray['r'], $colorArray['g'], $colorArray['b'], $colorArray['a']);
         } else {
             $rgbaString = sprintf("rgb(%d, %d, %d)", $colorArray['r'], $colorArray['g'], $colorArray['b']);
             $hexString = sprintf("#%02x%02x%02x", $colorArray['r'], $colorArray['g'], $colorArray['b']);
         }
         $colorString = '';
         if ($colorArray['r'] + $colorArray['g'] + $colorArray['b'] < 200) {
             if ($colorArray['a'] != 0) {
                 $colorString = 'color: #efefef';
             }
         }
         $output .= "<tr>";
         $output .= "<td>";
         $output .= $color;
         $output .= "</td>";
         $output .= "<td style='background-color: {$hexString};{$colorString}'>";
         $output .= $color;
         $output .= "</td>";
         $output .= "<td>";
         $output .= $rgbaString;
         $output .= "</td>";
         $output .= "<td>";
         $output .= $hexString;
         $output .= "</td>";
         $output .= "</tr>";
     }
     $output .= "</tbody>";
     $output .= "</table>";
     return $output;
 }
Example #16
0
 /**
  * {@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);
     }
 }
Example #17
0
 public function border($width, $height, $color = 'rgb(220, 220, 220)')
 {
     $color = new ImagickPixel();
     $color->setColor($color);
     $this->image->borderImage($color, $width, $height);
 }
Example #18
0
<?php

$root3 = 1.732050807568877;
$tests = array(array('rgb(245, 0, 0)', 'rgb(255, 0, 0)', 9 / $root3, false), array('rgb(245, 0, 0)', 'rgb(255, 0, 0)', 10 / $root3, true), array('rgb(0, 0, 0)', 'rgb(7, 7, 0)', 9 / $root3, false), array('rgb(0, 0, 0)', 'rgb(7, 7, 0)', 10 / $root3, true), array('rgba(0, 0, 0, 1)', 'rgba(7, 7, 0, 1)', 9 / $root3, false), array('rgba(0, 0, 0, 1)', 'rgba(7, 7, 0, 1)', 10 / $root3, true), array('rgb(128, 128, 128)', 'rgb(128, 128, 120)', 7 / $root3, false), array('rgb(128, 128, 128)', 'rgb(128, 128, 120)', 8 / $root3, true), array('rgb(0, 0, 0)', 'rgb(255, 255, 255)', 254.9, false), array('rgb(0, 0, 0)', 'rgb(255, 255, 255)', 255, true), array('rgb(255, 0, 0)', 'rgb(0, 255, 255)', 254.9, false), array('rgb(255, 0, 0)', 'rgb(0, 255, 255)', 255, true), array('black', 'rgba(0, 0, 0)', 0.0, true), array('black', 'rgba(10, 0, 0, 1.0)', 10.0 / $root3, true));
try {
    foreach ($tests as $testInfo) {
        $color1 = $testInfo[0];
        $color2 = $testInfo[1];
        $distance = $testInfo[2];
        $expectation = $testInfo[3];
        $testDistance = $distance / 255.0 + 1.0E-8;
        $color1Pixel = new ImagickPixel($color1);
        $color2Pixel = new ImagickPixel($color2);
        $isSimilar = $color1Pixel->isPixelSimilar($color2Pixel, $testDistance);
        if ($isSimilar !== $expectation) {
            echo "isPixelSimilar failed. Color [{$color1}] compared to color [{$color2}]" . " is not within distance {$testDistance}." . PHP_EOL;
        }
    }
    echo "success";
} catch (\Exception $e) {
    echo "Exception caught in ImagickPixel::isPixelSimilar test: " . $e->getMessage() . PHP_EOL;
}
Example #19
0
 static function verifycode_im()
 {
     if (empty($_SESSION)) {
         session_start();
     }
     $authnum = '';
     srand((double) microtime() * 1000000);
     $_SESSION['authcode'] = "";
     /* imagick对象 *
              $Imagick = new Imagick();
     
              /* 背景对象 */
     $bg = new ImagickPixel();
     /* Set the pixel color to white */
     $bg->setColor('rgb(235,235,235)');
     /* 画刷 *
              $ImagickDraw = new ImagickDraw();
     
              /* Set font and font size. You can also specify /path/to/font.ttf */
     $ImagickDraw->setFont(LIBPATH . '/../static/fonts/CONSOLA.TTF');
     $ImagickDraw->setFontSize(24);
     $ImagickDraw->setFillColor('black');
     //生成数字和字母混合的验证码方法
     $ychar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
     $list = explode(",", $ychar);
     for ($i = 0; $i < 4; $i++) {
         $randnum = rand(0, 35);
         $authnum .= $list[$randnum];
     }
     $authnum = strtoupper($authnum);
     $_SESSION['authcode'] = $authnum;
     /* Create new empty image */
     $Imagick->newImage(60, 24, $bg);
     /* Write the text on the image */
     $Imagick->annotateImage($ImagickDraw, 4, 20, 0, $authnum);
     /* 变形 *
              //$Imagick->swirlImage( 10 );
     
              /* 随即线条 */
     /*$ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
       $ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
       $ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
       $ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );
       $ImagickDraw->line( rand( 0, 70 ), rand( 0, 30 ), rand( 0, 70 ), rand( 0, 30 ) );*/
     /* Draw the ImagickDraw object contents to the image. */
     $Imagick->drawImage($ImagickDraw);
     /* Give the image a format */
     $Imagick->setImageFormat('png');
     /* Send headers and output the image */
     //header( "Content-Type: image/{$Imagick->getImageFormat()}" );
     echo $Imagick->getImageBlob();
 }
Example #20
0
 /**
  * Gets specifically formatted color string from Color instance
  *
  * @param ColorInterface $color
  *
  * @return \ImagickPixel
  */
 private function getColor(ColorInterface $color)
 {
     $pixel = new \ImagickPixel((string) $color);
     $pixel->setColorValue(\Imagick::COLOR_ALPHA, $color->getAlpha() / 100);
     return $pixel;
 }
Example #21
0
<?php

/*
	This examples was ported from Imagemagick C examples.
*/
/* Create Imagick objects */
$Imagick = new Imagick();
/* Create ImagickDraw objects */
$ImagickDraw = new ImagickDraw();
/* Create ImagickPixel objects */
$ImagickPixel = new ImagickPixel();
/* This array contains polygon geometry */
$array = array(array("x" => 378.1, "y" => 81.72), array("x" => 381.1, "y" => 79.56), array("x" => 384.3, "y" => 78.12), array("x" => 387.6, "y" => 77.33), array("x" => 391.1, "y" => 77.11), array("x" => 394.6, "y" => 77.62), array("x" => 397.8, "y" => 78.77), array("x" => 400.9, "y" => 80.56999999999999), array("x" => 403.6, "y" => 83.02), array("x" => 523.9, "y" => 216.8), array("x" => 526.2, "y" => 219.7), array("x" => 527.6, "y" => 223), array("x" => 528.4, "y" => 226.4), array("x" => 528.6, "y" => 229.8), array("x" => 528.0, "y" => 233.3), array("x" => 526.9, "y" => 236.5), array("x" => 525.1, "y" => 239.5), array("x" => 522.6, "y" => 242.2), array("x" => 495.9, "y" => 266.3), array("x" => 493, "y" => 268.5), array("x" => 489.7, "y" => 269.9), array("x" => 486.4, "y" => 270.8), array("x" => 482.9, "y" => 270.9), array("x" => 479.5, "y" => 270.4), array("x" => 476.2, "y" => 269.3), array("x" => 473.2, "y" => 267.5), array("x" => 470.4, "y" => 265), array("x" => 350, "y" => 131.2), array("x" => 347.8, "y" => 128.3), array("x" => 346.4, "y" => 125.1), array("x" => 345.6, "y" => 121.7), array("x" => 345.4, "y" => 118.2), array("x" => 346, "y" => 114.8), array("x" => 347.1, "y" => 111.5), array("x" => 348.9, "y" => 108.5), array("x" => 351.4, "y" => 105.8), array("x" => 378.1, "y" => 81.72));
/* This ImagickPixel is used to set background color */
$ImagickPixel->setColor('gray');
/* Create new image, set color to gray and format to png*/
$Imagick->newImage(700, 500, $ImagickPixel);
$Imagick->setImageFormat('png');
/* Create the polygon*/
$ImagickDraw->polygon($array);
/* Render the polygon to image*/
$Imagick->drawImage($ImagickDraw);
/* Send headers and output the image */
header("Content-Type: image/{$Imagick->getImageFormat()}");
echo $Imagick->getImageBlob();
Example #22
0
 /**
  * Gets specifically formatted color string from Color instance
  *
  * @param ColorInterface $color
  *
  * @return \ImagickPixel
  */
 private function getColor(ColorInterface $color)
 {
     $pixel = new \ImagickPixel((string) $color);
     $pixel->setColorValue(\Imagick::COLOR_ALPHA, number_format(round($color->getAlpha() / 100, 2), 1));
     return $pixel;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $draw = new ImagickDraw();
     $draw->setStrokeWidth($this->thickness);
     if (!is_null($this->color)) {
         $stroke = new ImagickPixel();
         $stroke->setColor($this->color);
         $draw->setStrokeColor($stroke);
     }
     if (!is_null($this->fill)) {
         $fill = new ImagickPixel();
         $fill->setColor($this->fill);
         $draw->setFillColor($fill);
     }
     $draw->rectangle($this->x1, $this->y1, $this->x2, $this->y2);
     $resource->drawImage($draw);
     return $image;
 }
Example #24
0
 /**
  * Gets specifically formatted color string from Color instance
  *
  * @param Color $color
  *
  * @return string
  */
 private function getColor(Color $color)
 {
     $pixel = new \ImagickPixel((string) $color);
     $pixel->setColorValue(\Imagick::COLOR_OPACITY, number_format(abs(round($color->getAlpha() / 100, 1)), 1));
     return $pixel;
 }
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     $fill = new ImagickPixel();
     $fill->setColor($this->fill);
     /*
      *  colorFloodfillImage has been depricated, use new method is available
      */
     if (method_exists($resource, 'floodFillPaintImage') && is_null($this->border)) {
         $target = $resource->getImagePixelColor($this->getX(), $this->getY());
         $resource->floodFillPaintImage($fill, $this->getFuzz(), $target, $this->getX(), $this->getY(), false);
     } else {
         $border = new ImagickPixel();
         $border->setColor($this->border);
         $resource->colorFloodfillImage($fill, $this->getFuzz(), $border, $this->getX(), $this->getY());
     }
     return $image;
 }
Example #26
0
    $ref = $general->addChild('ref');
    //$ref->addAttribute("titulo",iconv('ISO-8859-1','UTF-8//TRANSLIT',$f['titulo']));
    $ref->addAttribute("titulo", $f['titulo']);
    $ref->addAttribute("pagina", $pagina_actual);
    $cp = 'SELECT foto, pc.titulo FROM flores_productos_categoria LEFT JOIN flores_producto_contenedor AS pc USING(codigo_producto) LEFT JOIN flores_producto_variedad USING(codigo_producto) WHERE codigo_categoria=' . $f['codigo_categoria'] . ' GROUP BY codigo_producto';
    $rp = db_consultar($cp);
    $pagina_actual += 1 + mysql_numrows($rp);
    while ($fp = mysql_fetch_assoc($rp)) {
        if (!file_exists('catalogo360/pages/' . $fp['foto'])) {
            $im = new Imagick('IMG/i/' . $fp['foto']);
            $im->setCompression(Imagick::COMPRESSION_JPEG);
            $im->setCompressionQuality(90);
            $im->setImageFormat('jpeg');
            $im->stripImage();
            $draw = new ImagickDraw();
            $pixel = new ImagickPixel('gray');
            $pixel->setColor('black');
            $draw->setFont('flower.ttf');
            $draw->setFontSize(30);
            $im->thumbnailImage(350, 525, false);
            $im->annotateImage($draw, 10, 45, 0, $fp['titulo']);
            $im->writeImage('catalogo360/pages/' . $fp['foto']);
            $im->clear();
            $im->destroy();
            unset($im);
        }
        $XMLP->pages->addChild('page', 'pages/' . $fp['foto']);
    }
}
file_put_contents('catalogo360/marcadores.xml', $XML->asXML());
file_put_contents('catalogo360/config.xml', $XMLP->asXML());
 /**
  * Apply the transform to the sfImage object.
  *
  * @param sfImage
  * @return sfImage
  */
 protected function transform(sfImage $image)
 {
     $resource = $image->getAdapter()->getHolder();
     // By default use the background of the top left corner
     if (is_null($this->background)) {
         $this->background = $resource->getImagePixelColor(0, 0);
         $background = $this->background;
     } else {
         $background = new ImagickPixel();
         $background->setColor($this->background);
     }
     $resource->setBackgroundColor($background);
     $resource->trimImage($this->fuzz);
     return $image;
 }
Example #28
0
<?php

try {
    $pixel = new ImagickPixel('the-best-color-in-the-world');
} catch (ImagickPixelException $ex) {
    echo "__construct\n";
}
$pixel = new ImagickPixel('white');
try {
    $pixel->setColor('the-worst-color-in-the-world');
} catch (ImagickPixelException $ex) {
    echo "setColor\n";
}
define('IMAGICK_COLOR_INVALID', -1);
try {
    $pixel->getColorValue(IMAGICK_COLOR_INVALID);
} catch (ImagickPixelException $ex) {
    echo "getColorValue\n";
}
try {
    $pixel->setColorValue(IMAGICK_COLOR_INVALID, 0);
} catch (ImagickPixelException $ex) {
    echo "setColorValue\n";
}
try {
    $pixel->isPixelSimilar(new ImagickPixelException(), 0);
} catch (ImagickPixelException $ex) {
    echo "isPixelSimilar\n";
}
?>
==DONE==
Example #29
0
 public static function imagickcolortorgbhex(\ImagickPixel $color)
 {
     preg_match('#rgb\\(([0-9\\.]*?)%,([0-9\\.]*?)%,([0-9\\.]*?)%\\)#', $color->getcolorasstring(), $matches);
     list(, $r, $g, $b) = $matches;
     return dechex(255 * $r / 100) . dechex(255 * $g / 100) . dechex(255 * $b / 100);
 }
Example #30
0
function whirlyGif($numberDots, $numberFrames, $loopTime, $backgroundColor, $phaseMultiplier, $phaseDivider)
{
    $aniGif = new \Imagick();
    $aniGif->setFormat("gif");
    $width = 500;
    $height = $width;
    $numberDots = intval($numberDots);
    if ($numberDots < 1) {
        $numberDots = 1;
    }
    $maxFrames = $numberFrames;
    $frameDelay = ceil($loopTime / $maxFrames);
    $scale = 1;
    $startColor = new \ImagickPixel('red');
    $dots = [];
    for ($i = 0; $i < $numberDots; $i++) {
        $colorInfo = $startColor->getHSL();
        //Rotate the hue by 180 degrees
        $newHue = $colorInfo['hue'] + $i / $numberDots;
        if ($newHue > 1) {
            $newHue = $newHue - 1;
        }
        //Set the ImagickPixel to the new color
        $color = new \ImagickPixel('#ffffff');
        $colorInfo['saturation'] *= 0.95;
        $color->setHSL($newHue, $colorInfo['saturation'], $colorInfo['luminosity']);
        $dots[] = new Dot($color, $i, $numberDots, $width, $height);
    }
    for ($frame = 0; $frame < $maxFrames; $frame++) {
        $draw = new \ImagickDraw();
        $draw->setStrokeColor('none');
        $draw->setFillColor('none');
        $draw->rectangle(0, 0, $width, $height);
        $draw->translate($width / 2, $height / 2);
        foreach ($dots as $dot) {
            /** @var $dot Dot */
            $dot->render($draw, $frame, $maxFrames, $phaseMultiplier, $phaseDivider);
        }
        //Create an image object which the draw commands can be rendered into
        $imagick = new \Imagick();
        $imagick->newImage($width * $scale, $height * $scale, $backgroundColor);
        $imagick->setImageFormat("png");
        $imagick->setImageDispose(\Imagick::DISPOSE_PREVIOUS);
        //Render the draw commands in the ImagickDraw object
        //into the image.
        $imagick->drawImage($draw);
        $imagick->setImageDelay($frameDelay);
        $aniGif->addImage($imagick);
        $imagick->destroy();
    }
    $aniGif->setImageFormat('gif');
    $aniGif->setImageIterations(0);
    //loop forever
    $aniGif->mergeImageLayers(\Imagick::LAYERMETHOD_OPTIMIZEPLUS);
    header("Content-Type: image/gif");
    echo $aniGif->getImagesBlob();
}