Ejemplo n.º 1
0
 /**
  * Const'r
  *
  * @see Horde_Image_Base::_construct
  */
 public function __construct($params, $context = array())
 {
     if (!Horde_Util::loadExtension('imagick')) {
         throw new Horde_Image_Exception('Required PECL Imagick extension not found.');
     }
     parent::__construct($params, $context);
     ini_set('imagick.locale_fix', 1);
     $this->_imagick = new Imagick();
     if (!empty($params['filename'])) {
         $this->loadFile($params['filename']);
     } elseif (!empty($params['data'])) {
         $this->loadString($params['data']);
     } else {
         $this->_width = max(array($this->_width, 1));
         $this->_height = max(array($this->_height, 1));
         try {
             $this->_imagick->newImage($this->_width, $this->_height, $this->_background);
         } catch (ImagickException $e) {
             throw new Horde_Image_Exception($e);
         }
     }
     try {
         $this->_imagick->setImageFormat($this->_type);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
 }
Ejemplo n.º 2
0
 public function create($width, $height, $color = 0xffffff, $opacity = 0)
 {
     $this->image = new $this->image_class();
     $this->image->newImage($width, $height, $this->get_color($color, $opacity));
     $this->update_size($width, $height);
     $this->format = 'png';
     return $this;
 }
Ejemplo n.º 3
0
 public function makeImageOfCertification()
 {
     date_default_timezone_set('UTC');
     $timeStamp = date('jS F Y');
     $text = "CERTIFIED COPY" . "\n" . $this->serial . "\n" . $timeStamp;
     $image = new \Imagick();
     $draw = new \ImagickDraw();
     $color = new \ImagickPixel('#000000');
     $background = new \ImagickPixel("rgb(85, 196, 241)");
     $draw->setFont($this->container->getParameter('assetic.write_to') . $this->container->get('templating.helper.assets')->getUrl('fonts/futura.ttf'));
     $draw->setFontSize(24);
     $draw->setFillColor($color);
     $draw->setTextAntialias(true);
     $draw->setStrokeAntialias(true);
     //Align text to the center of the background
     $draw->setTextAlignment(\Imagick::ALIGN_CENTER);
     //Get information of annotation image
     $metrics = $image->queryFontMetrics($draw, $text);
     //Calc the distance(pixels) to move the sentences
     $move = $metrics['textWidth'] / 2;
     $draw->annotation($move, $metrics['ascender'], $text);
     //Create an image of certification
     $image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
     $image->setImageFormat('png');
     $image->drawImage($draw);
     //Save an image temporary
     $image->writeImage("cert_" . $this->serial . "_.png");
 }
Ejemplo n.º 4
0
function build_sprite($sprite)
{
    global $db, $SPRITES_DIR;
    if (!class_exists("Imagick")) {
        return;
    }
    $BGCOLOR = '#FDFEFD';
    $WIDTH = $sprite == 3 ? 40 : 20;
    $HEIGHT = 20;
    $query = $db->query("SELECT COUNT(*) AS count FROM teams WHERE sprite={$sprite}");
    $row = $query->fetch();
    $count = $row['count'] + 1;
    $spriteWidth = $WIDTH;
    $spriteHeight = $count * ($HEIGHT + 1) - 1;
    $DIR = "{$SPRITES_DIR}/sprite{$sprite}/";
    $s = new Imagick();
    $s->newImage($spriteWidth, $spriteHeight, new ImagickPixel($BGCOLOR), 'gif');
    $s->paintTransparentImage(new ImagickPixel($BGCOLOR), 0.0, 0);
    // Create the default (empty) crest.
    addCrest($s, $DIR . '_unknown.gif', 0);
    $offset = $HEIGHT + 1;
    $query = $db->query("SELECT * FROM teams WHERE sprite={$sprite}");
    while ($row = $query->fetch()) {
        addCrest($s, $DIR . $row['fileName'], $offset);
        $offset += $HEIGHT + 1;
    }
    $s->writeImage("{$SPRITES_DIR}/s{$sprite}.gif");
    $s->destroy();
}
 /**
  * Return a PNG image representation of barcode (requires GD or Imagick library).
  *
  * @param string $code code to print
  * @param string $type type of barcode:
  * @param int $widthFactor Width of a single bar element in pixels.
  * @param int $totalHeight Height of a single bar element in pixels.
  * @param array $color RGB (0-255) foreground color for bar elements (background is transparent).
  * @return \Imagick imagick object with barcode
  * @public
  */
 public function getBarcode($code, $type, $widthFactor = 2, $totalHeight = 30, $color = array(0, 0, 0))
 {
     $barcodeData = $this->getBarcodeData($code, $type);
     // calculate image size
     $width = $barcodeData['maxWidth'] * $widthFactor;
     $height = $totalHeight;
     $colorForeground = new \imagickpixel('rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')');
     $png = new \Imagick();
     $png->newImage($width, $height, 'none', 'png');
     $imageMagickObject = new \imagickdraw();
     $imageMagickObject->setFillColor($colorForeground);
     $imageMagickObject->setStrokeAntialias(false);
     $imageMagickObject->setStrokeColor('rgb(255,255,255)');
     // print bars
     $positionHorizontal = 0;
     foreach ($barcodeData['bars'] as $bar) {
         $bw = round($bar['width'] * $widthFactor, 3);
         $bh = round($bar['height'] * $totalHeight / $barcodeData['maxHeight'], 3);
         if ($bar['drawBar']) {
             $y = round($bar['positionVertical'] * $totalHeight / $barcodeData['maxHeight'], 3);
             // draw a vertical bar
             $imageMagickObject->rectangle($positionHorizontal, $y, $positionHorizontal + $bw, $y + $bh);
         }
         $positionHorizontal += $bw;
     }
     $png->drawImage($imageMagickObject);
     return $png;
 }
Ejemplo n.º 6
0
 public function softThumb($width, $height, $path, $bg = 'transparent')
 {
     if ($this->originImage) {
         echo "\nWrite image to `{$path}`\n";
         $resizeParams = $this->getSizes($width, $height);
         $overlay = clone $this->originImage;
         $overlay->scaleImage($resizeParams['width'], $resizeParams['height']);
         $overlayGeo = $overlay->getImageGeometry();
         if ($overlayGeo['width'] > $overlayGeo['height']) {
             $resizeParams['top'] = ($height - $overlayGeo['height']) / 2;
             $resizeParams['left'] = 0;
         } else {
             $resizeParams['top'] = 0;
             $resizeParams['left'] = ($width - $overlayGeo['width']) / 2;
         }
         $thumb = new \Imagick();
         $thumb->newImage($width, $height, $bg);
         $thumb->setImageFormat("png");
         $thumb->setCompression(\Imagick::COMPRESSION_ZIP);
         $thumb->setImageCompressionQuality(0);
         $thumb->compositeImage($overlay, \Imagick::COMPOSITE_DEFAULT, $resizeParams['left'], $resizeParams['top']);
         $thumb->writeImageFile(fopen($path, "wb"));
         $thumb->destroy();
     } else {
         throw new \Exception("As first You must load image", 404);
     }
 }
Ejemplo n.º 7
0
 /**
  * Applies the effect.
  */
 public function apply()
 {
     if (!method_exists($this->_image->imagick, 'polaroidImage') || !method_exists($this->_image->imagick, 'trimImage')) {
         throw new Horde_Image_Exception('Your version of Imagick is not compiled against a recent enough ImageMagick library to use the PolaroidImage effect.');
     }
     try {
         // This determines the color of the underlying shadow.
         $this->_image->imagick->setImageBackgroundColor(new ImagickPixel($this->_params['shadowcolor']));
         $this->_image->imagick->polaroidImage(new ImagickDraw(), $this->_params['angle']);
         // We need to create a new image to composite the polaroid over.
         // (yes, even if it's a transparent background evidently)
         $size = $this->_image->getDimensions();
         $imk = new Imagick();
         $imk->newImage($size['width'], $size['height'], $this->_params['background']);
         $imk->setImageFormat($this->_image->getType());
         $result = $imk->compositeImage($this->_image->imagick, Imagick::COMPOSITE_OVER, 0, 0);
         $this->_image->imagick->clear();
         $this->_image->imagick->addImage($imk);
     } catch (ImagickPixelException $e) {
         throw new Horde_Image_Exception($e);
     } catch (ImagickDrawException $e) {
         throw new Horde_Image_Exception($e);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     $imk->destroy();
 }
Ejemplo n.º 8
0
 public function renderImage()
 {
     //Create a ImagickDraw object to draw into.
     $draw = new \ImagickDraw();
     $darkColor = new \ImagickPixel('brown');
     //http://www.imagemagick.org/Usage/compose/#compose_terms
     $draw->setStrokeColor($darkColor);
     $draw->setFillColor('white');
     $draw->setStrokeWidth(2);
     $draw->setFontSize(72);
     $draw->setStrokeOpacity(1);
     $draw->setStrokeColor($darkColor);
     $draw->setStrokeWidth(2);
     $draw->setFont("../fonts/CANDY.TTF");
     $draw->setFontSize(140);
     $draw->setFillColor('none');
     $draw->rectangle(0, 0, 1000, 300);
     $draw->setFillColor('white');
     $draw->annotation(50, 180, "Lorem Ipsum!");
     $imagick = new \Imagick(realpath("images/TestImage.jpg"));
     $draw->composite(\Imagick::COMPOSITE_MULTIPLY, -500, -200, 2000, 600, $imagick);
     //Create an image object which the draw commands can be rendered into
     $imagick = new \Imagick();
     $imagick->newImage(1000, 300, "SteelBlue2");
     $imagick->setImageFormat("png");
     //Render the draw commands in the ImagickDraw object
     //into the image.
     $imagick->drawImage($draw);
     //Send the image to the browser
     header("Content-Type: image/png");
     echo $imagick->getImageBlob();
 }
Ejemplo n.º 9
0
 /**
  * アバター自動生成処理
  *
  * @param Model $model ビヘイビア呼び出し元モデル
  * @param array $user ユーザデータ配列
  * @return mixed On success Model::$data, false on failure
  * @throws InternalErrorException
  */
 public function createAvatarAutomatically(Model $model, $user)
 {
     //imagickdraw オブジェクトを作成します
     $draw = new ImagickDraw();
     //文字色のセット
     $draw->setfillcolor('white');
     //フォントサイズを 160 に設定します
     $draw->setFontSize(140);
     //テキストを追加します
     $draw->setFont(CakePlugin::path($model->plugin) . 'webroot' . DS . 'fonts' . DS . 'ipaexg.ttf');
     $draw->annotation(19, 143, mb_substr(mb_convert_kana($user['User']['handlename'], 'KVA'), 0, 1));
     //新しいキャンバスオブジェクトを作成する
     $canvas = new Imagick();
     //ランダムで背景色を指定する
     $red1 = strtolower(dechex(mt_rand(3, 12)));
     $red2 = strtolower(dechex(mt_rand(0, 15)));
     $green1 = strtolower(dechex(mt_rand(3, 12)));
     $green2 = strtolower(dechex(mt_rand(0, 15)));
     $blue1 = strtolower(dechex(mt_rand(3, 12)));
     $blue2 = strtolower(dechex(mt_rand(0, 15)));
     $canvas->newImage(179, 179, '#' . $red1 . $red2 . $green1 . $green2 . $blue1 . $blue2);
     //ImagickDraw をキャンバス上に描画します
     $canvas->drawImage($draw);
     //フォーマットを PNG に設定します
     $canvas->setImageFormat('png');
     App::uses('TemporaryFolder', 'Files.Utility');
     $folder = new TemporaryFolder();
     $filePath = $folder->path . DS . Security::hash($user['User']['handlename'], 'md5') . '.png';
     $canvas->writeImages($filePath, true);
     return $filePath;
 }
Ejemplo n.º 10
0
 function create_mask($image_path_1, $image_path_2, $mask_path, $step_width, $step_height)
 {
     $info = new Imagick($image_path_1);
     $mask = new Imagick();
     $mask->newImage($info->width, $info->height, 'none');
     $mask->setImageFormat('png');
     $chunk = new Imagick();
     $chunk->newImage($step_width, $step_height, new ImagickPixel('black'));
     $chunk->setImageFormat('png');
     $prefix1 = basename($image_path_1, '.png');
     $prefix2 = basename($image_path_2, '.png');
     $paths = glob("process/{$prefix1}*.png");
     foreach ($paths as $path) {
         $path2 = "process/" . $prefix2 . substr(basename($path), strlen($prefix2));
         // compare 1 and 2
         $a = new Imagick($path);
         $b = new Imagick($path2);
         $diff = $a->compareImages($b, Imagick::METRIC_MEANSQUAREERROR);
         if ($diff[1] > 0) {
             preg_match('~.*?(\\d+)\\-(\\d+).png~', $path, $m) or die("Issue fetching the x y from {$path}\r\n");
             $mask->compositeImage($chunk, Imagick::COMPOSITE_DEFAULT, $m[1], $m[2]);
         }
     }
     $mask->writeImage($mask_path);
 }
Ejemplo n.º 11
0
 /**
  * 生成验证码
  * @param  string $file 图片保存文件名,不指定则图片会被直接输出
  * @return null
  */
 public function get($file = "")
 {
     $support = $this->support();
     list($code, $answer) = $this->generateCode();
     $image = null;
     @session_start();
     $_SESSION['vitex.captcha.answer'] = strtolower($answer);
     if ($support == 'imagick') {
         $image = new \Imagick();
         $image->newImage($this->width, $this->height, "none");
         $image->setImageFormat('png');
         $image = $this->imagickLine($image, $this->linenum);
         $image = $this->imagickDrawText($image, $code);
         $image->swirlImage(30);
         $image->oilPaintImage(1);
         if ($file) {
             $image->writeImage($file);
         } else {
             header("Content-type:image/png");
             echo $image->getImageBlob();
         }
     } else {
         $image = imagecreate($this->width, $this->height);
         $color = imagecolorallocate($image, 255, 255, 255);
         imagecolortransparent($image, $color);
         $this->gdLine($image, $this->linenum);
         $this->gdDrawText($image, $code);
         if ($file) {
             imagepng($image, $file);
         } else {
             header("Content-type: image/jpeg; Cache-Control: no-store, no-cache, must-revalidate");
             imagepng($image);
         }
     }
 }
Ejemplo n.º 12
0
 private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4, $format = "png", $quality = 85, $filename = FALSE, $save = TRUE, $print = false)
 {
     $imgH = count($frame);
     $imgW = strlen($frame[0]);
     $col[0] = new \ImagickPixel("white");
     $col[1] = new \ImagickPixel("black");
     $image = new \Imagick();
     $image->newImage($imgW, $imgH, $col[0]);
     $image->setCompressionQuality($quality);
     $image->setImageFormat($format);
     $draw = new \ImagickDraw();
     $draw->setFillColor($col[1]);
     for ($y = 0; $y < $imgH; $y++) {
         for ($x = 0; $x < $imgW; $x++) {
             if ($frame[$y][$x] == '1') {
                 $draw->point($x, $y);
             }
         }
     }
     $image->drawImage($draw);
     $image->borderImage($col[0], $outerFrame, $outerFrame);
     $image->scaleImage(($imgW + 2 * $outerFrame) * $pixelPerPoint, 0);
     if ($save) {
         if ($filename === false) {
             throw new Exception("QR Code filename can't be empty");
         }
         $image->writeImages($filename, true);
     }
     if ($print) {
         Header("Content-type: image/" . $format);
         echo $image;
     }
 }
Ejemplo n.º 13
0
 protected function save($path)
 {
     $pathinfo = pathinfo($path);
     if (!file_exists($pathinfo['dirname'])) {
         mkdir($pathinfo['dirname'], 0777, true);
     }
     try {
         $image = new \Imagick($this->source);
         $image->thumbnailImage($this->width, $this->height, true);
         if ($this->color) {
             $thumb = $image;
             $image = new \Imagick();
             $image->newImage($this->width, $this->height, $this->color, $pathinfo['extension']);
             $size = $thumb->getImageGeometry();
             $x = ($this->width - $size['width']) / 2;
             $y = ($this->height - $size['height']) / 2;
             $image->compositeImage($thumb, \imagick::COMPOSITE_OVER, $x, $y);
             $thumb->destroy();
         }
         $image->writeImage($path);
         $image->destroy();
     } catch (\Exception $e) {
     }
     return $this;
 }
Ejemplo n.º 14
0
 /**
  * Creates a cover image for the given album.
  *
  * @param \Photo\Model\Album $album The album to create a cover image for.
  *
  * @return \Imagick The cover image.
  */
 protected function generateCover($album)
 {
     $config = $this->getConfig();
     $columns = $config['album_cover']['cols'];
     $rows = $config['album_cover']['rows'];
     $count = $columns * $rows;
     $images = $this->getImages($album, $count);
     /*
      * If there are not enough images available to fill the matrix we
      * reduce the amount of rows and columns
      */
     while (count($images) < $count) {
         if ($columns < $rows) {
             $rows--;
         } else {
             $columns--;
         }
         $count = $rows * $columns;
     }
     // Make a blank canvas
     $target = new \Imagick();
     $target->newImage($config['album_cover']['width'], $config['album_cover']['height'], $config['album_cover']['background']);
     if (count($images) > 0) {
         $this->drawComposition($target, $columns, $rows, $images);
     }
     $target->setImageFormat("png");
     return $target;
 }
Ejemplo n.º 15
0
 /**
  * Create a new empty (1 x 1 px) gd true colour image
  *
  * @param integer Image width
  * @param integer Image Height
  */
 public function create($x = 1, $y = 1)
 {
     $image = new Imagick();
     $image->newImage($x, $y, new ImagickPixel('white'));
     $image->setImageFormat('png');
     $this->setHolder($image);
 }
Ejemplo n.º 16
0
 public function resizeTo($width, $height)
 {
     if (osc_use_imagick()) {
         $bg = new Imagick();
         $bg->newImage($width, $height, 'white');
         $this->im->thumbnailImage($width, $height, true);
         $geometry = $this->im->getImageGeometry();
         $x = ($width - $geometry['width']) / 2;
         $y = ($height - $geometry['height']) / 2;
         $bg->compositeImage($this->im, imagick::COMPOSITE_OVER, $x, $y);
         $this->im = $bg;
     } else {
         $w = imagesx($this->im);
         $h = imagesy($this->im);
         if ($w / $h >= $width / $height) {
             //$newW = $width;
             $newW = $w > $width ? $width : $w;
             $newH = $h * ($newW / $w);
         } else {
             //$newH = $height;
             $newH = $h > $height ? $height : $h;
             $newW = $w * ($newH / $h);
         }
         $newIm = imagecreatetruecolor($width, $height);
         //$newW, $newH);
         imagealphablending($newIm, false);
         $colorTransparent = imagecolorallocatealpha($newIm, 255, 255, 255, 127);
         imagefill($newIm, 0, 0, $colorTransparent);
         imagesavealpha($newIm, true);
         imagecopyresampled($newIm, $this->im, ($width - $newW) / 2, ($height - $newH) / 2, 0, 0, $newW, $newH, $w, $h);
         imagedestroy($this->im);
         $this->im = $newIm;
     }
     return $this;
 }
 function writeText($text)
 {
     if ($this->printer == null) {
         throw new LogicException("Not attached to a printer.");
     }
     if ($text == null) {
         return;
     }
     $text = trim($text, "\n");
     /* Create Imagick objects */
     $image = new Imagick();
     $draw = new ImagickDraw();
     $color = new ImagickPixel('#000000');
     $background = new ImagickPixel('white');
     /* Create annotation */
     //$draw -> setFont('Arial');// (not necessary?)
     $draw->setFontSize(24);
     // Size 21 looks good for FONT B
     $draw->setFillColor($color);
     $draw->setStrokeAntialias(true);
     $draw->setTextAntialias(true);
     $metrics = $image->queryFontMetrics($draw, $text);
     $draw->annotation(0, $metrics['ascender'], $text);
     /* Create image & draw annotation on it */
     $image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
     $image->setImageFormat('png');
     $image->drawImage($draw);
     //$image -> writeImage("test.png");
     /* Save image */
     $escposImage = new EscposImage();
     $escposImage->readImageFromImagick($image);
     $size = Escpos::IMG_DEFAULT;
     $this->printer->bitImage($escposImage, $size);
 }
Ejemplo n.º 18
0
 function page_testfonts()
 {
     //load background
     $im = new Imagick();
     $im->newimage(800, 10000, 'lightgray');
     $y = 10;
     $i = 1;
     foreach ($im->queryFonts() as $font) {
         $insert_image = new Imagick();
         $insert_image->newImage(600, 30, 'whitesmoke');
         $insert_image->setImageFormat("png");
         $draw = new ImagickDraw();
         $draw->setFont($font);
         $draw->setFontSize(25);
         $draw->setFillColor(new ImagickPixel('black'));
         $draw->setgravity(imagick::GRAVITY_NORTH);
         $insert_image->annotateImage($draw, 0, 0, 0, $i . '.' . $font);
         $im->compositeImage($insert_image, $insert_image->getImageCompose(), 100, $y);
         $y += 30;
         $i++;
     }
     $im->setImageFormat('jpg');
     header('Content-Type: image/jpg');
     echo $im;
 }
Ejemplo n.º 19
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
            );
        }
    }
 /**
  * Reduces colors of a given image
  *
  * @param  Intervention\Image\Image $image
  * @return boolean
  */
 public function execute($image)
 {
     $count = $this->argument(0)->value();
     $matte = $this->argument(1)->value();
     // get current image size
     $size = $image->getSize();
     // build 2 color alpha mask from original alpha
     $alpha = clone $image->getCore();
     $alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
     $alpha->transparentPaintImage('#ffffff', 0, 0, false);
     $alpha->separateImageChannel(\Imagick::CHANNEL_ALPHA);
     $alpha->negateImage(false);
     if ($matte) {
         // get matte color
         $mattecolor = $image->getDriver()->parseColor($matte)->getPixel();
         // create matte image
         $canvas = new \Imagick();
         $canvas->newImage($size->width, $size->height, $mattecolor, 'png');
         // lower colors of original and copy to matte
         $image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false);
         $canvas->compositeImage($image->getCore(), \Imagick::COMPOSITE_DEFAULT, 0, 0);
         // copy new alpha to canvas
         $canvas->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
         // replace core
         $image->setCore($canvas);
     } else {
         $image->getCore()->quantizeImage($count, \Imagick::COLORSPACE_RGB, 0, false, false);
         $image->getCore()->compositeImage($alpha, \Imagick::COMPOSITE_COPYOPACITY, 0, 0);
     }
     return true;
 }
