コード例 #1
0
ファイル: GdFile.php プロジェクト: robtuley/knotwerk
 /**
  * Load the image from file.
  *
  * @param T_File_Path $path  file path
  */
 function __construct($path)
 {
     $this->mime = $path->getMime();
     if (!$path->exists()) {
         throw new T_Exception_Image($path->__toString() . ' not exists');
     }
     $pathstr = $path->__toString();
     list($this->width, $this->height, $type) = @getimagesize($pathstr);
     switch ($this->mime->getType()) {
         case T_Mime::JPEG:
             if ($type !== IMAGETYPE_JPEG) {
                 throw new T_Exception_Image($pathstr . ' is not a JPEG');
             }
             $this->handle = @imagecreatefromjpeg($pathstr);
             break;
         case T_Mime::PNG:
             if ($type !== IMAGETYPE_PNG) {
                 throw new T_Exception_Image($pathstr . ' is not a PNG');
             }
             $this->handle = @imagecreatefrompng($pathstr);
             break;
         case T_Mime::GIF:
             if ($type !== IMAGETYPE_GIF) {
                 throw new T_Exception_Image($pathstr . ' is not a GIF');
             }
             $this->handle = @imagecreatefromgif($pathstr);
             break;
         default:
             $msg = 'Illegal image MIME type ' . $mime->__toString();
             throw new T_Exception_Image($msg);
     }
     if ($this->handle === false) {
         throw new T_Exception_Image('Error loading ' . $pathstr);
     }
 }
コード例 #2
0
ファイル: Gd.php プロジェクト: robtuley/knotwerk
 /**
  * Save to file.
  *
  * @param string $dir  directory
  * @param string $filename  filename
  * @return T_File_Path   filepath to file (normalized extension)
  */
 function toFile($dir, $filename)
 {
     $path = new T_File_Path($dir, $filename, $this->getMime()->getExt());
     if ($path->exists()) {
         /* atomic swap-based replace performed so no possibility of
            mid-write read of partial image by another process */
         $tmp = new T_File_Path($dir, uniqid(rand(), true), $this->getMime()->getExt());
         $this->export($tmp->__toString());
         $tmp->rename($path);
     } else {
         $this->export($path->__toString());
     }
     return $path;
 }
コード例 #3
0
ファイル: File.php プロジェクト: robtuley/knotwerk
 /**
  * Compiles a template file using a filter.
  *
  * @param mixed  filter
  * @return string  compiled template filename
  */
 function _compileUsingFilter($filter)
 {
     $dir = new T_File_Dir(T_CACHE_DIR . 'template');
     $cache = new T_File_Path($dir->__toString(), md5($this->_tpl), 'php');
     if (!$cache->exists() || $cache->exists() && $cache->getLastModified() < filemtime($this->_tpl)) {
         $data = @file_get_contents($this->_tpl);
         if ($data === false) {
             $msg = "Error reading template file {$this->_tpl}";
             throw new RuntimeException();
         }
         $data = _transform($data, $filter);
         $swap = new T_File_Swap($cache, 'wb');
         $swap->write($data);
         $swap->close();
     }
     return $cache->__toString();
 }
コード例 #4
0
ファイル: Path.php プロジェクト: robtuley/knotwerk
 /**
  * Rename the current file to a new filename.
  *
  * @param T_File_Path $path  new filepath for file
  */
 function rename(T_File_Path $path)
 {
     if (T_WINDOWS && $path->exists()) {
         $path->delete();
         /* required for windows, but weakens application as possibility
            of failure to rename resulting in just file deletion  */
     }
     $ok = @rename($this->getPath(), $path->__toString());
     if (!$ok) {
         $msg = 'rename to ' . $path->__toString() . ' failed';
         throw new T_Exception_File($this->getPath(), $msg);
     }
     $this->dir = $path->getDirName();
     $this->filename = $path->getFilename();
     $this->mime = $path->getMime();
     return $this;
 }