Ejemplo n.º 1
0
 public function createVariation($absoluteURI, $variationName, $width, $height, $variationType = EBLOG_VARIATION_USER_TYPE)
 {
     $this->baseURI = $absoluteURI;
     // @task: Determine the path to this new image variation.
     $title = $this->getTitle();
     $prefix = EBLOG_USER_VARIATION_PREFIX;
     if ($variationType == EBLOG_VARIATION_SYSTEM_TYPE) {
         $prefix = EBLOG_SYSTEM_VARIATION_PREFIX;
     }
     $variationFile = $prefix . '_' . $variationName . '_' . basename($this->file);
     $path = dirname($this->file) . DIRECTORY_SEPARATOR . $variationFile;
     // @task: Return an error when a variation with the same title already exist.
     if (JFile::exists($path)) {
         return JText::_('COM_EASYBLOG_FAILED_TO_CREATE_VARIATION_AS_IT_EXISTS');
     }
     // @task: Let's work on the smart resizing now.
     require_once EBLOG_CLASSES . DIRECTORY_SEPARATOR . 'easysimpleimage.php';
     $config = EasyBlogHelper::getConfig();
     $simpleImage = new EasySimpleImage();
     $simpleImage->load($this->file);
     $simpleImage->resize($width, $height);
     $state = $simpleImage->save($path, $simpleImage->image_type, $config->get('main_image_quality'));
     if (!$state) {
         return JText::_('COM_EASYBLOG_FAILED_TO_CREATE_VARIATION_PERMISSIONS');
     }
     // @rule: Determine if this variation can be deleted.
     $canDelete = $variationType != EBLOG_VARIATION_SYSTEM_TYPE;
     $media = new EasyBlogMediaManager();
     $data = $media->getItem($path, dirname(dirname($this->getURI())), $this->relativePath, false, $this->place, false, false, true)->toObject();
     return $this->getVariationObject($data, $variationName, $width, $height, $canDelete, false);
 }
Ejemplo n.º 2
0
 public static function getThumbnailImage($img)
 {
     $srcpattern = '/src=".*?"/';
     preg_match($srcpattern, $img, $src);
     if (isset($src[0])) {
         $imagepath = trim(str_ireplace('src=', '', $src[0]), '"');
         $segment = explode('/', $imagepath);
         $file = end($segment);
         $thumbnailpath = str_ireplace($file, 'thumb_' . $file, implode('/', $segment));
         if (!JFile::exists($thumbnailpath)) {
             $image = new EasySimpleImage();
             $image->load($imagepath);
             $image->resize(64, 64);
             $image->save($thumbnailpath);
         }
         $newSrc = 'src="' . $thumbnailpath . '"';
     } else {
         return false;
     }
     $oldAttributes = array('src' => $srcpattern, 'width' => '/width=".*?"/', 'height' => '/height=".*?"/');
     $newAttributes = array('src' => $newSrc, 'width' => '', 'height' => '');
     return preg_replace($oldAttributes, $newAttributes, $img);
 }