/**
  * 
  * init image parameters from url
  */
 private function initImageParams($urlImage, $size = UniteFunctionsWPBiz::THUMB_MEDIUM, $ratio = 'none', $refresh = 'false')
 {
     if (is_numeric($urlImage)) {
         $this->thumbID = $urlImage;
         $this->imageUrl = UniteFunctionsWPBiz::getUrlAttachmentImage($this->thumbID, $size);
         $this->imageUrlOrig = UniteFunctionsWPBiz::getUrlAttachmentImage($this->thumbID, 'full');
     } else {
         $this->imageUrl = $urlImage;
         $this->imageUrlOrig = $urlImage;
     }
     //set image path, file and url
     if (!empty($this->imageUrl)) {
         $this->imageFilepath = UniteFunctionsWPBiz::getImagePathFromURL($this->imageUrl);
         $realPath = UniteFunctionsWPBiz::getPathUploads() . $this->imageFilepath;
         //scale img if needed
         if ($ratio !== 'none') {
             $ratio = explode('_', $ratio);
             if (count($ratio) == 2) {
                 $image = wp_get_image_editor($realPath);
                 if (!is_wp_error($image)) {
                     $origSize = $image->get_size();
                     if (isset($origSize['width']) && $origSize['width'] > 0 && isset($origSize['height']) && $origSize['height'] > 0) {
                         $doCreate = true;
                         //get new dimensions based on the scale ratio
                         $newSize = UniteFunctionsBiz::getImageSizeByRatio($origSize['width'], $origSize['height'], $ratio['0'], $ratio['1']);
                         //check if file exists with dimensions
                         $suffix = $image->get_suffix();
                         $fnCheck = $image->generate_filename();
                         $fnCheck = str_replace($suffix . '.', $newSize['0'] . 'x' . $newSize['1'] . '.', $fnCheck);
                         //check if file exists
                         if (file_exists($fnCheck) != false) {
                             if ($refresh == 'false') {
                                 $doCreate = false;
                             }
                         }
                         //refresh
                         if ($doCreate) {
                             $image->resize($newSize['0'], $newSize['1'], true);
                             $newImage = $image->generate_filename();
                             $image->save($newImage);
                         } else {
                             $newImage = $fnCheck;
                         }
                         if (trim($newImage) !== '') {
                             $this->imageUrl = str_replace(ABSPATH, '', $newImage);
                             $this->imageFilepath = UniteFunctionsWPBiz::getImagePathFromURL($this->imageUrl);
                             $realPath = UniteFunctionsWPBiz::getPathUploads() . $this->imageFilepath;
                             $this->imageUrl = get_bloginfo('wpurl') . '/' . $this->imageUrl;
                         }
                     }
                 }
             }
         }
         if (file_exists($realPath) == false || is_file($realPath) == false) {
             $this->imageFilepath = "";
         }
         $this->imageFilename = basename($this->imageUrl);
     }
 }
 /**
  * get image real path phisical on disk from url
  */
 public static function getImageRealPathFromUrl($urlImage)
 {
     $filepath = self::getImagePathFromURL($urlImage);
     $realPath = UniteFunctionsWPBiz::getPathUploads() . $filepath;
     return $realPath;
 }
Example #3
0
 /**
  * 
  * on show image ajax event. outputs image with parameters 
  */
 public static function onShowImage()
 {
     $pathImages = UniteFunctionsWPBiz::getPathUploads();
     $urlImages = UniteFunctionsWPBiz::getUrlUploads();
     try {
         $imageView = new UniteImageViewBiz(self::$path_cache, $pathImages, $urlImages);
         $imageView->showImageFromGet();
     } catch (Exception $e) {
         header("status: 500");
         echo $e->getMessage();
         exit;
     }
 }