PrimitiveImage.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2006-2007 by Konstantin V. Arkhipov                     *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: PrimitiveImage.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00018     final class PrimitiveImage extends PrimitiveFile
00019     {
00020         private $width      = null;
00021         private $height     = null;
00022         
00023         private $maxWidth   = null;
00024         private $minWidth   = null;
00025         
00026         private $maxHeight  = null;
00027         private $minHeight  = null;
00028         
00029         private $type       = null;
00030         
00034         public function clean()
00035         {
00036             $this->width = $this->height = null;
00037             
00038             $this->type = null;
00039             
00040             return parent::clean();
00041         }
00042         
00043         public function getWidth()
00044         {
00045             return $this->width;
00046         }
00047         
00048         public function getHeight()
00049         {
00050             return $this->height;
00051         }
00052         
00053         public function getType()
00054         {
00055             return $this->type;
00056         }
00057 
00061         public function setMaxWidth($max)
00062         {
00063             $this->maxWidth = $max;
00064             
00065             return $this;
00066         }
00067         
00071         public function setMinWidth($min)
00072         {
00073             $this->minWidth = $min;
00074             
00075             return $this;
00076         }
00077         
00081         public function setMaxHeight($max)
00082         {
00083             $this->maxHeight = $max;
00084             
00085             return $this;
00086         }
00087         
00091         public function setMinHeight($min)
00092         {
00093             $this->minHeight = $min;
00094             
00095             return $this;
00096         }
00097         
00098         public function import($scope)
00099         {
00100             if (!$result = parent::import($scope))
00101                 return $result;
00102             
00103             try {
00104                 list($width, $height, $type) = getimagesize($this->value);
00105             } catch (BaseException $e) {
00106                 // bad luck
00107                 return false;
00108             }
00109             
00110             if (!$width || !$height || !$type) {
00111                 $this->value = null;
00112                 return false;
00113             }
00114             
00115             if (
00116                 !($this->maxWidth && ($width > $this->maxWidth))
00117                 && !($this->minWidth && ($width < $this->minWidth))
00118                 && !($this->maxHeight && ($height > $this->maxHeight))
00119                 && !($this->minHeight && ($height < $this->minHeight))
00120             ) {
00121                 $this->type = new ImageType($type);
00122                 $this->width = $width;
00123                 $this->height = $height;
00124                 
00125                 return true;
00126             }
00127             
00128             return false;
00129         }
00130     }
00131 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4