Ejemplo n.º 21
0
 function imagick_thumbnail($image, $timage, $ext, $thumbnail_name, $imginfo)
 {
     try {
         $imagick = new Imagick();
         $fullpath = "./" . $this->thumbnail_path . "/" . $timage[0] . "/" . $thumbnail_name;
         if ($ext == "gif") {
             $imagick->readImage($image . '[0]');
         } else {
             $imagick->readImage($image);
         }
         $info = $imagick->getImageGeometry();
         $this->info[0] = $info['width'];
         $this->info[1] = $info['height'];
         $imagick->thumbnailImage($this->dimension, $this->dimension, true);
         if ($ext == "png" || $ext == "gif") {
             $white = new Imagick();
             $white->newImage($this->dimension, $this->dimension, "white");
             $white->compositeimage($image, Imagick::COMPOSITE_OVER, 0, 0);
             $white->writeImage($fullpath);
             $white->clear();
         } else {
             $imagick->writeImage($fullpath);
         }
         $imagick->clear();
     } catch (Exception $e) {
         echo "Unable to load image." . $e->getMessage();
         return false;
     }
     return true;
 }
Ejemplo n.º 22
0
 /**
  * Creates a blank image.
  *
  * @param integer $width
  * @param integer $height
  *
  * @return XenForo_Image_Imagemagick_Pecl
  */
 public static function createImageDirect($width, $height)
 {
     $instance = new Imagick();
     // background colour is transparent with none
     $instance->newImage($width, $height, new ImagickPixel('none'));
     $class = XenForo_Application::resolveDynamicClass(__CLASS__);
     return new $class($instance);
 }
