Exemple #1
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);
 }
function setColor()
{
    $draw = new \ImagickDraw();
    $strokeColor = new \ImagickPixel('green');
    $fillColor = new \ImagickPixel();
    $fillColor->setColor('rgba(100%, 75%, 0%, 1.0)');
    $draw->setstrokewidth(3.0);
    $draw->setStrokeColor($strokeColor);
    $draw->setFillColor($fillColor);
    $draw->rectangle(200, 200, 300, 300);
    $image = new \Imagick();
    $image->newImage(500, 500, "SteelBlue2");
    $image->setImageFormat("png");
    $image->drawImage($draw);
    header("Content-Type: image/png");
    echo $image->getImageBlob();
}
Exemple #3
0
 /**
  * Function resize the Image on the fly with Imagemagick
  *
  * @param sting $strSrc
  * @param sting $intHeight
  * @param sting $intWidth
  *
  */
 function fnOnTheFlyImageResize($strSrc, $intHeight, $intWidth)
 {
     $strImageSrc = $strSrc;
     $strImageH = $intHeight;
     $strImageW = $intWidth;
     if (substr(trim($strImageSrc), 0, 4) == "http") {
         // SITENAME
         $strImageSrc = str_replace(SITE_NAME . "/", "", $strImageSrc);
         if (substr(trim($strImageSrc), 0, 4) == "user") {
             // NOT BSE64 DEODED
             $strImageSrc = base64_encode($strImageSrc);
         }
         if (substr(trim($strImageSrc), 0, 9) == "editorial") {
             // NOT BSE64 DEODED
             $strImageSrc = base64_encode($strImageSrc);
         }
     } elseif (substr(trim($strImageSrc), 0, 4) == "user") {
         // NOT BSE64 DEODED
         $strImageSrc = base64_encode($strImageSrc);
     } elseif (substr(trim($strImageSrc), 0, 5) == "/user") {
         // NOT BSE64 DEODED
         $strImageSrc = substr_replace("/", '', 0, 1);
         $strImageSrc = base64_encode($strImageSrc);
     }
     if (!$strImageH) {
         $strImageH = "70";
     }
     if (!$strImageW) {
         $strImageW = "70";
     }
     if ($strImageSrc != "") {
         // Decode image from base64
         $image = base64_decode($strImageSrc);
         //$image=$strImageSrc;
         // Create Imagick object
         $im = new Imagick();
         // Convert image into Imagick
         $im->readImage(DOCUMENT_ROOT . "/" . $image);
         //$im->readImage($image);
         // Create thumbnail max of 200x82
         $im->thumbnailImage($strImageW, $strImageH, true);
         // Add a subtle border
         $color = new ImagickPixel();
         $color->setColor("rgb(220,220,220)");
         $im->borderImage($color, 1, 1);
         // Output the image
         $output = $im->getimageblob();
         $outputtype = $im->getFormat();
         // unset($im);
         header("Content-type: {$outputtype}");
         print $output;
     }
 }
