Beispiel #1
0
 /**
  * tries to resize an image to the exact size wile mantaining aspect ratio,
  * the image will be croped to fit the measures
  * @param $width
  * @param $height
  */
 function resizeExactly(phmagick $p, $width, $height)
 {
     //requires Crop plugin
     //requires dimensions plugin
     $p->requirePlugin('crop');
     $p->requirePlugin('info');
     list($w, $h) = $p->getInfo($p->getSource());
     if ($w > $h) {
         $h = $height;
         $w = 0;
     } else {
         $h = 0;
         $w = $width;
     }
     $p->resize($w, $h)->crop($width, $height);
 }
 function glow(phmagick $p, $color = '#827f00', $offset = 10, $transparency = 60)
 {
     $p->requirePlugin('info');
     list($w, $h) = $p->getInfo($p->getSource());
     $cmd = $p->getBinary('convert');
     $cmd .= ' "' . $p->getSource() . '" ';
     $cmd .= '( +clone  -background "' . $color . '"  -shadow ' . $transparency . 'x' . $offset . '-' . $offset / 4 . '+' . $offset / 4 . ' ) +swap -background none   -layers merge  +repage  ';
     $cmd .= ' "' . $p->getDestination() . '"';
     $p->execute($cmd);
     $p->setSource($p->getDestination());
     $p->setHistory($p->getDestination());
     return $p;
 }
Beispiel #3
0
 /**
  * Flips the image horizonaly and verticaly
  * @return unknown_type
  */
 function reflection(phmagick $p, $size = 60, $transparency = 50)
 {
     $p->requirePlugin('info');
     $source = $p->getSource();
     //invert image
     $this->flipVertical($p);
     //crop it to $size%
     list($w, $h) = $p->getInfo($p->getDestination());
     $p->crop($w, $h * ($size / 100), 0, 0, phMagickGravity::None);
     //make a image fade to transparent
     $cmd = $p->getBinary('convert');
     $cmd .= ' "' . $p->getSource() . '"';
     $cmd .= ' ( -size ' . $w . 'x' . $h * ($size / 100) . ' gradient: ) ';
     $cmd .= ' +matte -compose copy_opacity -composite ';
     $cmd .= ' "' . $p->getDestination() . '"';
     $p->execute($cmd);
     //apply desired transparency, by creating a transparent image and merge the mirros image on to it with the desired transparency
     $file = dirname($p->getDestination()) . '/' . uniqid() . '.png';
     $cmd = $p->getBinary('convert');
     $cmd .= '  -size ' . $w . 'x' . $h * ($size / 100) . ' xc:none  ';
     $cmd .= ' "' . $file . '"';
     $p->execute($cmd);
     $cmd = $p->getBinary('composite');
     $cmd .= ' -dissolve ' . $transparency;
     $cmd .= ' "' . $p->getDestination() . '"';
     $cmd .= ' ' . $file;
     $cmd .= ' "' . $p->getDestination() . '"';
     $p->execute($cmd);
     unlink($file);
     //append the source and the relfex
     $cmd = $p->getBinary('convert');
     $cmd .= ' "' . $source . '"';
     $cmd .= ' "' . $p->getDestination() . '"';
     $cmd .= ' -append ';
     $cmd .= ' "' . $p->getDestination() . '"';
     $p->execute($cmd);
     $p->setSource($p->getDestination());
     $p->setHistory($p->getDestination());
     return $p;
 }