Ejemplo n.º 23
0
 /**
  * Create an image resource
  *
  * @see ImageTransform\FileAccessAdapter
  *
  * @param integer              $width  Width of the image to be created
  * @param integer              $height Height of the image to be created
  */
 public function create($width, $height)
 {
     $resource = new \Imagick();
     $resource->newImage($width, $height, new \ImagickPixel('none'));
     $this->set('image.resource', $resource);
     $this->set('image.width', $width);
     $this->set('image.height', $height);
 }
Ejemplo n.º 24
0
 function init($width, $height, $background, $format)
 {
     $img = new Imagick();
     $this->id = new ImagickDraw();
     $img->newImage($width, $height, new ImagickPixel($background));
     $img->setImageFormat("png");
     $this->im = $img;
 }
Ejemplo n.º 25
0
 public function makeBarcodePNG($w = 2, $h = 30, $color = array(0, 0, 0))
 {
     // calculate image size
     $width = $this->barcode_array['maxw'] * $w;
     $height = $h;
     if (function_exists('imagecreate')) {
         // GD library
         $imagick = false;
         $png = imagecreate($width, $height);
         $bgcol = imagecolorallocate($png, 255, 255, 255);
         imagecolortransparent($png, $bgcol);
         $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]);
     } elseif (extension_loaded('imagick')) {
         $imagick = true;
         $bgcol = new imagickpixel('rgb(255,255,255');
         $fgcol = new imagickpixel('rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')');
         $png = new Imagick();
         $png->newImage($width, $height, 'none', 'png');
         $bar = new imagickdraw();
         $bar->setfillcolor($fgcol);
     } else {
         return false;
     }
     // print bars
     $x = 0;
     foreach ($this->barcode_array['bcode'] as $k => $v) {
         $bw = round($v['w'] * $w, 3);
         $bh = round($v['h'] * $h / $this->barcode_array['maxh'], 3);
         if ($v['t']) {
             $y = round($v['p'] * $h / $this->barcode_array['maxh'], 3);
             // draw a vertical bar
             if ($imagick) {
                 $bar->rectangle($x, $y, $x + $bw - 1, $y + $bh - 1);
             } else {
                 imagefilledrectangle($png, $x, $y, $x + $bw - 1, $y + $bh - 1, $fgcol);
             }
         }
         $x += $bw;
     }
     // send headers
     //header('Content-Type: image/png');
     //header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
     //header('Pragma: public');
     //header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
     //header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
     if ($imagick) {
         $png->drawimage($bar);
         echo $png;
     } else {
         // start buffering
         ob_start();
         imagepng($png);
         $contents = ob_get_contents();
         ob_end_clean();
         imagedestroy($png);
         return '<img src="data:image/png;base64,' . base64_encode($contents) . '" />';
     }
 }
