public function process($args)
 {
     if (isset($args[0])) {
         $rotation = $args[0];
     } else {
         $rotation = mt_rand(-5, 5);
     }
     if (isset($args[1])) {
         $signature = $args[1];
     }
     /* -------------------------- */
     $frame_path = DOCROOT . "/staticfiles/img/polaroids/blog_polaroid_frame.png";
     if (!isset($frame_path) or !file_exists($frame_path)) {
         return;
     }
     // Load the frame and crop the requested image
     $frame = new Gmagick();
     $frame->readImage($frame_path);
     $w = $frame->getimagewidth();
     $h = $frame->getimageheight();
     $this->crop(85, 90);
     $x = 10;
     $y = 15;
     $this->image->borderImage("transparent", $x, $y);
     // Have to add a border as the x displacement in compositeImage() is broken!
     $this->image->compositeImage($frame, Gmagick::COMPOSITE_OVER, 0, 0);
     // Some comp styles seem to throw errors!
     // Add the signature if we have been asked for one
     if (isset($signature)) {
         $sig_path = DOCROOT . "/staticfiles/img/polaroids/" . $signature . "_sig.png";
         if (!file_exists($sig_path)) {
             return;
         }
         $sig = new Gmagick();
         $sig->readImage($sig_path);
         $sw = $sig->getimagewidth();
         $sh = $sig->getimageheight();
         $x = ($this->image->getimagewidth() - $sig->getimagewidth()) / 2;
         $y = 330;
         // Have to add a border as the x displacement in compositeImage() is broken!
         $sig->borderImage("transparent", $x, $y);
         $this->image->compositeImage($sig, Gmagick::COMPOSITE_OVER, 0, 0);
         // Some comp styles seem to throw errors!
     }
     // Rotate the image
     if ($rotation != 0) {
         $frame->magnifyimage();
         $frame->magnifyimage();
         $this->image->rotateimage('transparent', $rotation);
         $frame->minifyimage();
         $frame->minifyimage();
     }
 }
Пример #2
0
<?php

//Instantiate a new Gmagick object
$image = new Gmagick('example.jpg');
//Make thumbnail from image loaded. 0 for either axes preserves aspect ratio
$image->thumbnailImage(100, 0);
//Create a border around the image, then simulate how the image will look like as an oil painting
//Notice the chaining of mutator methods which is supported in gmagick
$image->borderImage("yellow", 8, 8)->oilPaintImage(0.3);
//Write the current image at the current state to a file
$image->write('example_thumbnail.jpg');
Пример #3
0
 public function process($args)
 {
     if (isset($args[0]) and is_numeric($args[0])) {
         $rotation = $args[0];
     } else {
         $rotation = mt_rand(-5, 5);
     }
     if (isset($args[1])) {
         $signature = $args[1];
     }
     if (isset($args[2])) {
         $role = $args[2];
     }
     /* -------------------------- */
     $frame_path = DOCROOT . "/staticfiles/img/polaroids/polaroid_frame.png";
     if (!isset($frame_path) or !file_exists($frame_path)) {
         return;
     }
     // Load the frame and crop the requested image
     $frame = new Gmagick();
     $frame->readImage($frame_path);
     $w = $frame->getimagewidth();
     $h = $frame->getimageheight();
     $this->crop(285, 294);
     $x = 28;
     $y = 31;
     $this->image->borderImage("transparent", $x, $y);
     // Have to add a border as the x displacement in compositeImage() is broken!
     $frame->compositeImage($this->image, Gmagick::COMPOSITE_OVER, 0, 0);
     // Some comp styles seem to throw errors!
     $this->image = $frame;
     // Add the signature if we have been asked for one
     if (isset($signature)) {
         $sig_path = DOCROOT . "/staticfiles/img/polaroids/" . $signature . "_sig.png";
         if (file_exists($sig_path)) {
             $sig = new Gmagick();
             $sig->readImage($sig_path);
             $sw = $sig->getimagewidth();
             $sh = $sig->getimageheight();
             $x = ($this->image->getimagewidth() - $sig->getimagewidth()) / 2;
             $y = 330;
             // Have to add a border as the x displacement in compositeImage() is broken!
             $sig->borderImage("transparent", $x, $y);
             $this->image->compositeImage($sig, Gmagick::COMPOSITE_OVER, 0, 0);
             // Some comp styles seem to throw errors!
         }
     }
     // Add the role if we've been asked for one
     if (isset($role)) {
         $font_size = 17;
         $draw = new GmagickDraw();
         $draw->setFontSize($font_size);
         $draw->setFont(DOCROOT . "/staticfiles/img/polaroids/monaco.ttf");
         $draw->setFillColor('#666');
         $text_width = $font_size * strlen($role) * 0.77;
         // Seems to be about a 0.77 ration for monaco between width and height
         $x = ($this->image->getimagewidth() - $text_width) / 2;
         $this->image->annotateimage($draw, $x, 395, 0, $role);
     }
     // Rotate the image
     if ($rotation != 0) {
         $frame->magnifyimage();
         $frame->magnifyimage();
         $this->image->rotateimage('transparent', $rotation);
         $frame->minifyimage();
         $frame->minifyimage();
     }
 }