XOOPS RMCommon Utilities  2.1.8.91RC
 All Classes Namespaces Files Functions Variables
transform.php
Go to the documentation of this file.
1 <?php
2 /*
3  +--------------------------------------------------------------------------------------------+
4  | DISCLAIMER - LEGAL NOTICE - |
5  +--------------------------------------------------------------------------------------------+
6  | |
7  | This program is free for non comercial use, see the license terms available at |
8  | http://www.francodacosta.com/licencing/ for more information |
9  | |
10  | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
11  | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
12  | |
13  | USE IT AT YOUR OWN RISK |
14  | |
15  | |
16  +--------------------------------------------------------------------------------------------+
17 
18 */
31  function rotate (phmagick $p,$degrees=45){
32  $cmd = $p->getBinary('convert');
33  $cmd .= ' -background "transparent" -rotate ' . $degrees ;
34  $cmd .= ' "' . $p->getSource().'"' ;
35  $cmd .= ' "' . $p->getDestination().'"' ;
36 
37  $p->execute($cmd);
38  $p->setSource($p->getDestination());
39  $p->setHistory($p->getDestination());
40  return $p ;
41  }
42 
48  $cmd = $p->getBinary('convert');
49  $cmd .= ' -flip ' ;
50  $cmd .= ' "' . $p->getSource() .'"';
51  $cmd .= ' "' . $p->getDestination() .'"';
52 
53  $p->execute($cmd);
54  $p->setSource($p->getDestination());
55  $p->setHistory($p->getDestination());
56  return $p ;
57  }
58 
64  $cmd = $p->getBinary('convert');
65  $cmd .= ' -flop ' ;
66  $cmd .= ' "' . $p->getSource() .'"';
67  $cmd .= ' "' . $p->getDestination().'"' ;
68 
69  $p->execute($cmd);
70  $p->setSource($p->getDestination());
71  $p->setHistory($p->getDestination());
72  return $p ;
73  }
74 
79  function reflection(phmagick $p, $size = 60, $transparency = 50){
80  $p->requirePlugin('info');
81 
82  $source = $p->getSource();
83 
84  //invert image
85  $this->flipVertical($p);
86 
87  //crop it to $size%
88  list($w, $h) = $p->getInfo($p->getDestination());
89  $p->crop($w, $h * ($size/100),0,0,phMagickGravity::None);
90 
91  //make a image fade to transparent
92  $cmd = $p->getBinary('convert');
93  $cmd .= ' "' . $p->getSource() .'"';
94  $cmd .= ' ( -size ' . $w.'x'. ( $h * ($size/100)) .' gradient: ) ';
95  $cmd .= ' +matte -compose copy_opacity -composite ';
96  $cmd .= ' "' . $p->getDestination().'"' ;
97 
98  $p->execute($cmd);
99 
100  //apply desired transparency, by creating a transparent image and merge the mirros image on to it with the desired transparency
101  $file = dirname($p->getDestination()) . '/'. uniqid() . '.png';
102 
103  $cmd = $p->getBinary('convert');
104  $cmd .= ' -size ' . $w.'x'. ( $h * ($size/100)) .' xc:none ';
105  $cmd .= ' "' . $file .'"' ;
106 
107  $p->execute($cmd);
108 
109  $cmd = $p->getBinary('composite');
110  $cmd .= ' -dissolve ' . $transparency ;
111  $cmd .= ' "' . $p->getDestination() .'"' ;
112  $cmd .= ' ' . $file ;
113  $cmd .= ' "' . $p->getDestination() .'"' ;
114 
115  $p->execute($cmd);
116 
117  unlink($file);
118 
119  //append the source and the relfex
120  $cmd = $p->getBinary('convert');
121  $cmd .= ' "' . $source .'"' ;
122  $cmd .= ' "' . $p->getDestination().'"' ;
123  $cmd .= ' -append ';
124  $cmd .= ' "' . $p->getDestination().'"' ;
125 
126  $p->execute($cmd);
127 
128  $p->setSource($p->getDestination());
129  $p->setHistory($p->getDestination());
130  return $p ;
131  }
132 
133 
134 
135 }
136 ?>