function getMime(phmagick $p, $file = '') { if ($file == '') { $file = $p->getSource(); } $info = getimagesize($file); return $info["mime"]; }
function convert(phmagick $p) { $cmd = $p->getBinary('convert'); $cmd .= ' -quality ' . $p->getImageQuality(); $cmd .= ' "' . $p->getSource() . '" "' . $p->getDestination() . '"'; $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p; }
/** * Add's an watermark to an image * * @param $watermarkImage String - Image path * @param $gravity phMagickGravity - The placement of the watermark * @param $transparency Integer - 1 to 100 the tranparency of the watermark (100 = opaque) */ function watermark(phmagick $p, $watermarkImage, $gravity = 'center', $transparency = 50) { //composite -gravity SouthEast watermark.png original-image.png output-image.png $cmd = $p->getBinary('composite'); $cmd .= ' -dissolve ' . $transparency; $cmd .= ' -gravity ' . $gravity; $cmd .= ' ' . $watermarkImage; $cmd .= ' "' . $p->getSource() . '"'; $cmd .= ' "' . $p->getDestination() . '"'; $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p; }
/** * * @param $width Integer * @param $height Integer * @param $top Integer - The Y coordinate for the left corner of the crop rectangule * @param $left Integer - The X coordinate for the left corner of the crop rectangule * @param $gravity phMagickGravity - The initial placement of the crop rectangule * @return unknown_type */ function crop(phmagick $p, $width, $height, $top = 0, $left = 0, $gravity = 'center') { $cmd = $p->getBinary('convert'); $cmd .= ' ' . $p->getSource(); if ($gravity != '' || $gravity != phMagickGravity::None) { $cmd .= ' -gravity ' . $gravity; } $cmd .= ' -crop ' . (int) $width . 'x' . (int) $height; $cmd .= '+' . $left . '+' . $top; $cmd .= ' ' . $p->getDestination(); $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p; }
/** * 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); }
/** * 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; }
function edges(phmagick $p, $amount = 10) { $cmd = $p->getBinary('convert'); $cmd .= ' -adaptive-sharpen 2x' . $amount; $cmd .= ' -background "none" "' . $p->getSource() . '"'; $cmd .= ' "' . $p->getDestination() . '"'; $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p; }
function autoLevels(phmagick $p) { $cmd = $p->getBinary('convert'); $cmd .= ' -normalize '; $cmd .= ' -background "none" "' . $p->getSource() . '"'; $cmd .= ' "' . $p->getDestination() . '"'; $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p; }
function border(phmagick $p, $borderColor = "#000", $borderSize = "1") { $cmd = $p->getBinary('convert'); $cmd .= ' "' . $p->getSource() . '"'; $cmd .= ' -bordercolor "' . $borderColor . '" -border ' . $borderSize; $cmd .= ' "' . $p->getDestination() . '"'; $ret = $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p; }