Ejemplo n.º 26
0
 /**
  * Returns a PNG representation of the barcode
  * @param int $width The width of a single rectangle element in pixels
  * @param int $height The height of a single rectangle element in pixels
  * @param array $color RGB (0-255) foreground color for rectangle elements (background is transparent)
  * @return string An base64 encoded image string representing the barcode
  */
 public function toPNG($width = 3, $height = 3, $color = array(0, 0, 0))
 {
     // calculate image size
     $imageWidth = $this->barcode_array['num_cols'] * $width;
     $imageHeight = $this->barcode_array['num_rows'] * $height;
     if (function_exists('imagecreate')) {
         // GD library
         $imagick = false;
         $png = imagecreate($imageWidth, $imageHeight);
         $bgcol = imagecolorallocate($png, 255, 255, 255);
         imagecolortransparent($png, $bgcol);
         $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]);
     } else {
         if (extension_loaded('imagick')) {
             $imagick = true;
             $fgcol = new \imagickpixel('rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')');
             $png = new \Imagick();
             $png->newImage($imageWidth, $imageHeight, 'none', 'png');
             $bar = new \imagickdraw();
             $bar->setfillcolor($fgcol);
         } else {
             throw new \RuntimeException("PHP 4+ or the imagick extension is required to generate PNG barcodes.");
         }
     }
     // print barcode elements
     $y = 0;
     // for each row
     for ($r = 0; $r < $this->barcode_array['num_rows']; ++$r) {
         $x = 0;
         // for each column
         for ($c = 0; $c < $this->barcode_array['num_cols']; ++$c) {
             if ($this->barcode_array['bcode'][$r][$c] == 1) {
                 // draw a single barcode cell
                 if ($imagick) {
                     $bar->rectangle($x, $y, $x + $width, $y + $height);
                 } else {
                     imagefilledrectangle($png, $x, $y, $x + $width, $y + $height, $fgcol);
                 }
             }
             $x += $width;
         }
         $y += $height;
     }
     ob_start();
     // get image out put
     if ($imagick) {
         $png->drawimage($bar);
         echo $png;
     } else {
         imagepng($png);
         imagedestroy($png);
     }
     $image = ob_get_clean();
     $image = base64_encode($image);
     //$image = 'data:image/png;base64,' . base64_encode($image);
     return $image;
 }
