<?php
 class Media { function init() { if(floatval(phpversion())<5) return false; require_once(dirname(__FILE__).'/../lib/php/phmagick/phmagick.php'); $this->_IM = new phmagick; $this->isIM = true; $this->_IM->setImageQuality($this->Mizu->Conf['plugins']['mediaQuality']); $this->showThumbnail = array('pdf','psd','ico','tif'); } function getThumb($f,$d) { $this->_IM->setDestination($this->getBaseDir().$d); $this->_IM->acquireFrame($this->getBaseDir().$f); } function getBaseDir() { return $this->Mizu->_Url->SCRIPT_BASEDIR; } function getDimens() { if(!$this->Act['Dim']) { $R = $this->_IM->getInfo($this->_IM->getSource()); $R['w'] = $R[0]; $R['h'] = $R[1]; $this->Act['Dim'] = $R; } return $this->Act['Dim']; } function getHeight() { $A = $this->getDimens(); return $A['h']; } function getWidth() { $A = $this->getDimens(); return $A['w']; } function byStr($f) { $F = $this->getBaseDir().$f; $this->_IM->setSource($F); $this->Act = array(); } function crop($x1,$y1=null,$x2=null,$y2=null) { if(!$x2) { $tmp = explode('!',$x1); $x1 = $tmp[0]; $y1 = $tmp[1]; $x2 = $tmp[2]; $y2 = $tmp[3]; } $P = array(); $P['x1o'] = $x1; $P['y1o'] = $y1; $P['x2o'] = $x2; $P['y2o'] = $y2; $P['x1'] = $this->getWidth()*$x1/100; $P['y1'] = $this->getHeight()*$y1/100; $P['x2'] = $this->getWidth()*$x2/100; $P['y2'] = $this->getHeight()*$y2/100; $P['w'] = ($P['x2']); $P['h'] = ($P['y2']); $P['t'] = ($P['y1']); $P['l'] = ($P['x1']); $P['g'] = 'NorthWest'; $this->Act['a'][]['crop'] = $P; } function resize($w=null,$h=null,$s=null) { if(!$h AND !$w) return false; if(substr($h,-1)=='c') { $h = substr($h,0,-1); $C['h'] = $h; } if(substr($w,-1)=='c') { $w = substr($w,0,-1); $C['w'] = $w; } if($C) { $P = array(); $P['w'] = $C['w']; $P['h'] = $C['h']; $P['t'] = 0; $P['l'] = 0; $P['g'] = 'center'; $this->Act['a'][]['resizeExactly'] = $P; } else { $this->Act['a'][]['resize']= array('w'=>$w,'h'=>$h,'s'=>$s); } } function save($f) { $this->_IM->setDestination($this->getBaseDir().$f); if($this->Act['a']) { foreach($this->Act['a'] as $t => $v) { $t = key($v); $v = $v[$t]; switch($t) { case 'crop' : $this->_IM->crop($v['w'],$v['h'],$v['t'],$v['l'],$v['g']); break; case 'resize' : $this->_IM->resize($v['w'],$v['h'],$v['s']); break; case 'resizeExactly' : $this->_IM->resizeExactly($v['w'],$v['h']); break; } } } else { copy($this->_IM->getSource(),$this->_IM->getDestination()); } $this->_IM->torgb(); } } 