<?php
 class phMagick_transform{ function rotate (phmagick $p,$degrees=45){ $cmd = $p->getBinary('convert'); if($degrees=='auto') { $q = "identify -format '%[EXIF:Orientation]' " .$p->getSource(); $Conf = array( 3 => 180, 6 => 90, 8 => -90, ); $or = exec($q); $degrees = $Conf[$or]; if(!$degrees) { return false; } $cmd .= ' -background "transparent" -rotate ' . $degrees ; } else { $cmd .= ' -background "transparent" -rotate ' . $degrees ; } $cmd .= '  "' . $p->getSource().'"' ; $cmd .= ' "' . $p->getDestination().'"' ; $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p ; } function flipVertical(phmagick $p){ $cmd = $p->getBinary('convert'); $cmd .= ' -flip ' ; $cmd .= ' "' . $p->getSource() .'"'; $cmd .= ' "' . $p->getDestination() .'"'; $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p ; } function flipHorizontal(phmagick $p){ $cmd = $p->getBinary('convert'); $cmd .= ' -flop ' ; $cmd .= ' "' . $p->getSource() .'"'; $cmd .= ' "' . $p->getDestination().'"' ; $p->execute($cmd); $p->setSource($p->getDestination()); $p->setHistory($p->getDestination()); return $p ; } function reflection(phmagick $p, $size = 60, $transparency = 50){ $p->requirePlugin('info'); $source = $p->getSource(); $this->flipVertical($p); list($w, $h) = $p->getInfo($p->getDestination()); $p->crop($w, $h * ($size/100),0,0,phMagickGravity::None); $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); $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); $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 ; } } ?>