Ejemplo n.º 27
0
 /**
  * @param \Imagick $imagick
  * @param int $graphWidth
  * @param int $graphHeight
  */
 public static function analyzeImage(\Imagick $imagick, $graphWidth = 255, $graphHeight = 127)
 {
     $sampleHeight = 20;
     $border = 2;
     $imagick->transposeImage();
     $imagick->scaleImage($graphWidth, $sampleHeight);
     $imageIterator = new \ImagickPixelIterator($imagick);
     $luminosityArray = [];
     foreach ($imageIterator as $row => $pixels) {
         /* Loop through pixel rows */
         foreach ($pixels as $column => $pixel) {
             /* Loop through the pixels in the row (columns) */
             /** @var $pixel \ImagickPixel */
             if (false) {
                 $color = $pixel->getColor();
                 $luminosityArray[] = $color['r'];
             } else {
                 $hsl = $pixel->getHSL();
                 $luminosityArray[] = $hsl['luminosity'];
             }
         }
         /* Sync the iterator, this is important to do on each iteration */
         $imageIterator->syncIterator();
         break;
     }
     $draw = new \ImagickDraw();
     $strokeColor = new \ImagickPixel('red');
     $fillColor = new \ImagickPixel('red');
     $draw->setStrokeColor($strokeColor);
     $draw->setFillColor($fillColor);
     $draw->setStrokeWidth(0);
     $draw->setFontSize(72);
     $draw->setStrokeAntiAlias(true);
     $previous = false;
     $x = 0;
     foreach ($luminosityArray as $luminosity) {
         $pos = $graphHeight - 1 - $luminosity * ($graphHeight - 1);
         if ($previous !== false) {
             /** @var $previous int */
             //printf ( "%d, %d, %d, %d <br/>\n" , $x - 1, $previous, $x, $pos);
             $draw->line($x - 1, $previous, $x, $pos);
         }
         $x += 1;
         $previous = $pos;
     }
     $plot = new \Imagick();
     $plot->newImage($graphWidth, $graphHeight, 'white');
     $plot->drawImage($draw);
     $outputImage = new \Imagick();
     $outputImage->newImage($graphWidth, $graphHeight + $sampleHeight, 'white');
     $outputImage->compositeimage($plot, \Imagick::COMPOSITE_ATOP, 0, 0);
     $outputImage->compositeimage($imagick, \Imagick::COMPOSITE_ATOP, 0, $graphHeight);
     $outputImage->borderimage('black', $border, $border);
     $outputImage->setImageFormat("png");
     App::cachingHeader("Content-Type: image/png");
     echo $outputImage;
 }
 private function inscribeImageIntoCanvas(\Imagick $image) : \Imagick
 {
     $dimensions = $image->getImageGeometry();
     $x = (int) round(($this->width - $dimensions['width']) / 2);
     $y = (int) round(($this->height - $dimensions['height']) / 2);
     $canvas = new \Imagick();
     $canvas->newImage($this->width, $this->height, $this->backgroundColor, $image->getImageFormat());
     $canvas->compositeImage($image, \Imagick::COMPOSITE_OVER, $x, $y);
     return $canvas;
 }
