Exemple #1
0
 /**
  * Resizes image to desired width and height, returns true on success.
  *
  * @param string $sSrc           Source of image file
  * @param string $sTarget        Target to write resized image file
  * @param mixed  $iDesiredWidth  Width of resized image
  * @param mixed  $iDesiredHeight Height of resized image
  *
  * @return bool
  */
 public function resizeImage($sSrc, $sTarget, $iDesiredWidth, $iDesiredHeight)
 {
     // use this GD Version
     if (($iUseGDVersion = getGdVersion()) && function_exists('imagecreate') && file_exists($sSrc) && ($aImageInfo = @getimagesize($sSrc))) {
         $myConfig = $this->getConfig();
         list($iWidth, $iHeight) = calcImageSize($iDesiredWidth, $iDesiredHeight, $aImageInfo[0], $aImageInfo[1]);
         return $this->_resize($aImageInfo, $sSrc, null, $sTarget, $iWidth, $iHeight, $iUseGDVersion, $myConfig->getConfigParam('blDisableTouch'), $myConfig->getConfigParam('sDefaultImageQuality'));
     }
     return false;
 }
 /**
  * Generates requested image
  *
  * @param string $sImageSource image source
  * @param string $sImageTarget image target
  *
  * @return string
  */
 protected function _generateImage($sImageSource, $sImageTarget)
 {
     $sPath = false;
     if (getGdVersion() !== false && $this->_isTargetPathValid($sImageTarget) && ($sImageType = $this->_getImageType())) {
         // including generator files
         includeImageUtils();
         // in case lock file creation failed should check if another process did not created image yet
         if ($this->_lock($sImageTarget)) {
             // extracting image info - size/quality
             list($iWidth, $iHeight, $iQuality) = $this->_getImageInfo();
             switch ($sImageType) {
                 case "png":
                     $sPath = $this->_generatePng($sImageSource, $sImageTarget, $iWidth, $iHeight);
                     break;
                 case "jpeg":
                     $sPath = $this->_generateJpg($sImageSource, $sImageTarget, $iWidth, $iHeight, $iQuality);
                     break;
                 case "gif":
                     $sPath = $this->_generateGif($sImageSource, $sImageTarget, $iWidth, $iHeight);
                     break;
             }
             // releasing..
             if ($sPath) {
                 $this->_unlock($sImageTarget);
             }
         } else {
             // assuming that image was created by another process
             $sPath = file_exists($sImageTarget) ? $sImageTarget : false;
         }
     }
     return $sPath;
 }
 /**
  * Return true, if the version of the gd library is correct
  *
  * @return bool
  */
 protected function validateGdVersion()
 {
     return getGdVersion() !== false;
 }