Пример #1
0
 /**
  * Returns url to unit media file by it's filename
  *
  * @param Zend_Db_Table_Row $unit
  * @param string $filename - media manager image name
  * @param RM_Media_Image $thumbnail
  * @return string
  */
 function getFileURL($filename, $thumbnail = null)
 {
     if ($thumbnail !== null) {
         return $this->_unitURL . '/' . $this->_unit->id . '/' . $thumbnail->createFilename($filename);
     } else {
         return $this->_unitURL . '/' . $this->_unit->id . '/' . $filename;
     }
 }
Пример #2
0
 /**
  * Create a thumbnail for an image
  *
  * @param RM_Media_Image $thumbnail
  * @param string $folderpath 
  * @param string $filename 
  */
 protected function _createThumbnail(RM_Media_Image $thumbnail, $folderpath, $filename)
 {
     $filepath = $folderpath . DIRECTORY_SEPARATOR . $filename;
     $thumbfileName = $thumbnail->createFilename($filename);
     $thumbpath = $folderpath . DIRECTORY_SEPARATOR . $thumbfileName;
     list($width, $height, $type) = getimagesize($filepath);
     list($thumbWidth, $thumbHeight) = $thumbnail->getImageSize($width, $height);
     if (function_exists('imagecreatetruecolor')) {
         $thumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
     } else {
         //If not GD PHP extension installed images will be in low quality
         $thumb = imagecreate($thumbWidth, $thumbHeight);
     }
     switch ($type) {
         case IMAGETYPE_JPEG:
             $source = imagecreatefromjpeg($filepath);
             break;
         case IMAGETYPE_GIF:
             $source = imagecreatefromgif($filepath);
             break;
         case IMAGETYPE_PNG:
             $source = imagecreatefrompng($filepath);
             break;
         case IMAGETYPE_BMP:
             $source = imagecreatefromwbmp($filepath);
             break;
     }
     imagecopyresized($thumb, $source, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height);
     switch ($type) {
         case IMAGETYPE_JPEG:
             imagejpeg($thumb, $thumbpath, $thumbnail->getQuality());
             break;
         case IMAGETYPE_GIF:
             imagegif($thumb, $thumbpath);
             break;
         case IMAGETYPE_PNG:
             imagepng($thumb, $thumbpath, round($thumbnail->getQuality() / 100));
             break;
         case IMAGETYPE_BMP:
             image2wbmp($thumb, $thumbpath);
             break;
     }
     imagedestroy($thumb);
     return $thumbfileName;
 }