# 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
    00017     final class PrimitiveImage extends PrimitiveFile
    00018     {
    00019         private $width      = null;
    00020         private $height     = null;
    00021
    00022         private $maxWidth   = null;
    00023         private $minWidth   = null;
    00024
    00025         private $maxHeight  = null;
    00026         private $minHeight  = null;
    00027
    00028         private $type       = null;
    00029
    00033         public function clean()
    00034         {
    00035             $this->width = $this->height = null;
    00036
    00037             $this->type = null;
    00038
    00039             return parent::clean();
    00040         }
    00041
    00042         public function getWidth()
    00043         {
    00044             return $this->width;
    00045         }
    00046
    00047         public function getHeight()
    00048         {
    00049             return $this->height;
    00050         }
    00051
    00052         public function getType()
    00053         {
    00054             return $this->type;
    00055         }
    00056
    00060         public function setMaxWidth($max)
    00061         {
    00062             $this->maxWidth = $max;
    00063
    00064             return $this;
    00065         }
    00066
    00067         public function getMaxWidth()
    00068         {
    00069             return $this->maxWidth;
    00070         }
    00071
    00075         public function setMinWidth($min)
    00076         {
    00077             $this->minWidth = $min;
    00078
    00079             return $this;
    00080         }
    00081
    00082         public function getMinWidth()
    00083         {
    00084             return $this->minWidth;
    00085         }
    00086
    00090         public function setMaxHeight($max)
    00091         {
    00092             $this->maxHeight = $max;
    00093
    00094             return $this;
    00095         }
    00096
    00097         public function getMaxHeight()
    00098         {
    00099             return $this->maxHeight;
    00100         }
    00101
    00105         public function setMinHeight($min)
    00106         {
    00107             $this->minHeight = $min;
    00108
    00109             return $this;
    00110         }
    00111
    00112         public function getMinHeight()
    00113         {
    00114             return $this->minHeight;
    00115         }
    00116
    00117         public function import($scope)
    00118         {
    00119             if (!$result = parent::import($scope))
    00120                 return $result;
    00121
    00122             try {
    00123                 list($width, $height, $type) = getimagesize($this->value);
    00124             } catch (BaseException $e) {
    00125                 // bad luck
    00126                 return false;
    00127             }
    00128
    00129             if (!$width || !$height || !$type) {
    00130                 $this->value = null;
    00131                 return false;
    00132             }
    00133
    00134             if (
    00135                 !($this->maxWidth && ($width > $this->maxWidth))
    00136                 && !($this->minWidth && ($width < $this->minWidth))
    00137                 && !($this->maxHeight && ($height > $this->maxHeight))
    00138                 && !($this->minHeight && ($height < $this->minHeight))
    00139             ) {
    00140                 $this->type = new ImageType($type);
    00141                 $this->width = $width;
    00142                 $this->height = $height;
    00143
    00144                 return true;
    00145             }
    00146
    00147             return false;
    00148         }
    00149     }
    00150 ?>