Exemple #4
0
 public function transform($operation, $parameters)
 {
     if ($this->properties["mimetype"] == "image/tilepic") {
         return false;
     }
     # no transformations for Tilepic
     if (!$this->handle) {
         return false;
     }
     if (!$this->info["TRANSFORMATIONS"][$operation]) {
         # invalid transformation
         $this->postError(1655, _t("Invalid transformation %1", $operation), "WLPlugImagick->transform()");
         return false;
     }
     # get parameters for this operation
     $sparams = $this->info["TRANSFORMATIONS"][$operation];
     $w = $parameters["width"];
     $h = $parameters["height"];
     $cw = $this->get("width");
     $ch = $this->get("height");
     if ((bool) $this->properties['no_upsampling']) {
         $w = min($cw, round($w));
         $h = min($ch, round($h));
     }
     $do_crop = 0;
     try {
         switch ($operation) {
             # -----------------------
             case 'ANNOTATE':
                 $d = new ImagickDraw();
                 if ($parameters['font']) {
                     $d->setFont($parameters['font']);
                 }
                 $size = $parameters['size'] > 0 ? $parameters['size'] : 18;
                 $d->setFontSize($size);
                 $inset = $parameters['inset'] > 0 ? $parameters['inset'] : 0;
                 $pw = new ImagickPixel();
                 $pw->setColor($parameters['color'] ? $parameters['color'] : "black");
                 $d->setFillColor($pw);
                 switch ($parameters['position']) {
                     case 'north_east':
                         $d->setGravity(imagick::GRAVITY_NORTHEAST);
                         break;
                     case 'north_west':
                         $d->setGravity(imagick::GRAVITY_NORTHWEST);
                         break;
                     case 'north':
                         $d->setGravity(imagick::GRAVITY_NORTH);
                         break;
                     case 'south_east':
                         $d->setGravity(imagick::GRAVITY_SOUTHEAST);
                         break;
                     case 'south':
                         $d->setGravity(imagick::GRAVITY_SOUTH);
                         break;
                     case 'center':
                         $d->setGravity(imagick::GRAVITY_CENTER);
                         break;
                     case 'south_west':
                     default:
                         $d->setGravity(imagick::GRAVITY_SOUTHWEST);
                         break;
                 }
                 $this->handle->annotateImage($d, $inset, $size + $inset, 0, $parameters['text']);
                 break;
                 # -----------------------
             # -----------------------
             case 'WATERMARK':
                 if (!file_exists($parameters['image'])) {
                     break;
                 }
                 $vn_opacity_setting = $parameters['opacity'];
                 if ($vn_opacity_setting < 0 || $vn_opacity_setting > 1) {
                     $vn_opacity_setting = 0.5;
                 }
                 $d = new ImagickDraw();
                 if (($vn_watermark_width = $parameters['width']) < 10) {
                     $vn_watermark_width = $cw / 2;
                 }
                 if (($vn_watermark_height = $parameters['height']) < 10) {
                     $vn_watermark_height = $ch / 2;
                 }
                 switch ($parameters['position']) {
                     case 'north_east':
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = 0;
                         break;
                     case 'north_west':
                         $vn_watermark_x = 0;
                         $vn_watermark_y = 0;
                         break;
                     case 'north':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = 0;
                         break;
                     case 'south_east':
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                     case 'south':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                     case 'center':
                         $vn_watermark_x = ($cw - $vn_watermark_width) / 2;
                         $vn_watermark_y = ($ch - $vn_watermark_height) / 2;
                         break;
                     case 'south_west':
                     default:
                         $vn_watermark_x = $cw - $vn_watermark_width;
                         $vn_watermark_y = $ch - $vn_watermark_height;
                         break;
                 }
                 $w = new Imagick();
                 if (!$w->readImage($parameters['image'])) {
                     $this->postError(1610, _t("Couldn't load watermark image at %1", $parameters['image']), "WLPlugImagick->transform:WATERMARK()");
                     return false;
                 }
                 //$w->evaluateImage(imagick::COMPOSITE_MINUS, $vn_opacity, imagick::CHANNEL_OPACITY) ; [seems broken with latest imagick circa March 2010?]
                 if (method_exists($w, "setImageOpacity")) {
                     // added in ImageMagick 6.3.1
                     $w->setImageOpacity($vn_opacity_setting);
                 }
                 $d->composite(imagick::COMPOSITE_DISSOLVE, $vn_watermark_x, $vn_watermark_y, $vn_watermark_width, $vn_watermark_height, $w);
                 $this->handle->drawImage($d);
                 break;
                 # -----------------------
             # -----------------------
             case 'SCALE':
                 $aa = $parameters["antialiasing"];
                 if ($aa <= 0) {
                     $aa = 0;
                 }
                 switch ($parameters["mode"]) {
                     # ----------------
                     case "width":
                         $scale_factor = $w / $cw;
                         $h = $ch * $scale_factor;
                         break;
                         # ----------------
                     # ----------------
                     case "height":
                         $scale_factor = $h / $ch;
                         $w = $cw * $scale_factor;
                         break;
                         # ----------------
                     # ----------------
                     case "bounding_box":
                         $scale_factor_w = $w / $cw;
                         $scale_factor_h = $h / $ch;
                         $w = $cw * ($scale_factor_w < $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $h = $ch * ($scale_factor_w < $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         break;
                         # ----------------
                     # ----------------
                     case "fill_box":
                         $crop_from = $parameters["crop_from"];
                         if (!in_array($crop_from, array('center', 'north_east', 'north_west', 'south_east', 'south_west', 'random'))) {
                             $crop_from = '';
                         }
                         $scale_factor_w = $w / $cw;
                         $scale_factor_h = $h / $ch;
                         $w = $cw * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $h = $ch * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h);
                         $do_fill_box_crop = true;
                         break;
                         # ----------------
                 }
                 $w = round($w);
                 $h = round($h);
                 if ($w > 0 && $h > 0) {
                     $crop_w_edge = $crop_h_edge = 0;
                     if (preg_match("/^([\\d]+)%\$/", $parameters["trim_edges"], $va_matches)) {
                         $crop_w_edge = ceil(intval($va_matches[1]) / 100 * $w);
                         $crop_h_edge = ceil(intval($va_matches[1]) / 100 * $h);
                     } else {
                         if (isset($parameters["trim_edges"]) && intval($parameters["trim_edges"]) > 0) {
                             $crop_w_edge = $crop_h_edge = intval($parameters["trim_edges"]);
                         }
                     }
                     if (!$this->handle->resizeImage($w + $crop_w_edge * 2, $h + $crop_h_edge * 2, imagick::FILTER_CUBIC, $aa)) {
                         $this->postError(1610, _t("Error during resize operation"), "WLPlugImagick->transform()");
                         return false;
                     }
                     if ($do_fill_box_crop) {
                         // use face detection info to intelligently crop
                         if (is_array($this->properties['faces']) && sizeof($this->properties['faces'])) {
                             $va_info = array_shift($this->properties['faces']);
                             $crop_from_offset_x = ceil($va_info['x'] * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h));
                             $crop_from_offset_x -= ceil(0.15 * $parameters["width"]);
                             // since face will be tightly cropped give it some room
                             $crop_from_offset_y = ceil($va_info['y'] * ($scale_factor_w > $scale_factor_h ? $scale_factor_w : $scale_factor_h));
                             $crop_from_offset_y -= ceil(0.15 * $parameters["height"]);
                             // since face will be tightly cropped give it some room
                             // Don't try to crop beyond image boundaries, you just end up scaling the image, often awkwardly
                             if ($crop_from_offset_x > $w - $parameters["width"]) {
                                 $crop_from_offset_x = 0;
                             }
                             if ($crop_from_offset_y > $h - $parameters["height"]) {
                                 $crop_from_offset_y = 0;
                             }
                             if ($crop_from_offset_x < 0) {
                                 $crop_from_offset_x = 0;
                             }
                             if ($crop_from_offset_y < 0) {
                                 $crop_from_offset_y = 0;
                             }
                         } else {
                             switch ($crop_from) {
                                 case 'north_west':
                                     $crop_from_offset_y = 0;
                                     $crop_from_offset_x = $w - $parameters["width"];
                                     break;
                                 case 'south_east':
                                     $crop_from_offset_x = 0;
                                     $crop_from_offset_y = $h - $parameters["height"];
                                     break;
                                 case 'south_west':
                                     $crop_from_offset_x = $w - $parameters["width"];
                                     $crop_from_offset_y = $h - $parameters["height"];
                                     break;
                                 case 'random':
                                     $crop_from_offset_x = rand(0, $w - $parameters["width"]);
                                     $crop_from_offset_y = rand(0, $h - $parameters["height"]);
                                     break;
                                 case 'north_east':
                                     $crop_from_offset_x = $crop_from_offset_y = 0;
                                     break;
                                 case 'center':
                                 default:
                                     if ($w > $parameters["width"]) {
                                         $crop_from_offset_x = ceil(($w - $parameters["width"]) / 2);
                                     } else {
                                         if ($h > $parameters["height"]) {
                                             $crop_from_offset_y = ceil(($h - $parameters["height"]) / 2);
                                         }
                                     }
                                     break;
                             }
                         }
                         if (!$this->handle->cropImage($parameters["width"], $parameters["height"], $crop_w_edge + $crop_from_offset_x, $crop_h_edge + $crop_from_offset_y)) {
                             $this->postError(1610, _t("Error during crop operation"), "WLPlugImagick->transform()");
                             return false;
                         }
                         $this->properties["width"] = $parameters["width"];
                         $this->properties["height"] = $parameters["height"];
                     } else {
                         if ($crop_w_edge || $crop_h_edge) {
                             if (!$this->handle->cropImage($w, $h, $crop_w_edge, $crop_h_edge)) {
                                 $this->postError(1610, _t("Error during crop operation"), "WLPlugImagick->transform()");
                                 return false;
                             }
                         }
                         $this->properties["width"] = $w;
                         $this->properties["height"] = $h;
                     }
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "ROTATE":
                 $angle = $parameters["angle"];
                 if ($angle > -360 && $angle < 360) {
                     if (!$this->handle->rotateImage("#FFFFFF", $angle)) {
                         $this->postError(1610, _t("Error during image rotate"), "WLPlugImagick->transform()");
                         return false;
                     }
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "DESPECKLE":
                 $radius = $parameters["radius"];
                 if (!$this->handle->despeckleImage()) {
                     $this->postError(1610, _t("Error during image despeckle"), "WLPlugImagick->transform:DESPECKLE()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "MEDIAN":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 if (!$this->handle->medianFilterImage($radius)) {
                     $this->postError(1610, _t("Error during image median filter"), "WLPlugImagick->transform:MEDIAN()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "SHARPEN":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 $sigma = $parameters["sigma"];
                 if ($sigma < 0.1) {
                     $sigma = 1;
                 }
                 if (!$this->handle->sharpenImage($radius, $sigma)) {
                     $this->postError(1610, _t("Error during image sharpen"), "WLPlugImagick->transform:SHARPEN()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "UNSHARPEN_MASK":
                 $radius = $parameters["radius"];
                 if ($radius < 0.1) {
                     $radius = 1;
                 }
                 $sigma = $parameters["sigma"];
                 if ($sigma < 0.1) {
                     $sigma = 1;
                 }
                 $threshold = $parameters["threshold"];
                 if ($threshold < 0.1) {
                     $threshold = 1;
                 }
                 $amount = $parameters["amount"];
                 if ($amount < 0.1) {
                     $amount = 1;
                 }
                 if (!$this->handle->unsharpMaskImage($radius, $sigma, $amount, $threshold)) {
                     $this->postError(1610, _t("Error during image unsharp mask"), "WLPlugImagick->transform:UNSHARPEN_MASK()");
                     return false;
                 }
                 break;
                 # -----------------------
             # -----------------------
             case "SET":
                 while (list($k, $v) = each($parameters)) {
                     $this->set($k, $v);
                 }
                 break;
                 # -----------------------
         }
         return 1;
     } catch (Exception $e) {
         $this->postError(1610, _t("Imagick exception"), "WLPlugImagick->transform");
         return false;
     }
 }
Exemple #5
0
 /**
  * Rotate image on specific angle
  *
  * @param int $angle
  * @return void
  */
 public function rotate($angle)
 {
     $this->_checkCanProcess();
     // compatibility with GD2 adapter
     $angle = 360 - $angle;
     $pixel = new \ImagickPixel();
     $pixel->setColor("rgb(" . $this->imageBackgroundColor . ")");
     $this->_imageHandler->rotateImage($pixel, $angle);
     $this->refreshImageDimensions();
 }
 /**
  * Default constructor
  * @param mixed|null $files
  */
 public function __construct($files = null)
 {
     parent::__construct($files);
     $this->black = new \ImagickPixel();
     $this->black->setColor("black");
 }
 /**
  * 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;
 }
Exemple #8
0
 public function border($width, $height, $color = 'rgb(220, 220, 220)')
 {
     $color = new ImagickPixel();
     $color->setColor($color);
     $this->image->borderImage($color, $width, $height);
 }
 /**
  * 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;
 }
 /**
  * @see	wcf\system\image\adapter\IImageAdapter::setColor()
  */
 public function setColor($red, $green, $blue)
 {
     $this->color = new \ImagickPixel();
     $this->color->setColor('rgb(' . $red . ',' . $green . ',' . $blue . ')');
 }
function borderImage($im, $borderWidth)
{
    $color = new ImagickPixel();
    $color->setColor("rgb(224,224,224)");
    $im->borderImage($color, $borderWidth, $borderWidth);
    $color->destroy();
    return $im;
}
<?php

require '../lib_config.php';
session();
$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 */
 /**
  * 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);
     $border = new ImagickPixel();
     $border->setColor($this->border);
     $resource->colorFloodfillImage($fill, $this->fuzz, $border, $this->x, $this->y);
     return $image;
 }
Exemple #14
0
<?php

// hphp doesn't support this at this moment
// ini_set('precision', 3);
function dump($exp)
{
    $ret = print_r($exp, true);
    $ret = preg_replace_callback('/\\d+\\.\\d+/', function ($matches) {
        return sprintf('%.3f', $matches[0]);
    }, $ret);
    echo "{$ret}\n";
}
$pixel = new ImagickPixel();
$pixel->setColor('yellow');
dump($pixel->getHSL());
dump($pixel->getColor(true));
$pixel = new ImagickPixel($pixel->getColorAsString());
dump($pixel->getHSL());
dump($pixel->getColor(false));
$pixel = new ImagickPixel();
$pixel->setHSL(0.3, 0.4, 0.5);
dump($pixel->getHSL());
dump($pixel->getColor(false));
$pixel = new ImagickPixel($pixel->getColorAsString());
dump($pixel->getHSL());
dump($pixel->getColor(true));
$pixel = new ImagickPixel('#F02B88');
$colors = array(Imagick::COLOR_BLACK, Imagick::COLOR_BLUE, Imagick::COLOR_CYAN, Imagick::COLOR_GREEN, Imagick::COLOR_RED, Imagick::COLOR_YELLOW, Imagick::COLOR_MAGENTA, Imagick::COLOR_ALPHA, Imagick::COLOR_FUZZ);
foreach ($colors as $color) {
    dump($pixel->getColorValue($color));
}
Exemple #15
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();
Exemple #16
0
 public function brushpng($color, $size, $brushpath)
 {
     $info = $this->_handle->getImageGeometry();
     $image = new \Imagick();
     $image->newImage($info["width"], $info["height"], "transparent", "png");
     //$image->setImageFormat("png");
     $draw = new \ImagickDraw();
     $pixel = new \ImagickPixel();
     $pixel->setColor("transparent");
     $draw->setFillColor($pixel);
     $pixel->setColor($color);
     $draw->setStrokeColor($pixel);
     $draw->setStrokeWidth($size);
     $draw->setStrokeLineCap(\imagick::LINECAP_ROUND);
     $draw->setStrokeLineJoin(\imagick::LINEJOIN_ROUND);
     $draw->polyline($brushpath);
     $image->drawImage($draw);
     $pixel->destroy();
     $draw->destroy();
     $this->_handle = $image;
 }
 /**
  * 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;
 }
Exemple #18
0
 /**
  * @param int $dw
  * @param bool $pdfLogo
  * @param int $pdfLogoSize
  */
 public function showImg($dw = 500, $pdfLogo = false, $pdfLogoSize = 128)
 {
     $cachename = $this->fullpath . $dw . $this->pageid . ".png";
     $cacheimg = $this->cachepath . '/' . $this->_nameFilter($cachename);
     if (class_exists('Imagick')) {
         try {
             $im = $this->_dataCacher($cachename);
             if ($im === false) {
                 $this->_logToFile('File not in cache');
                 $im = new imagick($this->fullpath . '[' . $this->pageid . ']');
                 //$im->setSize($dw*2,$dw*2);
                 $im->setImageFormat("png");
                 $im->adaptiveResizeImage($dw, $dw, true);
                 // add a border to the image
                 $color = new ImagickPixel();
                 $color->setColor("rgb(200,200,200)");
                 $im->borderImage($color, 1, 1);
                 // draw the PDF icon on top of the PDF preview
                 if ($pdfLogo) {
                     $pdflogo = new Imagick($this->assetsPath . $this->deficon);
                     $pdflogo->adaptiveResizeImage($pdfLogoSize, $pdfLogoSize);
                     $im->compositeImage($pdflogo, Imagick::COMPOSITE_DEFAULT, 1, 1);
                 }
                 $this->_dataCacher($cachename, $im);
                 $im->writeImage($cacheimg);
             } else {
                 $this->_logToFile('File IS cached');
             }
             header("Content-Type: image/png");
             header("Content-Disposition: attachment; filename=\"" . $cachename . ".png\";");
             $this->getRawFile($cacheimg, false, 'PNG', true);
         } catch (Exception $e) {
             return parent::showImg($dw);
         }
     } else {
         return parent::showImg($dw);
     }
 }
Exemple #19
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==
Exemple #20
0
 /**
  * @param string $code
  * @param int    $width
  * @param int    $height
  *
  * @return \ManaPHP\Http\ResponseInterface
  */
 protected function _generateByImagic($code, $width, $height)
 {
     $image = new \Imagick();
     $draw = new \ImagickDraw();
     $image->newImage($width, $height, new \ImagickPixel('rgb(' . $this->_bgRGB . ')'));
     $draw->setFont($this->alias->resolve($this->_fonts[(int) (mt_rand() % count($this->_fonts))]));
     $draw->setGravity(\Imagick::GRAVITY_NORTHWEST);
     $referenceFontSize = min($height, $width / $this->_length);
     $x = mt_rand($referenceFontSize * 0.1, $referenceFontSize * 0.3);
     $length = strlen($code);
     $fgPixel = new \ImagickPixel();
     /** @noinspection ForeachInvariantsInspection */
     for ($i = 0; $i < $length; $i++) {
         $fontSize = $referenceFontSize * mt_rand(800, 1000) / 1000;
         $draw->setFontSize($fontSize);
         $fgPixel->setColor('rgb(' . mt_rand(0, 240) . ',' . mt_rand(0, 240) . ',' . mt_rand(0, 240) . ')');
         $draw->setFillColor($fgPixel);
         $angle = mt_rand(-$this->_angleAmplitude, $this->_angleAmplitude);
         $y = ($height - $referenceFontSize) * mt_rand(-1000, 1000) / 1000;
         $image->annotateImage($draw, $x, $y, $angle, $code[$i]);
         $x += $fontSize * mt_rand(600, 800) / 1000;
         for ($k = 0; $k < $this->_noiseCharCount; $k++) {
             $letter = $this->_charset[(int) (mt_rand() % strlen($this->_charset))];
             $fgPixel->setColor('rgb(' . mt_rand(0, 240) . ',' . mt_rand(0, 240) . ',' . mt_rand(0, 240) . ')');
             $draw->setFillColor($fgPixel);
             $draw->setFontSize($fontSize * 0.4 * $this->_rand_amplitude(0.1));
             $angle = mt_rand(-40, 40);
             $image->annotateImage($draw, $x + mt_rand(-700, 700) / 1000 * $fontSize, $fontSize / 2 + mt_rand(-$fontSize * 0.5, $fontSize * 0.5), $angle, $letter);
         }
     }
     $this->response->setContentType('image/jpeg');
     $image->setImageFormat('jpeg');
     $this->response->setContent((string) $image);
     $image->destroy();
     $fgPixel->destroy();
     $draw->destroy();
     return $this->response;
 }
Exemple #21
0
    //$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());
echo $XML->asXML();
Exemple #22
0
<?php

/*
  A very primitive captcha implementation
*/
/* Create Imagick object */
$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('white');
/* 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 */
//$ImagickDraw->setFont( 'Helvetica Regular' );
$ImagickDraw->setFontSize(20);
/* Create the text */
$alphanum = 'ABXZRMHTL23456789';
$string = substr(str_shuffle($alphanum), 2, 6);
$string = "Imagick2";
/* Create new empty image */
$Imagick->newImage(85, 30, $bg);
/* Write the text on the image */
$Imagick->annotateImage($ImagickDraw, 4, 20, 0, $string);
/* Add some swirl */
$Imagick->swirlImage(20);
/* Create a few random lines */
$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));
Exemple #23
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();
 }
Exemple #24
0
 /**
  * 使用imagick扩展生成验证码图片
  * @param int $img_width
  * @param int $img_height
  * @param bool $addRandomLines
  * @param bool $swirl
  * @return array
  */
 static function verifycode_imagick($img_width = 80, $img_height = 30, $addRandomLines = true, $swirl = true)
 {
     $fontSize = 24;
     /* imagick对象 */
     $Imagick = new \Imagick();
     /* 背景对象 */
     $bg = new \ImagickPixel();
     /* Set the pixel color to white */
     $bg->setColor('rgb(235,235,235)');
     /* 画刷 */
     $ImagickDraw = new \ImagickDraw();
     if (is_file(self::$verifyCodeFontFile)) {
         $ImagickDraw->setFont(self::$verifyCodeFontFile);
     }
     $ImagickDraw->setFontSize($fontSize);
     $ImagickDraw->setFillColor('black');
     $code = strtoupper(RandomKey::string(self::$verifyCodeLength));
     /* Create new empty image */
     $Imagick->newImage($img_width, $img_height, $bg);
     /* Write the text on the image */
     $Imagick->annotateImage($ImagickDraw, 4, 20, 0, $code);
     /* 变形 */
     if ($swirl) {
         $Imagick->swirlImage(10);
     }
     /* 随即线条 */
     if ($addRandomLines) {
         $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 */
     return array('image' => $Imagick->getImageBlob(), 'code' => $code);
 }