function blueDiscAlpha($width, $height)
{
    $imagick = new Imagick();
    $imagick->newImage($width, $height, 'none');
    $draw = new ImagickDraw();
    $draw->setStrokeOpacity(0);
    $draw->setFillColor('blue');
    $draw->circle(2 * $width / 3, 2 * $height / 3, $width - ($width / 3 - $width / 4), 2 * $height / 3);
    $imagick->drawImage($draw);
    return $imagick;
}
Ejemplo n.º 30
0
 /**
  * Returns a PNG representation of the barcode
  * @param int $width The width of a single bar element in pixels
  * @param int $height The height of a single bar element in pixels
  * @param array $color RGB (0-255) foreground color for bar elements (background is transparent)
  * @return string An base64 encoded image string representing the barcode
  */
 public function toPNG($width = 2, $height = 30, $color = array(0, 0, 0))
 {
     // calculate image size
     $imageWidth = $this->barcode_array['maxw'] * $width;
     $imageHeight = $height;
     if (function_exists('imagecreate')) {
         // GD library
         $imagick = false;
         $png = imagecreate($imageWidth, $imageHeight);
         $bgcol = imagecolorallocate($png, 255, 255, 255);
         imagecolortransparent($png, $bgcol);
         $fgcol = imagecolorallocate($png, $color[0], $color[1], $color[2]);
     } else {
         if (extension_loaded('imagick')) {
             $imagick = true;
             $fgcol = new \imagickpixel('rgb(' . $color[0] . ',' . $color[1] . ',' . $color[2] . ')');
             $png = new \Imagick();
             $png->newImage($imageWidth, $imageHeight, 'none', 'png');
             $bar = new \imagickdraw();
             $bar->setfillcolor($fgcol);
         } else {
             throw new \RuntimeException("PHP 4+ or the imagick extension is required to generate PNG barcodes.");
         }
     }
     // print bars
     $x = 0;
     foreach ($this->barcode_array['bcode'] as $k => $v) {
         $bw = round($v['w'] * $width, 3);
         $bh = round($v['h'] * $height / $this->barcode_array['maxh'], 3);
         if ($v['t']) {
             $y = round($v['p'] * $height / $this->barcode_array['maxh'], 3);
             // draw a vertical bar
             if ($imagick) {
                 $bar->rectangle($x, $y, $x + $bw, $y + $bh);
             } else {
                 imagefilledrectangle($png, $x, $y, $x + $bw - 1, $y + $bh, $fgcol);
             }
         }
         $x += $bw;
     }
     ob_start();
     // get image out put
     if ($imagick) {
         $png->drawimage($bar);
         echo $png;
     } else {
         imagepng($png);
         imagedestroy($png);
     }
     $image = ob_get_clean();
     $image = base64_encode($image);
     //$image = 'data:image/png;base64,' . base64_encode($image);
     return $image;
 }